~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/pjlib/src/pjlib-test/main_win32.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: main_win32.c 3553 2011-05-05 06:14:19Z nanang $ */
 
2
/* 
 
3
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
 
4
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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 
 
19
 */
 
20
#include "test.h"
 
21
 
 
22
#include <pj/string.h>
 
23
#include <pj/unicode.h>
 
24
#include <pj/sock.h>
 
25
#include <pj/log.h>
 
26
 
 
27
#define WIN32_LEAN_AND_MEAN
 
28
#define NONAMELESSUNION
 
29
#include <windows.h>
 
30
#include <commctrl.h>
 
31
#include <tchar.h>
 
32
 
 
33
#define MAX_LOADSTRING      100
 
34
#define THIS_FILE           "main_win32.c"
 
35
 
 
36
#define IDC_HELLO_WINCE     3
 
37
#define ID_LOGWINDOW        104
 
38
 
 
39
 
 
40
ATOM                        MyRegisterClass     (HINSTANCE, LPTSTR);
 
41
BOOL                        InitInstance        (HINSTANCE, int);
 
42
LRESULT CALLBACK            WndProc             (HWND, UINT, WPARAM, LPARAM);
 
43
 
 
44
 
 
45
extern int                  param_log_decor;    // in test.c
 
46
 
 
47
static HINSTANCE            hInst;
 
48
static HWND                 hwndLog;
 
49
static HFONT                hFixedFont;
 
50
 
 
51
 
 
52
static void write_log(int level, const char *data, int len)
 
53
{
 
54
    PJ_DECL_UNICODE_TEMP_BUF(wdata,256);
 
55
 
 
56
    PJ_UNUSED_ARG(level);
 
57
    PJ_UNUSED_ARG(len);
 
58
    SendMessage(hwndLog, EM_REPLACESEL, FALSE, 
 
59
                (LPARAM)PJ_STRING_TO_NATIVE(data,wdata,256));
 
60
}
 
61
 
 
62
 
 
63
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
 
64
                   LPTSTR lpCmdLine, int nCmdShow)
 
65
{
 
66
    MSG msg;
 
67
    
 
68
    PJ_UNUSED_ARG(lpCmdLine);
 
69
    PJ_UNUSED_ARG(hPrevInstance);
 
70
 
 
71
    
 
72
    if (!InitInstance (hInstance, nCmdShow))
 
73
        return FALSE;
 
74
    
 
75
    pj_log_set_log_func( &write_log );
 
76
    param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR;
 
77
 
 
78
    // Run the test!
 
79
    test_main();
 
80
 
 
81
    PJ_LOG(3,(THIS_FILE,""));
 
82
    PJ_LOG(3,(THIS_FILE,"Press ESC to quit"));
 
83
 
 
84
    // Message loop, waiting to quit.
 
85
    while (GetMessage(&msg, NULL, 0, 0)) {
 
86
        TranslateMessage(&msg);
 
87
        DispatchMessage(&msg);
 
88
    }
 
89
    
 
90
    DeleteObject(hFixedFont);
 
91
    return msg.wParam;
 
92
}
 
93
 
 
94
 
 
95
#ifdef _CONSOLE
 
96
int main()
 
97
{
 
98
    return WinMain(GetModuleHandle(NULL), NULL, NULL, SW_SHOW);
 
99
}
 
100
#endif
 
101
 
 
102
 
 
103
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
 
104
{
 
105
    WNDCLASS    wc;
 
106
    
 
107
    wc.style            = CS_HREDRAW | CS_VREDRAW;
 
108
    wc.lpfnWndProc      = (WNDPROC) WndProc;
 
109
    wc.cbClsExtra       = 0;
 
110
    wc.cbWndExtra       = 0;
 
111
    wc.hInstance        = hInstance;
 
112
    ///wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HELLO_WINCE));
 
113
    wc.hIcon            = NULL;
 
114
    wc.hCursor          = 0;
 
115
    wc.hbrBackground    = (HBRUSH) GetStockObject(WHITE_BRUSH);
 
116
    wc.lpszMenuName     = 0;
 
117
    wc.lpszClassName    = szWindowClass;
 
118
    
 
119
    return RegisterClass(&wc);
 
120
}
 
121
 
 
122
 
 
123
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 
124
{
 
125
    HWND        hWnd;
 
126
    TCHAR       *szTitle = _T("PJSIP Test");
 
127
    TCHAR       *szWindowClass = _T("PJSIP_TEST");
 
128
    LOGFONT     lf;
 
129
 
 
130
 
 
131
    memset(&lf, 0, sizeof(lf));
 
132
    lf.lfHeight = 13;
 
133
#if PJ_NATIVE_STRING_IS_UNICODE
 
134
    wcscpy(lf.lfFaceName, _T("Courier New"));
 
135
#else
 
136
    strcpy(lf.lfFaceName, "Lucida Console");
 
137
#endif
 
138
 
 
139
    hFixedFont = CreateFontIndirect(&lf);
 
140
    if (!hFixedFont)
 
141
        return FALSE;
 
142
 
 
143
    hInst = hInstance;
 
144
    
 
145
    MyRegisterClass(hInstance, szWindowClass);
 
146
    
 
147
    hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
 
148
                        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
 
149
                        CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
 
150
    
 
151
    if (!hWnd)
 
152
        return FALSE;
 
153
    
 
154
    ShowWindow(hWnd, nCmdShow);
 
155
    UpdateWindow(hWnd);
 
156
 
 
157
    if (hwndLog) {
 
158
        SendMessage(hwndLog, WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0);  
 
159
        ShowWindow(hwndLog, TRUE);
 
160
    }
 
161
 
 
162
    return TRUE;
 
163
}
 
164
 
 
165
 
 
166
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
167
{
 
168
    RECT rt;
 
169
    DWORD dwStyle;
 
170
    
 
171
    switch (message) 
 
172
    {
 
173
    case WM_CREATE:
 
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
 
180
                                NULL,               // window text
 
181
                                dwStyle,            // style
 
182
                                0,                  // x-left
 
183
                                0,                  // y-top
 
184
                                rt.right-rt.left,   // w
 
185
                                rt.bottom-rt.top,   // h
 
186
                                hWnd,               // parent
 
187
                                (HMENU)ID_LOGWINDOW,// id
 
188
                                hInst,              // instance
 
189
                                NULL);              // NULL for control.
 
190
        break;
 
191
    case WM_ACTIVATE:
 
192
        if (LOWORD(wParam) == WA_INACTIVE)
 
193
            DestroyWindow(hWnd);
 
194
        break;
 
195
    case WM_CHAR:
 
196
        if (wParam == 27) {
 
197
            DestroyWindow(hWnd);
 
198
        }
 
199
        break;
 
200
    case WM_CLOSE:
 
201
        DestroyWindow(hWnd);
 
202
        break;
 
203
    case WM_DESTROY:
 
204
        PostQuitMessage(0);
 
205
        break;
 
206
    default:
 
207
        return DefWindowProc(hWnd, message, wParam, lParam);
 
208
    }
 
209
    return 0;
 
210
}
 
211