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

📄 dialer.c

📁 Dialer ---- Windows TAPI sample application created as an illustration of the usage of Windows TAPI
💻 C
📖 第 1 页 / 共 5 页
字号:
    if(szLine1[0])
        {
        if(ghFontBtnText && pszLine2)
            hFontPrev = SelectObject(hDC, ghFontBtnText);
        
        GetTextMetrics(hDC, &tm);
        rcText.bottom = (rcBtn.bottom + rcBtn.top)/2 - 2;
        rcText.top = rcText.bottom - (tm.tmHeight - 1);

        if(pszLine2 == NULL)
            OffsetRect(&rcText, 0, (rcText.bottom - rcText.top)/2);

        if(fHighlighted)
            OffsetRect(&rcText, 1, 1);

        DrawText(hDC, szLine1, -1, &rcText, DT_SINGLELINE | DT_CENTER);

        if(hFontPrev)
            SelectObject(hDC, hFontPrev);
        }
    if(pszLine2) // recall that pszLine2 == NULL to represent no second string
        {
        GetTextMetrics(hDC, &tm);
        if(IDD_Btn == IDD_DBUTTONSTAR || IDD_Btn == IDD_DBUTTONPOUND)
            rcText.top = (rcBtn.bottom + rcBtn.top)/2 - (tm.tmHeight)/2;
        else
            rcText.top = (rcBtn.bottom + rcBtn.top)/2 - 2;
        rcText.bottom = rcText.top + tm.tmHeight;

        if(fHighlighted)
            OffsetRect(&rcText, 1, 1);

        DrawText(hDC, pszLine2, -1, &rcText, DT_SINGLELINE | DT_CENTER);
        }

    SetBkMode(hDC, BkModePrev);
    }



//***************************************************************************
//***************************************************************************
//***************************************************************************
VOID DisableDialButtons(BOOL fDisable)
{
	int IDD;

	// Disable/enable Dial button
	EnableWindow( GetDlgItem( ghWndMain, IDD_DDIAL ),!fDisable) ;

	// Disable/enable Speed dial buttons
	for ( IDD = IDD_DSPEEDDIAL1; IDD <= IDD_DSPEEDDIAL8; ++IDD )
	{
		EnableWindow(GetDlgItem(ghWndMain, IDD),!fDisable);
	}
}



//***************************************************************************
//***************************************************************************
//***************************************************************************
VOID DialerCleanup(VOID)
    {
    RECT rc;
    WORD cItem; // count of numbers in combo box
    DWORD cLastDialed;
    char szPt[MAXBUFSIZE];
    char szNumber[TAPIMAXDESTADDRESSSIZE];
    char szFieldName[MAXBUFSIZE];

    CloseTAPI(); // unregister and line close

    if(!IsIconic(ghWndMain)) // if the window is not minimized, record position
        {
        GetWindowRect(ghWndMain, &rc);
        wsprintf(szPt, "%ld, %ld", rc.left, rc.top);
        WritePrivateProfileString(
            "Preference",
            "Main Window Left/Top",
            szPt,
            gszINIfilename
            );
        }

    cItem = (WORD)SendDlgItemMessage(ghWndMain, IDD_DCOMBO, CB_GETCOUNT, 0, 0);

    // write out last dialed numbers from combo box (write to INI)
    for(cLastDialed = 1; cLastDialed <= NLASTDIALED; ++cLastDialed)
        {
        if(cLastDialed <= cItem)
            SendDlgItemMessage(
                ghWndMain,
                IDD_DCOMBO,
                CB_GETLBTEXT,
                cLastDialed - 1, // it's a zero-based count
                (LPARAM)(LPCSTR)szNumber);

        else
            szNumber[0] = 0;

        wsprintf(szFieldName, "Last dialed %d", cLastDialed);
        WritePrivateProfileString(
            "Last dialed numbers",
            szFieldName,
            szNumber,            
            gszINIfilename
            );

        }

    DestroyWindow(ghWndMain);
    ghWndMain = NULL;

    DeleteObject(ghFontBtn);
    DeleteObject(ghFontBtnText);
    DeleteObject(ghFontBtnStar);
    }



//***************************************************************************
//***************************************************************************
//***************************************************************************
// unregister and line close
VOID CloseTAPI(VOID) 
{

	// unregister as call manager
	lineRegisterRequestRecipient (
									ghLineApp,
									0, // registration instance
									LINEREQUESTMODE_MAKECALL,
									FALSE
								 );

	if ( gCurrentLineInfo.hLine )
	{
		lineClose ( gCurrentLineInfo.hLine );
		gfCurrentLineAvail = FALSE;
		gCurrentLineInfo.hLine = (HLINE)((ULONG_PTR)NULL);
	}

	lineShutdown(ghLineApp);
}



//***************************************************************************
//***************************************************************************
//***************************************************************************
BOOL CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HICON hIcon;

        switch (msg)
        {
            case WM_INITDIALOG:
                hIcon = LoadIcon( ghInst, (LPCSTR) MAKEINTRESOURCE( IDI_DIALER ) );
                return TRUE;

            case WM_SYSCOMMAND:
                switch( (DWORD) wParam )
                {
                    case SC_CLOSE:                    
                        PostQuitMessage(0);
                }
                break;

            case WM_INITMENUPOPUP:
                // if edit menu
                if ( LOWORD(lParam) == 1 ) 
                {
                    UINT wEnable;

                    if ( GetParent( GetFocus() ) != GetDlgItem( ghWndMain, IDD_DCOMBO ) )
                    {
                        wEnable = MF_GRAYED;
                    }
                    else
                    {
                        LONG lSelect = (LONG)SendDlgItemMessage (
                            ghWndMain,
                            IDD_DCOMBO,
                            CB_GETEDITSEL,
                            0,
                            0
                            );

                        if ( HIWORD( lSelect ) != LOWORD( lSelect ) )
                            wEnable = MF_ENABLED;
                        else
                            wEnable = MF_GRAYED;
                    }

                    EnableMenuItem((HMENU)wParam, IDM_EDIT_CUT, wEnable);
                    EnableMenuItem((HMENU)wParam, IDM_EDIT_COPY, wEnable);
                    EnableMenuItem((HMENU)wParam, IDM_EDIT_DELETE, wEnable);

                    // enable paste option is there is data 
                    // in the clipboard
                    if ( IsClipboardFormatAvailable( CF_TEXT ) )
                    {
                        if ( GetClipboardData ( CF_TEXT ) )
                        {
                            wEnable = MF_ENABLED;
                        }
                        else
                        {
                            wEnable = MF_GRAYED;
                        }
                    }
                    else
                    {
                        wEnable = MF_GRAYED;	
                    }

                }
                break;


            case WM_COMMAND:
            {
                char szName[TAPIMAXCALLEDPARTYSIZE] = {'\0'};
                char szNumber[TAPIMAXDESTADDRESSSIZE] = {'\0'};

                switch( LOWORD( (DWORD)wParam ) )
                {
                    // FILE menu
                    case IDM_EXIT:
                        PostQuitMessage(0);                    
                        return TRUE;


                        // EDIT menu
                    case IDM_EDIT_CUT:
                        SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_CUT, 0, 0);
                        return TRUE;

                    case IDM_EDIT_COPY:
                        SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_COPY, 0, 0);
                        return TRUE;

                    case IDM_EDIT_PASTE:
                        SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_PASTE, 0, 0);
                        return TRUE;

                    case IDM_EDIT_DELETE:
                        SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_CLEAR, 0, 0);
                        return TRUE;

                    case IDM_EDIT_SPEEDDIAL:
                        DialogBoxParam (
                                        ghInst,
                                        MAKEINTRESOURCE(IDD_SD1),
                                        ghWndMain,
                                        (DLGPROC)SpeedDial1Proc,
                                        0
                                       );
                        SetFocus(GetDlgItem(ghWndMain, IDD_DDIAL));
                        return TRUE;

                        // TOOLS menu
                    case IDM_CONNECTUSING:
                        DialogBoxParam (
                                        ghInst,
                                        MAKEINTRESOURCE(IDD_CONNECTUSING),
                                        ghWndMain,
                                        (DLGPROC)ConnectUsingProc,
                                        MENU_CHOICE
                                       );
                        return TRUE;

                    case IDM_LOCATION:
                    {
                        char szCanNumber[ TAPIMAXDESTADDRESSSIZE ] = "";

                        // fetch the number to be dialed
                        if ( GetDlgItemText ( 
                                              ghWndMain,
                                              IDD_DCOMBO,
                                              szNumber,
                                              TAPIMAXDESTADDRESSSIZE
                                            )
                           )
                        {
                            // if a number exists, convert it to 
                            // its canonical form.
                            if ( !MakeCanonicalNumber ( szNumber, szCanNumber ) )
                            {
                                lstrcpy( szCanNumber, szNumber );
                            }
                        }

                        lineTranslateDialog (
                                             ghLineApp,
                                             0,
                                             TAPI_CURRENT_VERSION,
                                             ghWndMain,
                                             szCanNumber
                                            );
                        return TRUE;

                    }
                    // HELP menu

                    case IDM_ABOUT:
                        DialogBoxParam(
                                       ghInst,
                                       MAKEINTRESOURCE(IDD_ABOUT),
                                       ghWndMain,
                                       (DLGPROC)AboutProc,
                                       0
                                      );

                        return TRUE;


                        // Accelerator processing
                    case IDM_ACCEL_NUMTODIAL:
                        if(GetActiveWindow() == ghWndMain)
                            SetFocus(GetDlgItem(ghWndMain, IDD_DCOMBO));
                        return TRUE;


                        // Buttons
                    case IDD_DDIAL:

                    {
                        DWORD cSDEntry;
                        char szSDNumber[TAPIMAXDESTADDRESSSIZE];
                        char szFieldName[MAXBUFSIZE];

                        // check if number entered is dialable
                        if ( SendMessage (
                                          GetDlgItem(ghWndMain, IDD_DCOMBO),
                                          WM_GETTEXTLENGTH,
                                          0,
                                          0
                                         ) > 0 
                           )
                        {
                            // get the number to be dialed
                            GetDlgItemText (
                                            ghWndMain,
                                            IDD_DCOMBO,
                                            (LPSTR)szNumber,
                                            TAPIMAXDESTADDRESSSIZE
                                           );

                            // check if it is a speed dial number.  
                            // If so choose the name to be displayed.
                            for( cSDEntry = 1; cSDEntry <= NSPEEDDIALS; ++cSDEntry)
                            {
                                wsprintf(szFieldName, "Number%d", cSDEntry);
                                GetPrivateProfileString (
                                    "Speed Dial Settings",
                                    szFieldName,
                                    gszNULL,
                                    szSDNumber,
                                    TAPIMAXCALLEDPARTYSIZE - 1,
                                    gszINIfilename
                                    );

                                // if the number matches, get the name
                                if ( lstrcmp(szSDNumber, szNumber) == 0 )
                                {
                                    wsprintf( szFieldName, "Name%d", cSDEntry);
                                    GetPrivateProfileString (
                                        "Speed Dial Settings",
                                        szFieldName,
                                        gszNULL,
                                        szName,
                                        TAPIMAXCALLEDPARTYSIZE - 1,
                                        gszINIfilename
                                        );
                                    break;
                                }
                            }

                            SetFocus( GetDlgItem( ghWndMain, IDD_DDIAL ) );

                            // once the currentline has been set
                            // using the connect proc
                            // the user must hit dial again 
                            if ( giCurrentLine == (DWORD)-1 )
                            {
                                DialogBoxParam (
                                                ghInst,
                                                MAKEINTRESOURCE(IDD_CONNECTUSING),
                                                ghWndMain,
                                                (DLGPROC)ConnectUsingProc,
                                                INVALID_LINE
                                               );
                            }
                            else
                            {
                                AddToRedialList(szNumber);
                                InitiateCall(szNumber, szName);
                            }
                        }
                        return TRUE;
                    }


                    case IDD_DBUTTON1:
                    case IDD_DBUTTON2:
                    case IDD_DBUTTON3:
                    case IDD_DBUTTON4:
                    case IDD_DBUTTON5:
                    case IDD_DBUTTON6:
                    case IDD_DBUTTON7:
                    case IDD_DBUTTON8:
                    case IDD_DBUTTON9:
                    case IDD_DBUTTON0:
                    case IDD_DBUTTONSTAR:
                    case IDD_DBUTTONPOUND:
                    {
                        int     i;
                        TCHAR   szBuffer[TAPIMAXDESTADDRESSSIZE+1];

                        static const char digits[] = { '1', '2', '3', '4',
                        '5', '6', '7', '8',
                        '9', '0', '*', '#' };

                        i = (int)SendDlgItemMessage(ghWndMain,
                                               IDD_DCOMBO,
                                               WM_GETTEXT,
                                               (WPARAM)TAPIMAXDESTADDRESSSIZE+1,
                                               (LPARAM)szBuffer);

                        if (i < TAPIMAXDESTADDRESSSIZE)
                        {
                            MoveMemory(szBuffer+gdwStartSel+1,

⌨️ 快捷键说明

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