Ignore:
Timestamp:
Jan 20, 2006 9:03:36 PM (18 years ago)
Author:
bennylp
Message:

Completed testing for WinCE port

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pjlib-test/main_win32.c

    r125 r126  
    2020 
    2121#include <pj/string.h> 
    22 #include <pj/compat/unicode.h> 
     22#include <pj/unicode.h> 
    2323#include <pj/sock.h> 
    2424#include <pj/log.h> 
    2525 
     26#define WIN32_LEAN_AND_MEAN 
     27#define NONAMELESSUNION 
    2628#include <windows.h> 
    2729#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: 
    40 HINSTANCE                       hInst;                  // The current instance 
    41 ///HWND                         hwndCB;                 // The command bar handle 
    42 HWND                            hwLogWnd; 
    43  
    44 // Forward declarations of functions included in this code module: 
    45 ATOM                    MyRegisterClass (HINSTANCE, LPTSTR); 
    46 BOOL                    InitInstance    (HINSTANCE, int); 
    47 LRESULT CALLBACK        WndProc         (HWND, UINT, WPARAM, LPARAM); 
    48 ///LRESULT CALLBACK     About           (HWND, UINT, WPARAM, LPARAM); 
    49  
    50 static TCHAR logbuf[8192]; 
    51 PJ_DECL_UNICODE_TEMP_BUF(wdata,256); 
     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 
     39ATOM                        MyRegisterClass     (HINSTANCE, LPTSTR); 
     40BOOL                        InitInstance        (HINSTANCE, int); 
     41LRESULT CALLBACK            WndProc             (HWND, UINT, WPARAM, LPARAM); 
     42 
     43 
     44extern int                  param_log_decor;    // in test.c 
     45 
     46static HINSTANCE            hInst; 
     47static HWND                 hwndLog; 
     48static HFONT                hFixedFont; 
     49 
    5250 
    5351static void write_log(int level, const char *data, int len) 
    5452{ 
    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  
    62 int WINAPI WinMain(HINSTANCE hInstance, 
    63                    HINSTANCE hPrevInstance, 
    64                    LPTSTR    lpCmdLine, 
    65                    int      nCmdShow) 
     53    PJ_DECL_UNICODE_TEMP_BUF(wdata,256); 
     54 
     55    PJ_UNUSED_ARG(level); 
     56    PJ_UNUSED_ARG(len); 
     57    SendMessage(hwndLog, EM_REPLACESEL, FALSE,  
     58                (LPARAM)PJ_STRING_TO_NATIVE(data,wdata)); 
     59} 
     60 
     61 
     62int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,  
     63                   LPTSTR lpCmdLine, int nCmdShow) 
    6664{ 
    6765    MSG msg; 
    68     HACCEL hAccelTable; 
    69      
    70     // Perform application initialization: 
    71     if (!InitInstance (hInstance, nCmdShow))  
    72     { 
     66     
     67    PJ_UNUSED_ARG(lpCmdLine); 
     68    PJ_UNUSED_ARG(hPrevInstance); 
     69 
     70     
     71    if (!InitInstance (hInstance, nCmdShow)) 
    7372        return FALSE; 
     73     
     74    pj_log_set_log_func( &write_log ); 
     75    param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR; 
     76 
     77    // Run the test! 
     78    test_main(); 
     79 
     80    PJ_LOG(3,(THIS_FILE,"")); 
     81    PJ_LOG(3,(THIS_FILE,"Press ESC to quit")); 
     82 
     83    // Message loop, waiting to quit. 
     84    while (GetMessage(&msg, NULL, 0, 0)) { 
     85        TranslateMessage(&msg); 
     86        DispatchMessage(&msg); 
    7487    } 
    7588     
    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      
     89    DeleteObject(hFixedFont); 
    9390    return msg.wParam; 
    9491} 
    9592 
    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 // 
     93 
     94#ifdef _CONSOLE 
     95int main() 
     96{ 
     97    return WinMain(GetModuleHandle(NULL), NULL, NULL, SW_SHOW); 
     98} 
     99#endif 
     100 
     101 
    106102ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) 
    107103{ 
     
    123119} 
    124120 
    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 // 
     121 
    135122BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 
    136123{ 
    137124    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 
     125    TCHAR       *szTitle = _T("PJSIP Test"); 
     126    TCHAR       *szWindowClass = _T("PJSIP_TEST"); 
     127    LOGFONT     lf; 
     128 
     129 
     130    memset(&lf, 0, sizeof(lf)); 
     131    lf.lfHeight = 13; 
     132#if PJ_NATIVE_STRING_IS_UNICODE 
     133    wcscpy(lf.lfFaceName, _T("Courier New")); 
     134#else 
     135    strcpy(lf.lfFaceName, "Lucida Console"); 
     136#endif 
     137 
     138    hFixedFont = CreateFontIndirect(&lf); 
     139    if (!hFixedFont) 
     140        return FALSE; 
     141 
     142    hInst = hInstance; 
    142143     
    143144    MyRegisterClass(hInstance, szWindowClass); 
    144145     
    145146    hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, 
    146         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); 
     147                        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,  
     148                        CW_USEDEFAULT, NULL, NULL, hInstance, NULL); 
    147149     
    148150    if (!hWnd) 
    149     {    
    150151        return FALSE; 
    151     } 
    152152     
    153153    ShowWindow(hWnd, nCmdShow); 
    154154    UpdateWindow(hWnd); 
    155     ///if (hwndCB) 
    156     /// CommandBar_Show(hwndCB, TRUE); 
    157     if (hwLogWnd) 
    158         ShowWindow(hwLogWnd, TRUE); 
     155 
     156    if (hwndLog) { 
     157        SendMessage(hwndLog, WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0);   
     158        ShowWindow(hwndLog, TRUE); 
     159    } 
     160 
    159161    return TRUE; 
    160162} 
    161163 
    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 // 
     164 
    172165LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
    173166{ 
    174     int wmId, wmEvent; 
    175167    RECT rt; 
    176168    DWORD dwStyle; 
    177     TCHAR *szHello = L"Hello world!"; 
    178169     
    179170    switch (message)  
    180171    { 
    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); 
     172    case WM_CREATE: 
     173        // Create text control. 
     174        GetClientRect(hWnd, &rt); 
     175        dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |  
     176                  WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | 
     177                  ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY;  
     178        hwndLog = CreateWindow( TEXT("edit"),       // class 
     179                                NULL,               // window text 
     180                                dwStyle,            // style 
     181                                0,                  // x-left 
     182                                0,                  // y-top 
     183                                rt.right-rt.left,   // w 
     184                                rt.bottom-rt.top,   // h 
     185                                hWnd,               // parent 
     186                                (HMENU)ID_LOGWINDOW,// id 
     187                                hInst,              // instance 
     188                                NULL);              // NULL for control. 
     189        break; 
     190    case WM_ACTIVATE: 
     191        if (LOWORD(wParam) == WA_INACTIVE) 
     192            DestroyWindow(hWnd); 
     193        break; 
     194    case WM_CHAR: 
     195        if (wParam == 27) { 
     196            DestroyWindow(hWnd); 
    195197        } 
    196198        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); 
     199    case WM_CLOSE: 
     200        DestroyWindow(hWnd); 
     201        break; 
     202    case WM_DESTROY: 
     203        PostQuitMessage(0); 
     204        break; 
     205    default: 
     206        return DefWindowProc(hWnd, message, wParam, lParam); 
    237207    } 
    238208    return 0; 
Note: See TracChangeset for help on using the changeset viewer.