1
/* $Id: main_win32.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include <pj/string.h>
23
#include <pj/unicode.h>
27
#define WIN32_LEAN_AND_MEAN
28
#define NONAMELESSUNION
33
#define MAX_LOADSTRING 100
34
#define THIS_FILE "main_win32.c"
36
#define IDC_HELLO_WINCE 3
37
#define ID_LOGWINDOW 104
40
ATOM MyRegisterClass (HINSTANCE, LPTSTR);
41
BOOL InitInstance (HINSTANCE, int);
42
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
45
extern int param_log_decor; // in test.c
47
static HINSTANCE hInst;
49
static HFONT hFixedFont;
52
static void write_log(int level, const char *data, int len)
54
PJ_DECL_UNICODE_TEMP_BUF(wdata,256);
58
SendMessage(hwndLog, EM_REPLACESEL, FALSE,
59
(LPARAM)PJ_STRING_TO_NATIVE(data,wdata,256));
63
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
64
LPTSTR lpCmdLine, int nCmdShow)
68
PJ_UNUSED_ARG(lpCmdLine);
69
PJ_UNUSED_ARG(hPrevInstance);
72
if (!InitInstance (hInstance, nCmdShow))
75
pj_log_set_log_func( &write_log );
76
param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR;
81
PJ_LOG(3,(THIS_FILE,""));
82
PJ_LOG(3,(THIS_FILE,"Press ESC to quit"));
84
// Message loop, waiting to quit.
85
while (GetMessage(&msg, NULL, 0, 0)) {
86
TranslateMessage(&msg);
87
DispatchMessage(&msg);
90
DeleteObject(hFixedFont);
98
return WinMain(GetModuleHandle(NULL), NULL, NULL, SW_SHOW);
103
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
107
wc.style = CS_HREDRAW | CS_VREDRAW;
108
wc.lpfnWndProc = (WNDPROC) WndProc;
111
wc.hInstance = hInstance;
112
///wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HELLO_WINCE));
115
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
117
wc.lpszClassName = szWindowClass;
119
return RegisterClass(&wc);
123
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
126
TCHAR *szTitle = _T("PJSIP Test");
127
TCHAR *szWindowClass = _T("PJSIP_TEST");
131
memset(&lf, 0, sizeof(lf));
133
#if PJ_NATIVE_STRING_IS_UNICODE
134
wcscpy(lf.lfFaceName, _T("Courier New"));
136
strcpy(lf.lfFaceName, "Lucida Console");
139
hFixedFont = CreateFontIndirect(&lf);
145
MyRegisterClass(hInstance, szWindowClass);
147
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
148
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
149
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
154
ShowWindow(hWnd, nCmdShow);
158
SendMessage(hwndLog, WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0);
159
ShowWindow(hwndLog, TRUE);
166
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
174
// Create text control.
175
GetClientRect(hWnd, &rt);
176
dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
177
WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL |
178
ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY;
179
hwndLog = CreateWindow( TEXT("edit"), // class
184
rt.right-rt.left, // w
185
rt.bottom-rt.top, // h
187
(HMENU)ID_LOGWINDOW,// id
189
NULL); // NULL for control.
192
if (LOWORD(wParam) == WA_INACTIVE)
207
return DefWindowProc(hWnd, message, wParam, lParam);