blob: 2f3fc43ed25084e09a92ccb38e79b0372d557711 [file] [log] [blame]
Benny Prijono01f01542006-08-01 23:09:35 +00001// pjsua_wince.cpp : Defines the entry point for the application.
2//
3
4#include "stdafx.h"
5#include "pjsua_wince.h"
6#include <commctrl.h>
7#include <pjsua-lib/pjsua.h>
8
9#define MAX_LOADSTRING 100
10
11// Global Variables:
12static HINSTANCE hInst;
13static HWND hMainWnd;
14static HWND hwndCB;
Benny Prijonof20687a2006-08-04 18:27:19 +000015static HWND hwndGlobalStatus, hwndURI, hwndCallStatus;
16static HWND hwndActionButton, hwndExitButton;
Benny Prijono01f01542006-08-01 23:09:35 +000017
18static pj_pool_t *g_pool;
19static pj_str_t g_local_uri;
20static int g_current_acc;
21static int g_current_call = PJSUA_INVALID_ID;
Benny Prijonof20687a2006-08-04 18:27:19 +000022static int g_current_action;
Benny Prijono01f01542006-08-01 23:09:35 +000023
24enum
25{
26 ID_GLOBAL_STATUS = 21,
27 ID_URI,
28 ID_CALL_STATUS,
29 ID_POLL_TIMER,
30};
31
32enum
33{
34 ID_MENU_NONE = 64,
35 ID_MENU_CALL,
36 ID_MENU_ANSWER,
37 ID_MENU_DISCONNECT,
Benny Prijonof20687a2006-08-04 18:27:19 +000038 ID_BTN_ACTION,
Benny Prijono01f01542006-08-01 23:09:35 +000039};
40
Benny Prijono5da50432006-08-07 10:24:52 +000041#define DEFAULT_URI "sip:192.168.0.7"
Benny Prijonof20687a2006-08-04 18:27:19 +000042
Benny Prijono01f01542006-08-01 23:09:35 +000043
44// Forward declarations of functions included in this code module:
45static ATOM MyRegisterClass (HINSTANCE, LPTSTR);
46BOOL InitInstance (HINSTANCE, int);
47static void OnCreate (HWND hWnd);
48static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
49
50
51
52/////////////////////////////////////////////////////////////////////////////
53
54static void OnError(const wchar_t *title, pj_status_t status)
55{
56 char errmsg[PJ_ERR_MSG_SIZE];
57 PJ_DECL_UNICODE_TEMP_BUF(werrmsg, PJ_ERR_MSG_SIZE);
58
59 pj_strerror(status, errmsg, sizeof(errmsg));
60
61 MessageBox(NULL, PJ_STRING_TO_NATIVE(errmsg, werrmsg, PJ_ERR_MSG_SIZE),
62 title, MB_OK);
63}
64
65
66static void SetLocalURI(const char *uri, int len, bool enabled=true)
67{
68 wchar_t tmp[128];
Benny Prijonof20687a2006-08-04 18:27:19 +000069 if (len==-1) len=pj_ansi_strlen(uri);
Benny Prijono01f01542006-08-01 23:09:35 +000070 pj_ansi_to_unicode(uri, len, tmp, PJ_ARRAY_SIZE(tmp));
71 SetDlgItemText(hMainWnd, ID_GLOBAL_STATUS, tmp);
72 EnableWindow(hwndGlobalStatus, enabled?TRUE:FALSE);
73}
74
75
76
77static void SetURI(const char *uri, int len, bool enabled=true)
78{
79 wchar_t tmp[128];
Benny Prijonof20687a2006-08-04 18:27:19 +000080 if (len==-1) len=pj_ansi_strlen(uri);
Benny Prijono01f01542006-08-01 23:09:35 +000081 pj_ansi_to_unicode(uri, len, tmp, PJ_ARRAY_SIZE(tmp));
82 SetDlgItemText(hMainWnd, ID_URI, tmp);
83 EnableWindow(hwndURI, enabled?TRUE:FALSE);
84}
85
86
87static void SetCallStatus(const char *state, int len)
88{
89 wchar_t tmp[128];
Benny Prijonof20687a2006-08-04 18:27:19 +000090 if (len==-1) len=pj_ansi_strlen(state);
Benny Prijono01f01542006-08-01 23:09:35 +000091 pj_ansi_to_unicode(state, len, tmp, PJ_ARRAY_SIZE(tmp));
92 SetDlgItemText(hMainWnd, ID_CALL_STATUS, tmp);
93}
94
95static void SetAction(int action, bool enable=true)
96{
97 HMENU hMenu;
98
99 hMenu = CommandBar_GetMenu(hwndCB, 0);
100
101 RemoveMenu(hMenu, ID_MENU_NONE, MF_BYCOMMAND);
102 RemoveMenu(hMenu, ID_MENU_CALL, MF_BYCOMMAND);
103 RemoveMenu(hMenu, ID_MENU_ANSWER, MF_BYCOMMAND);
104 RemoveMenu(hMenu, ID_MENU_DISCONNECT, MF_BYCOMMAND);
105
106 switch (action) {
107 case ID_MENU_NONE:
108 InsertMenu(hMenu, ID_EXIT, MF_BYCOMMAND, action, TEXT("None"));
Benny Prijonof20687a2006-08-04 18:27:19 +0000109 SetWindowText(hwndActionButton, TEXT("-"));
Benny Prijono01f01542006-08-01 23:09:35 +0000110 break;
111 case ID_MENU_CALL:
112 InsertMenu(hMenu, ID_EXIT, MF_BYCOMMAND, action, TEXT("Call"));
Benny Prijonof20687a2006-08-04 18:27:19 +0000113 SetWindowText(hwndActionButton, TEXT("&Call"));
Benny Prijono01f01542006-08-01 23:09:35 +0000114 break;
115 case ID_MENU_ANSWER:
116 InsertMenu(hMenu, ID_EXIT, MF_BYCOMMAND, action, TEXT("Answer"));
Benny Prijonof20687a2006-08-04 18:27:19 +0000117 SetWindowText(hwndActionButton, TEXT("&Answer"));
Benny Prijono01f01542006-08-01 23:09:35 +0000118 break;
119 case ID_MENU_DISCONNECT:
120 InsertMenu(hMenu, ID_EXIT, MF_BYCOMMAND, action, TEXT("Hangup"));
Benny Prijonof20687a2006-08-04 18:27:19 +0000121 SetWindowText(hwndActionButton, TEXT("&Hangup"));
Benny Prijono01f01542006-08-01 23:09:35 +0000122 break;
123 }
124
125 EnableMenuItem(hMenu, action, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
Benny Prijonof20687a2006-08-04 18:27:19 +0000126 DrawMenuBar(hMainWnd);
127
128 g_current_action = action;
Benny Prijono01f01542006-08-01 23:09:35 +0000129}
130
131
132/*
133 * Handler when invite state has changed.
134 */
135static void on_call_state(pjsua_call_id call_id, pjsip_event *e)
136{
137 pjsua_call_info call_info;
138
139 PJ_UNUSED_ARG(e);
140
141 pjsua_call_get_info(call_id, &call_info);
142
143 if (call_info.state == PJSIP_INV_STATE_DISCONNECTED) {
144
145 g_current_call = PJSUA_INVALID_ID;
Benny Prijonof20687a2006-08-04 18:27:19 +0000146 SetURI(DEFAULT_URI, -1);
Benny Prijono01f01542006-08-01 23:09:35 +0000147 SetAction(ID_MENU_CALL);
Benny Prijonof20687a2006-08-04 18:27:19 +0000148 //SetCallStatus(call_info.state_text.ptr, call_info.state_text.slen);
149 SetCallStatus(call_info.last_status_text.ptr, call_info.last_status_text.slen);
Benny Prijono01f01542006-08-01 23:09:35 +0000150
151 } else {
Benny Prijonoedba0792006-08-06 18:23:56 +0000152 //if (g_current_call == PJSUA_INVALID_ID)
153 // g_current_call = call_id;
Benny Prijono01f01542006-08-01 23:09:35 +0000154
155 if (call_info.remote_contact.slen)
156 SetURI(call_info.remote_contact.ptr, call_info.remote_contact.slen, false);
157 else
158 SetURI(call_info.remote_info.ptr, call_info.remote_info.slen, false);
Benny Prijonoedba0792006-08-06 18:23:56 +0000159
160 if (call_info.state == PJSIP_INV_STATE_CONFIRMED)
161 SetAction(ID_MENU_DISCONNECT);
162
Benny Prijono01f01542006-08-01 23:09:35 +0000163 SetCallStatus(call_info.state_text.ptr, call_info.state_text.slen);
164 }
165}
166
167
168/*
169 * Callback on media state changed event.
170 * The action may connect the call to sound device, to file, or
171 * to loop the call.
172 */
173static void on_call_media_state(pjsua_call_id call_id)
174{
175 pjsua_call_info call_info;
176
177 pjsua_call_get_info(call_id, &call_info);
178
179 if (call_info.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
180 pjsua_conf_connect(call_info.conf_slot, 0);
181 pjsua_conf_connect(0, call_info.conf_slot);
182 }
183}
184
185
186/**
187 * Handler when there is incoming call.
188 */
189static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
190 pjsip_rx_data *rdata)
191{
192 pjsua_call_info call_info;
193
194 PJ_UNUSED_ARG(acc_id);
195 PJ_UNUSED_ARG(rdata);
196
197 if (g_current_call != PJSUA_INVALID_ID) {
Benny Prijonoedba0792006-08-06 18:23:56 +0000198 pj_str_t reason;
199 reason = pj_str("Another call is in progress");
200 pjsua_call_answer(call_id, PJSIP_SC_BUSY_HERE, &reason, NULL);
Benny Prijono01f01542006-08-01 23:09:35 +0000201 return;
202 }
203
204 g_current_call = call_id;
205
206 pjsua_call_get_info(call_id, &call_info);
207
208 SetAction(ID_MENU_ANSWER);
209 SetURI(call_info.remote_info.ptr, call_info.remote_info.slen, false);
Benny Prijonofd27c662006-08-09 11:59:26 +0000210 pjsua_call_answer(call_id, 200, NULL, NULL);
Benny Prijono01f01542006-08-01 23:09:35 +0000211}
212
213
214/*
215 * Handler registration status has changed.
216 */
217static void on_reg_state(pjsua_acc_id acc_id)
218{
219 PJ_UNUSED_ARG(acc_id);
220
221 // Log already written.
222}
223
224
225/*
226 * Handler on buddy state changed.
227 */
228static void on_buddy_state(pjsua_buddy_id buddy_id)
229{
230}
231
232
233/**
234 * Incoming IM message (i.e. MESSAGE request)!
235 */
236static void on_pager(pjsua_call_id call_id, const pj_str_t *from,
237 const pj_str_t *to, const pj_str_t *contact,
238 const pj_str_t *mime_type, const pj_str_t *text)
239{
240}
241
242
243/**
244 * Received typing indication
245 */
246static void on_typing(pjsua_call_id call_id, const pj_str_t *from,
247 const pj_str_t *to, const pj_str_t *contact,
248 pj_bool_t is_typing)
249{
250}
251
252
253
254static BOOL OnInitStack(void)
255{
256 pjsua_config cfg;
257 pjsua_logging_config log_cfg;
258 pjsua_media_config media_cfg;
259 pjsua_transport_config udp_cfg;
260 pjsua_transport_config rtp_cfg;
261 pjsua_transport_id transport_id;
262 pjsua_transport_info transport_info;
Benny Prijono7c3741f2006-08-05 21:07:15 +0000263 pj_str_t tmp;
Benny Prijono01f01542006-08-01 23:09:35 +0000264 pj_status_t status;
265
266 /* Create pjsua */
267 status = pjsua_create();
268 if (status != PJ_SUCCESS) {
269 OnError(TEXT("Error creating pjsua"), status);
270 return FALSE;
271 }
272
273 /* Create global pool for application */
274 g_pool = pjsua_pool_create("pjsua", 4000, 4000);
275
276 /* Init configs */
277 pjsua_config_default(&cfg);
278 pjsua_logging_config_default(&log_cfg);
279 pjsua_media_config_default(&media_cfg);
280 pjsua_transport_config_default(&udp_cfg);
Benny Prijonof20687a2006-08-04 18:27:19 +0000281 udp_cfg.port = 50060;
Benny Prijono01f01542006-08-01 23:09:35 +0000282 pjsua_transport_config_default(&rtp_cfg);
Benny Prijonof20687a2006-08-04 18:27:19 +0000283 rtp_cfg.port = 40000;
Benny Prijono01f01542006-08-01 23:09:35 +0000284
285 /* Setup media */
286 media_cfg.clock_rate = 8000;
Benny Prijono5da50432006-08-07 10:24:52 +0000287 media_cfg.ec_options = PJMEDIA_ECHO_SIMPLE;
Benny Prijonofd27c662006-08-09 11:59:26 +0000288 media_cfg.ec_tail_len = 256;
Benny Prijonoedba0792006-08-06 18:23:56 +0000289 media_cfg.quality = 1;
290 media_cfg.ptime = 20;
Benny Prijono01f01542006-08-01 23:09:35 +0000291
292 /* Initialize application callbacks */
293 cfg.cb.on_call_state = &on_call_state;
294 cfg.cb.on_call_media_state = &on_call_media_state;
295 cfg.cb.on_incoming_call = &on_incoming_call;
296 cfg.cb.on_reg_state = &on_reg_state;
297 cfg.cb.on_buddy_state = &on_buddy_state;
298 cfg.cb.on_pager = &on_pager;
299 cfg.cb.on_typing = &on_typing;
300
301 /* Initialize pjsua */
302 status = pjsua_init(&cfg, &log_cfg, &media_cfg);
303 if (status != PJ_SUCCESS) {
304 OnError(TEXT("Initialization error"), status);
305 return FALSE;
306 }
307
308 /* Set codec priority */
Benny Prijonoedba0792006-08-06 18:23:56 +0000309 pjsua_codec_set_priority(pj_cstr(&tmp, "pcmu"), 240);
310 pjsua_codec_set_priority(pj_cstr(&tmp, "pcma"), 230);
311 pjsua_codec_set_priority(pj_cstr(&tmp, "speex/8000"), 190);
Benny Prijonofd27c662006-08-09 11:59:26 +0000312 pjsua_codec_set_priority(pj_cstr(&tmp, "ilbc"), 189);
Benny Prijonoedba0792006-08-06 18:23:56 +0000313 pjsua_codec_set_priority(pj_cstr(&tmp, "speex/16000"), 180);
Benny Prijono7c3741f2006-08-05 21:07:15 +0000314 pjsua_codec_set_priority(pj_cstr(&tmp, "speex/32000"), 0);
Benny Prijonofd27c662006-08-09 11:59:26 +0000315 pjsua_codec_set_priority(pj_cstr(&tmp, "gsm"), 100);
Benny Prijono7c3741f2006-08-05 21:07:15 +0000316
Benny Prijono01f01542006-08-01 23:09:35 +0000317
318 /* Add UDP transport and the corresponding PJSUA account */
319 status = pjsua_transport_create(PJSIP_TRANSPORT_UDP,
320 &udp_cfg, &transport_id);
321 if (status != PJ_SUCCESS) {
322 OnError(TEXT("Error starting SIP transport"), status);
323 return FALSE;
324 }
325
326 pjsua_transport_get_info(transport_id, &transport_info);
327
328 g_local_uri.ptr = (char*)pj_pool_alloc(g_pool, 128);
329 g_local_uri.slen = pj_ansi_sprintf(g_local_uri.ptr,
330 "<sip:%.*s:%d>",
331 (int)transport_info.local_name.host.slen,
332 transport_info.local_name.host.ptr,
333 transport_info.local_name.port);
334
335
336 /* Add local account */
337 pjsua_acc_add_local(transport_id, PJ_TRUE, &g_current_acc);
338 pjsua_acc_set_online_status(g_current_acc, PJ_TRUE);
339
340 /* Start pjsua */
341 status = pjsua_start();
342 if (status != PJ_SUCCESS) {
343 OnError(TEXT("Error starting pjsua"), status);
344 return FALSE;
345 }
346
347 return TRUE;
348}
349
350
351//////////////////////////////////////////////////////////////////////////////
352
353int WINAPI WinMain(HINSTANCE hInstance,
354 HINSTANCE hPrevInstance,
355 LPTSTR lpCmdLine,
356 int nCmdShow)
357{
358 MSG msg;
359 HACCEL hAccelTable;
360
361
362
363 // Perform application initialization:
364 if (!InitInstance (hInstance, nCmdShow))
365 {
366 return FALSE;
367 }
368
369 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_PJSUA_WINCE);
370
371
372 // Main message loop:
373 while (GetMessage(&msg, NULL, 0, 0))
374 {
375 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
376 {
377 TranslateMessage(&msg);
378 DispatchMessage(&msg);
379 }
380 }
381
382 return msg.wParam;
383}
384
385static ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
386{
387 WNDCLASS wc;
388
389 wc.style = CS_HREDRAW | CS_VREDRAW;
390 wc.lpfnWndProc = (WNDPROC) WndProc;
391 wc.cbClsExtra = 0;
392 wc.cbWndExtra = 0;
393 wc.hInstance = hInstance;
394 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PJSUA_WINCE));
395 wc.hCursor = 0;
396 wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
397 wc.lpszMenuName = 0;
398 wc.lpszClassName = szWindowClass;
399
400 return RegisterClass(&wc);
401}
402
403
404
405BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
406{
407 HWND hWnd;
408 TCHAR szTitle[MAX_LOADSTRING];
409 TCHAR szWindowClass[MAX_LOADSTRING];
410
411 hInst = hInstance;
412
413 /* Init stack */
414 if (OnInitStack() == FALSE)
415 return FALSE;
416
417 LoadString(hInstance, IDC_PJSUA_WINCE, szWindowClass, MAX_LOADSTRING);
418 MyRegisterClass(hInstance, szWindowClass);
419
420 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
421 hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
Benny Prijonof20687a2006-08-04 18:27:19 +0000422 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 200,
Benny Prijono01f01542006-08-01 23:09:35 +0000423 NULL, NULL, hInstance, NULL);
424
425 if (!hWnd)
426 {
427 return FALSE;
428 }
429
430 hMainWnd = hWnd;
431 ShowWindow(hWnd, nCmdShow);
432 UpdateWindow(hWnd);
433 if (hwndCB)
434 CommandBar_Show(hwndCB, TRUE);
435
436 SetTimer(hMainWnd, ID_POLL_TIMER, 50, NULL);
437 return TRUE;
438}
439
440
441static void OnCreate(HWND hWnd)
442{
443 enum
444 {
445 X = 10,
Benny Prijonof20687a2006-08-04 18:27:19 +0000446 Y = 40,
Benny Prijono01f01542006-08-01 23:09:35 +0000447 W = 220,
448 H = 30,
449 };
450
451 DWORD dwStyle;
452
453 hMainWnd = hWnd;
454
455 hwndCB = CommandBar_Create(hInst, hWnd, 1);
456 CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
457 CommandBar_AddAdornments(hwndCB, 0, 0);
458
459 // Create global status text
460 dwStyle = WS_CHILD | WS_VISIBLE | WS_DISABLED | ES_LEFT;
461 hwndGlobalStatus = CreateWindow(
462 TEXT("EDIT"), // Class name
463 NULL, // Window text
464 dwStyle, // Window style
465 X, // x-coordinate of the upper-left corner
Benny Prijonof20687a2006-08-04 18:27:19 +0000466 Y+0, // y-coordinate of the upper-left corner
Benny Prijono01f01542006-08-01 23:09:35 +0000467 W, // Width of the window for the edit
468 // control
Benny Prijonof20687a2006-08-04 18:27:19 +0000469 H-5, // Height of the window for the edit
Benny Prijono01f01542006-08-01 23:09:35 +0000470 // control
471 hWnd, // Window handle to the parent window
472 (HMENU) ID_GLOBAL_STATUS, // Control identifier
473 hInst, // Instance handle
474 NULL); // Specify NULL for this parameter when
475 // you create a control
476 SetLocalURI(g_local_uri.ptr, g_local_uri.slen, false);
477
478
479 // Create URI edit
480 dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER;
481 hwndURI = CreateWindow (
482 TEXT("EDIT"), // Class name
483 NULL, // Window text
484 dwStyle, // Window style
485 X, // x-coordinate of the upper-left corner
Benny Prijonof20687a2006-08-04 18:27:19 +0000486 Y+H, // y-coordinate of the upper-left corner
Benny Prijono01f01542006-08-01 23:09:35 +0000487 W, // Width of the window for the edit
488 // control
Benny Prijonof20687a2006-08-04 18:27:19 +0000489 H-5, // Height of the window for the edit
Benny Prijono01f01542006-08-01 23:09:35 +0000490 // control
491 hWnd, // Window handle to the parent window
492 (HMENU) ID_URI, // Control identifier
493 hInst, // Instance handle
494 NULL); // Specify NULL for this parameter when
495 // you create a control
Benny Prijonof20687a2006-08-04 18:27:19 +0000496
497 // Create action Button
498 hwndActionButton = CreateWindow( L"button", L"Action",
499 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
500 X, Y+2*H,
501 60, H-5, hWnd,
502 (HMENU) ID_BTN_ACTION,
503 hInst, NULL );
504
505 // Create exit button
506 hwndExitButton = CreateWindow( L"button", L"E&xit",
507 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
508 X+70, Y+2*H,
509 60, H-5, hWnd,
510 (HMENU) ID_EXIT,
511 hInst, NULL );
512
Benny Prijono01f01542006-08-01 23:09:35 +0000513
514 // Create call status edit
515 dwStyle = WS_CHILD | WS_VISIBLE | WS_DISABLED;
516 hwndCallStatus = CreateWindow (
517 TEXT("EDIT"), // Class name
518 NULL, // Window text
519 dwStyle, // Window style
520 X, // x-coordinate of the upper-left corner
Benny Prijonof20687a2006-08-04 18:27:19 +0000521 Y+3*H, // y-coordinate of the upper-left corner
Benny Prijono01f01542006-08-01 23:09:35 +0000522 W, // Width of the window for the edit
523 // control
Benny Prijonof20687a2006-08-04 18:27:19 +0000524 H-5, // Height of the window for the edit
Benny Prijono01f01542006-08-01 23:09:35 +0000525 // control
526 hWnd, // Window handle to the parent window
527 (HMENU) ID_CALL_STATUS, // Control identifier
528 hInst, // Instance handle
529 NULL); // Specify NULL for this parameter when
530 // you create a control
531 SetCallStatus("Ready", 5);
Benny Prijono01f01542006-08-01 23:09:35 +0000532 SetAction(ID_MENU_CALL);
Benny Prijonof20687a2006-08-04 18:27:19 +0000533 SetURI(DEFAULT_URI, -1);
Benny Prijono39ea7f02006-09-14 13:52:29 +0000534 SetFocus(hWnd);
Benny Prijonof20687a2006-08-04 18:27:19 +0000535
Benny Prijono01f01542006-08-01 23:09:35 +0000536}
537
538
539static void OnDestroy(void)
540{
541 pjsua_destroy();
542}
543
544static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
545{
546 int wmId, wmEvent;
547
548 switch (message) {
Benny Prijono39ea7f02006-09-14 13:52:29 +0000549 case WM_KEYUP:
550 if (wParam==114) {
551 wParam = ID_MENU_CALL;
552 } else if (wParam==115) {
553 if (g_current_call == PJSUA_INVALID_ID)
554 wParam = ID_EXIT;
555 else
556 wParam = ID_MENU_DISCONNECT;
557 } else
558 break;
559
Benny Prijono01f01542006-08-01 23:09:35 +0000560 case WM_COMMAND:
561 wmId = LOWORD(wParam);
562 wmEvent = HIWORD(wParam);
Benny Prijonof20687a2006-08-04 18:27:19 +0000563 if (wmId == ID_BTN_ACTION)
564 wmId = g_current_action;
Benny Prijono01f01542006-08-01 23:09:35 +0000565 switch (wmId)
566 {
567 case ID_MENU_CALL:
568 if (g_current_call != PJSUA_INVALID_ID) {
569 MessageBox(NULL, TEXT("Can not make call"),
570 TEXT("You already have one call active"), MB_OK);
571 }
572 pj_str_t dst_uri;
573 wchar_t text[256];
574 char tmp[256];
575 pj_status_t status;
576
577 GetWindowText(hwndURI, text, PJ_ARRAY_SIZE(text));
578 pj_unicode_to_ansi(text, pj_unicode_strlen(text),
579 tmp, sizeof(tmp));
580 dst_uri.ptr = tmp;
581 dst_uri.slen = pj_ansi_strlen(tmp);
582 status = pjsua_call_make_call(g_current_acc,
583 &dst_uri, 0, NULL,
584 NULL, &g_current_call);
585 if (status != PJ_SUCCESS)
586 OnError(TEXT("Unable to make call"), status);
587 break;
588 case ID_MENU_ANSWER:
589 if (g_current_call == PJSUA_INVALID_ID)
590 MessageBox(NULL, TEXT("Can not answer"),
591 TEXT("There is no call!"), MB_OK);
Benny Prijonoedba0792006-08-06 18:23:56 +0000592 else
593 pjsua_call_answer(g_current_call, 200, NULL, NULL);
Benny Prijono01f01542006-08-01 23:09:35 +0000594 break;
595 case ID_MENU_DISCONNECT:
596 if (g_current_call == PJSUA_INVALID_ID)
597 MessageBox(NULL, TEXT("Can not disconnect"),
598 TEXT("There is no call!"), MB_OK);
599 else
600 pjsua_call_hangup(g_current_call, PJSIP_SC_DECLINE, NULL, NULL);
601 break;
602 case ID_EXIT:
603 DestroyWindow(hWnd);
604 break;
605 default:
606 return DefWindowProc(hWnd, message, wParam, lParam);
607 }
608 break;
609
610 case WM_CREATE:
611 OnCreate(hWnd);
612 break;
613
614 case WM_DESTROY:
615 OnDestroy();
616 CommandBar_Destroy(hwndCB);
617 PostQuitMessage(0);
618 break;
619
620 case WM_TIMER:
621 pjsua_handle_events(1);
622 break;
623
624 default:
625 return DefWindowProc(hWnd, message, wParam, lParam);
626 }
627 return 0;
628}
629