Debian Codegraph @

Xpjproject/pjlib/src/pjlib-test/main_win32.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 // Run the test!
77 test_main(1, argv);
78
79 PJ_LOG(3,(THIS_FILE,""));
80 PJ_LOG(3,(THIS_FILE,"Press ESC to quit"));
81
82 // Message loop, waiting to quit.
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 ///wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HELLO_WINCE));
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 // Create text control.
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"), // class
178 NULL, // window text
179 dwStyle, // style
180 0, // x-left
181 0, // y-top
182 rt.right-rt.left, // w
183 rt.bottom-rt.top, // h
184 hWnd, // parent
185 (HMENU)ID_LOGWINDOW,// id
186 hInst, // instance
187 NULL); // NULL for control.
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