diff options
Diffstat (limited to 'pjlib/src/pjlib-test/main_win32.c')
-rw-r--r-- | pjlib/src/pjlib-test/main_win32.c | 252 |
1 files changed, 111 insertions, 141 deletions
diff --git a/pjlib/src/pjlib-test/main_win32.c b/pjlib/src/pjlib-test/main_win32.c index a0ca2f91..07d91870 100644 --- a/pjlib/src/pjlib-test/main_win32.c +++ b/pjlib/src/pjlib-test/main_win32.c @@ -19,90 +19,86 @@ #include "test.h" #include <pj/string.h> -#include <pj/compat/unicode.h> +#include <pj/unicode.h> #include <pj/sock.h> #include <pj/log.h> +#define WIN32_LEAN_AND_MEAN +#define NONAMELESSUNION #include <windows.h> #include <commctrl.h> +#include <tchar.h> -#define MAX_LOADSTRING 100 +#define MAX_LOADSTRING 100 +#define THIS_FILE "main_win32.c" -#define IDC_HELLO_WINCE 3 -#define ID_LOGWINDOW 104 -///#define IDI_HELLO_WINCE 101 -///#define IDM_MENU 102 -///#define IDD_ABOUTBOX 103 -///#define IDM_FILE_EXIT 40002 -///#define IDM_HELP_ABOUT 40003 +#define IDC_HELLO_WINCE 3 +#define ID_LOGWINDOW 104 -// Global Variables: -HINSTANCE hInst; // The current instance -///HWND hwndCB; // The command bar handle -HWND hwLogWnd; -// Forward declarations of functions included in this code module: -ATOM MyRegisterClass (HINSTANCE, LPTSTR); -BOOL InitInstance (HINSTANCE, int); -LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); -///LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM); +ATOM MyRegisterClass (HINSTANCE, LPTSTR); +BOOL InitInstance (HINSTANCE, int); +LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); + + +extern int param_log_decor; // in test.c + +static HINSTANCE hInst; +static HWND hwndLog; +static HFONT hFixedFont; -static TCHAR logbuf[8192]; -PJ_DECL_UNICODE_TEMP_BUF(wdata,256); static void write_log(int level, const char *data, int len) { - GetWindowText(hwLogWnd, logbuf, PJ_ARRAY_SIZE(logbuf)); - wcscat(logbuf, PJ_NATIVE_STRING(data,wdata)); - SetWindowText(hwLogWnd, logbuf); - UpdateWindow(hwLogWnd); + PJ_DECL_UNICODE_TEMP_BUF(wdata,256); + + PJ_UNUSED_ARG(level); + PJ_UNUSED_ARG(len); + SendMessage(hwndLog, EM_REPLACESEL, FALSE, + (LPARAM)PJ_STRING_TO_NATIVE(data,wdata)); } -int WINAPI WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPTSTR lpCmdLine, - int nCmdShow) +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPTSTR lpCmdLine, int nCmdShow) { MSG msg; - HACCEL hAccelTable; - // Perform application initialization: - if (!InitInstance (hInstance, nCmdShow)) - { + PJ_UNUSED_ARG(lpCmdLine); + PJ_UNUSED_ARG(hPrevInstance); + + + if (!InitInstance (hInstance, nCmdShow)) return FALSE; - } pj_log_set_log_func( &write_log ); - pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR); + param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR; + // Run the test! test_main(); - hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_HELLO_WINCE); - - // Main message loop: - while (GetMessage(&msg, NULL, 0, 0)) - { - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + PJ_LOG(3,(THIS_FILE,"")); + PJ_LOG(3,(THIS_FILE,"Press ESC to quit")); + + // Message loop, waiting to quit. + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); } + DeleteObject(hFixedFont); return msg.wParam; } -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// -// COMMENTS: -// -// It is important to call this function so that the application -// will get 'well formed' small icons associated with it. -// + +#ifdef _CONSOLE +int main() +{ + return WinMain(GetModuleHandle(NULL), NULL, NULL, SW_SHOW); +} +#endif + + ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) { WNDCLASS wc; @@ -122,118 +118,92 @@ ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) return RegisterClass(&wc); } -// -// FUNCTION: InitInstance(HANDLE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// + BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; - TCHAR *szTitle = L"PJSIP Test"; - TCHAR *szWindowClass = L"PJSIP_TEST"; - - hInst = hInstance; // Store instance handle in our global variable + TCHAR *szTitle = _T("PJSIP Test"); + TCHAR *szWindowClass = _T("PJSIP_TEST"); + LOGFONT lf; + + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = 13; +#if PJ_NATIVE_STRING_IS_UNICODE + wcscpy(lf.lfFaceName, _T("Courier New")); +#else + strcpy(lf.lfFaceName, "Lucida Console"); +#endif + + hFixedFont = CreateFontIndirect(&lf); + if (!hFixedFont) + return FALSE; + + hInst = hInstance; MyRegisterClass(hInstance, szWindowClass); hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hWnd) - { return FALSE; - } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); - ///if (hwndCB) - /// CommandBar_Show(hwndCB, TRUE); - if (hwLogWnd) - ShowWindow(hwLogWnd, TRUE); + + if (hwndLog) { + SendMessage(hwndLog, WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0); + ShowWindow(hwndLog, TRUE); + } + return TRUE; } -// -// FUNCTION: WndProc(HWND, unsigned, WORD, LONG) -// -// PURPOSE: Processes messages for the main window. -// -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return -// -// + LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - int wmId, wmEvent; RECT rt; DWORD dwStyle; - TCHAR *szHello = L"Hello world!"; switch (message) { - case WM_COMMAND: - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - ///case IDM_HELP_ABOUT: - ///DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); - /// break; - ///case IDM_FILE_EXIT: - /// DestroyWindow(hWnd); - /// break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } + case WM_CREATE: + // Create text control. + GetClientRect(hWnd, &rt); + dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | + WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | + ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY; + hwndLog = CreateWindow( TEXT("edit"), // class + NULL, // window text + dwStyle, // style + 0, // x-left + 0, // y-top + rt.right-rt.left, // w + rt.bottom-rt.top, // h + hWnd, // parent + (HMENU)ID_LOGWINDOW,// id + hInst, // instance + NULL); // NULL for control. + break; + case WM_ACTIVATE: + if (LOWORD(wParam) == WA_INACTIVE) + DestroyWindow(hWnd); break; - case WM_CREATE: - ///hwndCB = CommandBar_Create(hInst, hWnd, 1); - ///CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0); - ///CommandBar_AddAdornments(hwndCB, 0, 0); - GetClientRect(hWnd, &rt); - dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | - WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | - ES_AUTOHSCROLL | ES_AUTOVSCROLL; - hwLogWnd = CreateWindow( TEXT("edit"), // class - NULL, // window text - dwStyle, // style - 0, // x-left - 0, // y-top - rt.right-rt.left, // w - rt.bottom-rt.top, // h - hWnd, // parent - (HMENU)ID_LOGWINDOW, // id - hInst, // instance - NULL); // NULL for control. - break; - case WM_PAINT: - ///hdc = BeginPaint(hWnd, &ps); - ///GetClientRect(hWnd, &rt); - ///DrawText(hdc, szHello, _tcslen(szHello), &rt, - /// DT_SINGLELINE | DT_VCENTER | DT_CENTER); - ///EndPaint(hWnd, &ps); - break; - case WM_ACTIVATE: - if (LOWORD(wParam) == WA_INACTIVE) - DestroyWindow(hWnd); - break; - case WM_CLOSE: + case WM_CHAR: + if (wParam == 27) { DestroyWindow(hWnd); - break; - case WM_DESTROY: - ///CommandBar_Destroy(hwndCB); - PostQuitMessage(0); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); + } + break; + case WM_CLOSE: + DestroyWindow(hWnd); + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } |