From 47e7de1c94be7f826080b3711451eafee894791f Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Thu, 19 Jan 2006 03:58:29 +0000 Subject: Initial, quick and dirty WinCE port with EVC4 git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@125 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pjlib-test/main.c | 3 + pjlib/src/pjlib-test/main_mod.c | 3 + pjlib/src/pjlib-test/main_win32.c | 240 ++++++++++++++++++++++++++++++++++++++ pjlib/src/pjlib-test/test.c | 2 - 4 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 pjlib/src/pjlib-test/main_win32.c (limited to 'pjlib/src/pjlib-test') diff --git a/pjlib/src/pjlib-test/main.c b/pjlib/src/pjlib-test/main.c index 20a34478..4236b5b5 100644 --- a/pjlib/src/pjlib-test/main.c +++ b/pjlib/src/pjlib-test/main.c @@ -90,6 +90,9 @@ int main(int argc, char *argv[]) } } + pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | + PJ_LOG_HAS_MICRO_SEC); + rc = test_main(); if (interractive) { diff --git a/pjlib/src/pjlib-test/main_mod.c b/pjlib/src/pjlib-test/main_mod.c index 2dada340..3ad07794 100644 --- a/pjlib/src/pjlib-test/main_mod.c +++ b/pjlib/src/pjlib-test/main_mod.c @@ -24,6 +24,9 @@ int init_module(void) { printk(KERN_INFO "PJLIB test module loaded. Starting tests...\n"); + pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | + PJ_LOG_HAS_MICRO_SEC); + test_main(); /* Prevent module from loading. We've finished test anyway.. */ diff --git a/pjlib/src/pjlib-test/main_win32.c b/pjlib/src/pjlib-test/main_win32.c new file mode 100644 index 00000000..a0ca2f91 --- /dev/null +++ b/pjlib/src/pjlib-test/main_win32.c @@ -0,0 +1,240 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "test.h" + +#include +#include +#include +#include + +#include +#include + +#define MAX_LOADSTRING 100 + +#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 + +// 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); + +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); +} + + +int WINAPI WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPTSTR lpCmdLine, + int nCmdShow) +{ + MSG msg; + HACCEL hAccelTable; + + // Perform application initialization: + 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); + + 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); + } + } + + 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. +// +ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) +{ + WNDCLASS wc; + + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = (WNDPROC) WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + ///wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HELLO_WINCE)); + wc.hIcon = NULL; + wc.hCursor = 0; + wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); + wc.lpszMenuName = 0; + wc.lpszClassName = 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 + + MyRegisterClass(hInstance, szWindowClass); + + hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, + 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); + 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); + } + 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: + DestroyWindow(hWnd); + break; + case WM_DESTROY: + ///CommandBar_Destroy(hwndCB); + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c index f8506fa9..ce0d1a3f 100644 --- a/pjlib/src/pjlib-test/test.c +++ b/pjlib/src/pjlib-test/test.c @@ -48,8 +48,6 @@ int test_inner(void) mem = &caching_pool.factory; pj_log_set_level(3); - pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | - PJ_LOG_HAS_MICRO_SEC); rc = pj_init(); if (rc != 0) { -- cgit v1.2.3