| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "test.h" |
| 20 |
|
| 21 |
#include <pj/string.h> |
| 22 |
#include <pj/unicode.h> |
| 23 |
#include <pj/sock.h> |
| 24 |
#include <pj/log.h> |
| 25 |
|
| 26 |
#define WIN32_LEAN_AND_MEAN |
| 27 |
#define NONAMELESSUNION |
| 28 |
#include <windows.h> |
| 29 |
#include <commctrl.h> |
| 30 |
#include <tchar.h> |
| 31 |
|
| 32 |
#define MAX_LOADSTRING 100 |
| 33 |
#define THIS_FILE "main_win32.c" |
| 34 |
|
| 35 |
#define IDC_HELLO_WINCE 3 |
| 36 |
#define ID_LOGWINDOW 104 |
| 37 |
|
| 38 |
|
| 39 |
ATOM MyRegisterClass (HINSTANCE, LPTSTR); |
| 40 |
BOOL InitInstance (HINSTANCE, int); |
| 41 |
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); |
| 42 |
|
| 43 |
|
| 44 |
static HINSTANCE hInst; |
| 45 |
static HWND hwndLog; |
| 46 |
static HFONT hFixedFont; |
| 47 |
|
| 48 |
|
| 49 |
static void write_log(int level, const char *data, int len) |
| 50 |
{ |
| 51 |
PJ_DECL_UNICODE_TEMP_BUF(wdata,256); |
| 52 |
|
| 53 |
PJ_UNUSED_ARG(level); |
| 54 |
PJ_UNUSED_ARG(len); |
| 55 |
SendMessage(hwndLog, EM_REPLACESEL, FALSE, |
| 56 |
(LPARAM)PJ_STRING_TO_NATIVE(data,wdata,256)); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 61 |
LPTSTR lpCmdLine, int nCmdShow) |
| 62 |
{ |
| 63 |
MSG msg; |
| 64 |
char *argv[] = {"pjlib-test", NULL}; |
| 65 |
|
| 66 |
PJ_UNUSED_ARG(lpCmdLine); |
| 67 |
PJ_UNUSED_ARG(hPrevInstance); |
| 68 |
|
| 69 |
|
| 70 |
if (!InitInstance (hInstance, nCmdShow)) |
| 71 |
return FALSE; |
| 72 |
|
| 73 |
pj_log_set_log_func( &write_log ); |
| 74 |
test_app.param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR; |
| 75 |
|
| 76 |
|
| 77 |
test_main(1, argv); |
| 78 |
|
| 79 |
PJ_LOG(3,(THIS_FILE,"")); |
| 80 |
PJ_LOG(3,(THIS_FILE,"Press ESC to quit")); |
| 81 |
|
| 82 |
|
| 83 |
while (GetMessage(&msg, NULL, 0, 0)) { |
| 84 |
TranslateMessage(&msg); |
| 85 |
DispatchMessage(&msg); |
| 86 |
} |
| 87 |
|
| 88 |
DeleteObject(hFixedFont); |
| 89 |
return msg.wParam; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
#ifdef _CONSOLE |
| 94 |
int main() |
| 95 |
{ |
| 96 |
return WinMain(GetModuleHandle(NULL), NULL, NULL, SW_SHOW); |
| 97 |
} |
| 98 |
#endif |
| 99 |
|
| 100 |
|
| 101 |
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) |
| 102 |
{ |
| 103 |
WNDCLASS wc; |
| 104 |
|
| 105 |
wc.style = CS_HREDRAW | CS_VREDRAW; |
| 106 |
wc.lpfnWndProc = (WNDPROC) WndProc; |
| 107 |
wc.cbClsExtra = 0; |
| 108 |
wc.cbWndExtra = 0; |
| 109 |
wc.hInstance = hInstance; |
| 110 |
|
| 111 |
wc.hIcon = NULL; |
| 112 |
wc.hCursor = 0; |
| 113 |
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); |
| 114 |
wc.lpszMenuName = 0; |
| 115 |
wc.lpszClassName = szWindowClass; |
| 116 |
|
| 117 |
return RegisterClass(&wc); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) |
| 122 |
{ |
| 123 |
HWND hWnd; |
| 124 |
TCHAR *szTitle = _T("PJSIP Test"); |
| 125 |
TCHAR *szWindowClass = _T("PJSIP_TEST"); |
| 126 |
LOGFONT lf; |
| 127 |
|
| 128 |
|
| 129 |
memset(&lf, 0, sizeof(lf)); |
| 130 |
lf.lfHeight = 13; |
| 131 |
#if PJ_NATIVE_STRING_IS_UNICODE |
| 132 |
wcscpy(lf.lfFaceName, _T("Courier New")); |
| 133 |
#else |
| 134 |
strcpy(lf.lfFaceName, "Lucida Console"); |
| 135 |
#endif |
| 136 |
|
| 137 |
hFixedFont = CreateFontIndirect(&lf); |
| 138 |
if (!hFixedFont) |
| 139 |
return FALSE; |
| 140 |
|
| 141 |
hInst = hInstance; |
| 142 |
|
| 143 |
MyRegisterClass(hInstance, szWindowClass); |
| 144 |
|
| 145 |
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, |
| 146 |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 147 |
CW_USEDEFAULT, NULL, NULL, hInstance, NULL); |
| 148 |
|
| 149 |
if (!hWnd) |
| 150 |
return FALSE; |
| 151 |
|
| 152 |
ShowWindow(hWnd, nCmdShow); |
| 153 |
UpdateWindow(hWnd); |
| 154 |
|
| 155 |
if (hwndLog) { |
| 156 |
SendMessage(hwndLog, WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0); |
| 157 |
ShowWindow(hwndLog, TRUE); |
| 158 |
} |
| 159 |
|
| 160 |
return TRUE; |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 165 |
{ |
| 166 |
RECT rt; |
| 167 |
DWORD dwStyle; |
| 168 |
|
| 169 |
switch (message) |
| 170 |
{ |
| 171 |
case WM_CREATE: |
| 172 |
|
| 173 |
GetClientRect(hWnd, &rt); |
| 174 |
dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | |
| 175 |
WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | |
| 176 |
ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY; |
| 177 |
hwndLog = CreateWindow( TEXT("edit"), |
| 178 |
NULL, |
| 179 |
dwStyle, |
| 180 |
0, |
| 181 |
0, |
| 182 |
rt.right-rt.left, |
| 183 |
rt.bottom-rt.top, |
| 184 |
hWnd, |
| 185 |
(HMENU)ID_LOGWINDOW, |
| 186 |
hInst, |
| 187 |
NULL); |
| 188 |
break; |
| 189 |
case WM_ACTIVATE: |
| 190 |
if (LOWORD(wParam) == WA_INACTIVE) |
| 191 |
DestroyWindow(hWnd); |
| 192 |
break; |
| 193 |
case WM_CHAR: |
| 194 |
if (wParam == 27) { |
| 195 |
DestroyWindow(hWnd); |
| 196 |
} |
| 197 |
break; |
| 198 |
case WM_CLOSE: |
| 199 |
DestroyWindow(hWnd); |
| 200 |
break; |
| 201 |
case WM_DESTROY: |
| 202 |
PostQuitMessage(0); |
| 203 |
break; |
| 204 |
default: |
| 205 |
return DefWindowProc(hWnd, message, wParam, lParam); |
| 206 |
} |
| 207 |
return 0; |
| 208 |
} |
| 209 |
|