blob: a0ca2f9158f59709fb0cbc34f01591f95831bc87 [file] [log] [blame]
Benny Prijono9cf138e2006-01-19 03:58:29 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
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/compat/unicode.h>
23#include <pj/sock.h>
24#include <pj/log.h>
25
26#include <windows.h>
27#include <commctrl.h>
28
29#define MAX_LOADSTRING 100
30
31#define IDC_HELLO_WINCE 3
32#define ID_LOGWINDOW 104
33///#define IDI_HELLO_WINCE 101
34///#define IDM_MENU 102
35///#define IDD_ABOUTBOX 103
36///#define IDM_FILE_EXIT 40002
37///#define IDM_HELP_ABOUT 40003
38
39// Global Variables:
40HINSTANCE hInst; // The current instance
41///HWND hwndCB; // The command bar handle
42HWND hwLogWnd;
43
44// Forward declarations of functions included in this code module:
45ATOM MyRegisterClass (HINSTANCE, LPTSTR);
46BOOL InitInstance (HINSTANCE, int);
47LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
48///LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
49
50static TCHAR logbuf[8192];
51PJ_DECL_UNICODE_TEMP_BUF(wdata,256);
52
53static void write_log(int level, const char *data, int len)
54{
55 GetWindowText(hwLogWnd, logbuf, PJ_ARRAY_SIZE(logbuf));
56 wcscat(logbuf, PJ_NATIVE_STRING(data,wdata));
57 SetWindowText(hwLogWnd, logbuf);
58 UpdateWindow(hwLogWnd);
59}
60
61
62int WINAPI WinMain(HINSTANCE hInstance,
63 HINSTANCE hPrevInstance,
64 LPTSTR lpCmdLine,
65 int nCmdShow)
66{
67 MSG msg;
68 HACCEL hAccelTable;
69
70 // Perform application initialization:
71 if (!InitInstance (hInstance, nCmdShow))
72 {
73 return FALSE;
74 }
75
76 pj_log_set_log_func( &write_log );
77 pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR);
78
79 test_main();
80
81 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_HELLO_WINCE);
82
83 // Main message loop:
84 while (GetMessage(&msg, NULL, 0, 0))
85 {
86 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
87 {
88 TranslateMessage(&msg);
89 DispatchMessage(&msg);
90 }
91 }
92
93 return msg.wParam;
94}
95
96//
97// FUNCTION: MyRegisterClass()
98//
99// PURPOSE: Registers the window class.
100//
101// COMMENTS:
102//
103// It is important to call this function so that the application
104// will get 'well formed' small icons associated with it.
105//
106ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
107{
108 WNDCLASS wc;
109
110 wc.style = CS_HREDRAW | CS_VREDRAW;
111 wc.lpfnWndProc = (WNDPROC) WndProc;
112 wc.cbClsExtra = 0;
113 wc.cbWndExtra = 0;
114 wc.hInstance = hInstance;
115 ///wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HELLO_WINCE));
116 wc.hIcon = NULL;
117 wc.hCursor = 0;
118 wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
119 wc.lpszMenuName = 0;
120 wc.lpszClassName = szWindowClass;
121
122 return RegisterClass(&wc);
123}
124
125//
126// FUNCTION: InitInstance(HANDLE, int)
127//
128// PURPOSE: Saves instance handle and creates main window
129//
130// COMMENTS:
131//
132// In this function, we save the instance handle in a global variable and
133// create and display the main program window.
134//
135BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
136{
137 HWND hWnd;
138 TCHAR *szTitle = L"PJSIP Test";
139 TCHAR *szWindowClass = L"PJSIP_TEST";
140
141 hInst = hInstance; // Store instance handle in our global variable
142
143 MyRegisterClass(hInstance, szWindowClass);
144
145 hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
146 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
147
148 if (!hWnd)
149 {
150 return FALSE;
151 }
152
153 ShowWindow(hWnd, nCmdShow);
154 UpdateWindow(hWnd);
155 ///if (hwndCB)
156 /// CommandBar_Show(hwndCB, TRUE);
157 if (hwLogWnd)
158 ShowWindow(hwLogWnd, TRUE);
159 return TRUE;
160}
161
162//
163// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
164//
165// PURPOSE: Processes messages for the main window.
166//
167// WM_COMMAND - process the application menu
168// WM_PAINT - Paint the main window
169// WM_DESTROY - post a quit message and return
170//
171//
172LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
173{
174 int wmId, wmEvent;
175 RECT rt;
176 DWORD dwStyle;
177 TCHAR *szHello = L"Hello world!";
178
179 switch (message)
180 {
181 case WM_COMMAND:
182 wmId = LOWORD(wParam);
183 wmEvent = HIWORD(wParam);
184 // Parse the menu selections:
185 switch (wmId)
186 {
187 ///case IDM_HELP_ABOUT:
188 ///DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
189 /// break;
190 ///case IDM_FILE_EXIT:
191 /// DestroyWindow(hWnd);
192 /// break;
193 default:
194 return DefWindowProc(hWnd, message, wParam, lParam);
195 }
196 break;
197 case WM_CREATE:
198 ///hwndCB = CommandBar_Create(hInst, hWnd, 1);
199 ///CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
200 ///CommandBar_AddAdornments(hwndCB, 0, 0);
201 GetClientRect(hWnd, &rt);
202 dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
203 WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL |
204 ES_AUTOHSCROLL | ES_AUTOVSCROLL;
205 hwLogWnd = CreateWindow( TEXT("edit"), // class
206 NULL, // window text
207 dwStyle, // style
208 0, // x-left
209 0, // y-top
210 rt.right-rt.left, // w
211 rt.bottom-rt.top, // h
212 hWnd, // parent
213 (HMENU)ID_LOGWINDOW, // id
214 hInst, // instance
215 NULL); // NULL for control.
216 break;
217 case WM_PAINT:
218 ///hdc = BeginPaint(hWnd, &ps);
219 ///GetClientRect(hWnd, &rt);
220 ///DrawText(hdc, szHello, _tcslen(szHello), &rt,
221 /// DT_SINGLELINE | DT_VCENTER | DT_CENTER);
222 ///EndPaint(hWnd, &ps);
223 break;
224 case WM_ACTIVATE:
225 if (LOWORD(wParam) == WA_INACTIVE)
226 DestroyWindow(hWnd);
227 break;
228 case WM_CLOSE:
229 DestroyWindow(hWnd);
230 break;
231 case WM_DESTROY:
232 ///CommandBar_Destroy(hwndCB);
233 PostQuitMessage(0);
234 break;
235 default:
236 return DefWindowProc(hWnd, message, wParam, lParam);
237 }
238 return 0;
239}
240