⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pjsua_wince.cpp

📁 一个开源SIP协议栈
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    pjsua_codec_set_priority(pj_cstr(&tmp, "speex/32000"), 0);
    pjsua_codec_set_priority(pj_cstr(&tmp, "gsm"), 100);


    /* Add UDP transport and the corresponding PJSUA account */
    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP,
				    &udp_cfg, &transport_id);
    if (status != PJ_SUCCESS) {
	OnError(TEXT("Error starting SIP transport"), status);
	return FALSE;
    }

    pjsua_transport_get_info(transport_id, &transport_info);

    g_local_uri.ptr = (char*)pj_pool_alloc(g_pool, 128);
    g_local_uri.slen = pj_ansi_sprintf(g_local_uri.ptr,
				       "<sip:%.*s:%d>",
				       (int)transport_info.local_name.host.slen,
				       transport_info.local_name.host.ptr,
				       transport_info.local_name.port);


    /* Add local account */
    pjsua_acc_add_local(transport_id, PJ_TRUE, &g_current_acc);
    pjsua_acc_set_online_status(g_current_acc, PJ_TRUE);

    /* Start pjsua */
    status = pjsua_start();
    if (status != PJ_SUCCESS) {
	OnError(TEXT("Error starting pjsua"), status);
	return FALSE;
    }

    return TRUE;
}


//////////////////////////////////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE hInstance,
		   HINSTANCE hPrevInstance,
		   LPTSTR    lpCmdLine,
		   int       nCmdShow)
{
    MSG msg;
    HACCEL hAccelTable;
    


    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow)) 
    {
	return FALSE;
    }
    
    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_PJSUA_WINCE);
    
    
    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
	if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
	{
	    TranslateMessage(&msg);
	    DispatchMessage(&msg);
	}
    }
    
    return msg.wParam;
}

static 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_PJSUA_WINCE));
    wc.hCursor		= 0;
    wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName	= 0;
    wc.lpszClassName	= szWindowClass;

    return RegisterClass(&wc);
}



BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND	hWnd;
    TCHAR	szTitle[MAX_LOADSTRING];
    TCHAR	szWindowClass[MAX_LOADSTRING];

    hInst = hInstance;

    /* Init stack */
    if (OnInitStack() == FALSE)
	return FALSE;

    LoadString(hInstance, IDC_PJSUA_WINCE, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance, szWindowClass);

    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
	    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 200, 
	    NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {	
	    return FALSE;
    }

    hMainWnd = hWnd;
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    if (hwndCB)
	CommandBar_Show(hwndCB, TRUE);

    SetTimer(hMainWnd, ID_POLL_TIMER, 50, NULL);
    return TRUE;
}


static void OnCreate(HWND hWnd)
{
    enum 
    {
	X = 10,
	Y = 40,
	W = 220,
	H = 30,
    };

    DWORD dwStyle;

    hMainWnd = hWnd;

    hwndCB = CommandBar_Create(hInst, hWnd, 1);			
    CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);   
    CommandBar_AddAdornments(hwndCB, 0, 0);

    // Create global status text
    dwStyle = WS_CHILD | WS_VISIBLE | WS_DISABLED | ES_LEFT;  
    hwndGlobalStatus = CreateWindow(
                TEXT("EDIT"),   // Class name
                NULL,           // Window text
                dwStyle,        // Window style
                X,		// x-coordinate of the upper-left corner
                Y+0,            // y-coordinate of the upper-left corner
                W,		// Width of the window for the edit
                                // control
                H-5,		// Height of the window for the edit
                                // control
                hWnd,           // Window handle to the parent window
                (HMENU) ID_GLOBAL_STATUS, // Control identifier
                hInst,           // Instance handle
                NULL);          // Specify NULL for this parameter when 
                                // you create a control
    SetLocalURI(g_local_uri.ptr, g_local_uri.slen, false);


    // Create URI edit
    dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER;  
    hwndURI = CreateWindow (
                TEXT("EDIT"),   // Class name
                NULL,		// Window text
                dwStyle,        // Window style
                X,  // x-coordinate of the upper-left corner
                Y+H,  // y-coordinate of the upper-left corner
                W,  // Width of the window for the edit
                                // control
                H-5,  // Height of the window for the edit
                                // control
                hWnd,           // Window handle to the parent window
                (HMENU) ID_URI, // Control identifier
                hInst,           // Instance handle
                NULL);          // Specify NULL for this parameter when 
                                // you create a control

    // Create action Button
    hwndActionButton = CreateWindow( L"button", L"Action", 
                         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
                         X, Y+2*H, 
			 60, H-5, hWnd, 
                         (HMENU) ID_BTN_ACTION,
                         hInst, NULL );

    // Create exit button
    hwndExitButton = CreateWindow( L"button", L"E&xit", 
                         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
                         X+70, Y+2*H, 
			 60, H-5, hWnd, 
                         (HMENU) ID_EXIT,
                         hInst, NULL );


    // Create call status edit
    dwStyle = WS_CHILD | WS_VISIBLE | WS_DISABLED;  
    hwndCallStatus = CreateWindow (
                TEXT("EDIT"),   // Class name
                NULL,		// Window text
                dwStyle,        // Window style
                X,  // x-coordinate of the upper-left corner
                Y+3*H,  // y-coordinate of the upper-left corner
                W,  // Width of the window for the edit
                                // control
                H-5,  // Height of the window for the edit
                                // control
                hWnd,           // Window handle to the parent window
                (HMENU) ID_CALL_STATUS, // Control identifier
                hInst,           // Instance handle
                NULL);          // Specify NULL for this parameter when 
                                // you create a control
    SetCallStatus("Ready", 5);
    SetAction(ID_MENU_CALL);
    SetURI(DEFAULT_URI, -1);
    SetFocus(hWnd);

}


static void OnDestroy(void)
{
    pjsua_destroy();
}

static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    
    switch (message) {
    case WM_KEYUP:
	if (wParam==114) {
	    wParam = ID_MENU_CALL;
	} else if (wParam==115) {
	    if (g_current_call == PJSUA_INVALID_ID)
		wParam = ID_EXIT;
	    else
		wParam = ID_MENU_DISCONNECT;
	} else
	    break;

    case WM_COMMAND:
	wmId    = LOWORD(wParam); 
	wmEvent = HIWORD(wParam); 
	if (wmId == ID_BTN_ACTION)
	    wmId = g_current_action;
	switch (wmId)
	{
	case ID_MENU_CALL:
	    if (g_current_call != PJSUA_INVALID_ID) {
		MessageBox(NULL, TEXT("Can not make call"), 
			   TEXT("You already have one call active"), MB_OK);
	    }
	    pj_str_t dst_uri;
	    wchar_t text[256];
	    char tmp[256];
	    pj_status_t status;

	    GetWindowText(hwndURI, text, PJ_ARRAY_SIZE(text));
	    pj_unicode_to_ansi(text, pj_unicode_strlen(text),
			       tmp, sizeof(tmp));
	    dst_uri.ptr = tmp;
	    dst_uri.slen = pj_ansi_strlen(tmp);
	    status = pjsua_call_make_call(g_current_acc,
						      &dst_uri, 0, NULL,
						      NULL, &g_current_call);
	    if (status != PJ_SUCCESS)
		OnError(TEXT("Unable to make call"), status);
	    break;
	case ID_MENU_ANSWER:
	    if (g_current_call == PJSUA_INVALID_ID)
		MessageBox(NULL, TEXT("Can not answer"), 
			   TEXT("There is no call!"), MB_OK);
	    else
		pjsua_call_answer(g_current_call, 200, NULL, NULL);
	    break;
	case ID_MENU_DISCONNECT:
	    if (g_current_call == PJSUA_INVALID_ID)
		MessageBox(NULL, TEXT("Can not disconnect"), 
			   TEXT("There is no call!"), MB_OK);
	    else
		pjsua_call_hangup(g_current_call, PJSIP_SC_DECLINE, NULL, NULL);
	    break;
	case ID_EXIT:
	    DestroyWindow(hWnd);
	    break;
	default:
	    return DefWindowProc(hWnd, message, wParam, lParam);
	}
	break;

    case WM_CREATE:
	OnCreate(hWnd);
	break;

    case WM_DESTROY:
	OnDestroy();
	CommandBar_Destroy(hwndCB);
	PostQuitMessage(0);
	break;

    case WM_TIMER:
	pjsua_handle_events(1);
	break;

    default:
	return DefWindowProc(hWnd, message, wParam, lParam);
    }
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -