//--------------------------------------------------------------------------- // // Module: simple.c // // Purpose: // The sample application demonstrates the usage of the Simple TAPI // API. // //--------------------------------------------------------------------------- // #include "tapi.h" #include "resource.h" #include void MakeLettersIntoDigits (LPSTR dialstring); LRESULT CALLBACK DialDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ); BOOL NEAR InitApplication( HANDLE hInstance ); HWND NEAR InitInstance( HANDLE hInstance, int nCmdShow ); LRESULT FAR PASCAL SIMPLEWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); #define MAXDSZ 30 //max size of dial string parts char szDialString[100]; //phone number to dial HINSTANCE ghInst; //global instance handle, for now. HWND hSIMPLEWnd; //global window handle char *gszSimpleClass="Simple"; //window class name char *gszAppName="Simple"; //application name // // FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int) // // PURPOSE: calls initialization function, processes message loop // // COMMENTS: // // Windows recognizes this function by name as the initial entry point // for the program. This function calls the application initialization // routine, if no other instance of the program is running, and always // calls the instance initialization routine. It then executes a // message retrieval and dispatch loop that is the top-level control // structure for the remainder of execution. The loop is terminated // when a WM_QUIT message is received, at which time this function // exits the application instance by returning the value passed by // PostQuitMessage(). // // If this function must abort before entering the message loop, it // returns the conventional value NULL. // int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; // Other instances of app running? if (!hPrevInstance) { // Initialize shared things if (!InitApplication(hInstance)) { return (FALSE); // Exits if unable to initialize } } if (NULL == (hSIMPLEWnd = InitInstance( hInstance, nCmdShow ))) return ( FALSE ) ; ghInst = hInstance; while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator (msg.hwnd, NULL, &msg)) { TranslateMessage(&msg);// Translates virtual key codes DispatchMessage(&msg); // Dispatches message to window } } /* end while (not a quit message) */ // Returns the value from PostQuitMessage return (msg.wParam); // This will prevent 'unused formal parameter' warnings lpCmdLine; } //--------------------------------------------------------------------------- // BOOL NEAR InitApplication( HANDLE hInstance ) // // Description: // First time initialization stuff. This registers information // such as window classes. // // Parameters: // HANDLE hInstance // Handle to this instance of the application. // //--------------------------------------------------------------------------- BOOL NEAR InitApplication( HANDLE hInstance ) { WNDCLASS wndclass ; // register window class wndclass.style = 0 ; wndclass.lpfnWndProc = SIMPLEWndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = sizeof( DWORD ) ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( SIMPLEICON ) ); wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ) ; wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ; wndclass.lpszMenuName = MAKEINTRESOURCE( SIMPLEMENU ) ; wndclass.lpszClassName = gszSimpleClass ; return( RegisterClass( &wndclass ) ) ; } // end of InitApplication() //--------------------------------------------------------------------------- // HWND NEAR InitInstance( HANDLE hInstance, int nCmdShow ) // // Description: // Initializes instance specific information. // // Parameters: // HANDLE hInstance // Handle to instance // // int nCmdShow // How do we show the window? // //--------------------------------------------------------------------------- HWND NEAR InitInstance( HANDLE hInstance, int nCmdShow ) { HWND hSIMPLEWnd ; // create the SIMPLE window hSIMPLEWnd = CreateWindow( gszSimpleClass, gszAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ) ; if (NULL == hSIMPLEWnd) return ( NULL ) ; ShowWindow( hSIMPLEWnd, nCmdShow ) ; UpdateWindow( hSIMPLEWnd ) ; return ( hSIMPLEWnd ) ; } // end of InitInstance() //--------------------------------------------------------------------------- // LRESULT FAR PASCAL SIMPLEWndProc( HWND hWnd, UINT uMsg, // WPARAM wParam, LPARAM lParam ) // // Description: // This is the SIMPLE Window Proc. This handles ALL messages // to the simple window. // // Parameters: // As documented for Window procedures. // //--------------------------------------------------------------------------- LRESULT FAR PASCAL SIMPLEWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { LONG lrc; switch (uMsg) { case WM_CREATE: break; case WM_COMMAND: { switch ((DWORD) wParam) { case IDM_DIAL: if (!DialogBox (GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIAL), hWnd, (DLGPROC)DialDialogProc)) break; //make the call if (tapiRequestMakeCall(szDialString, gszAppName, NULL, NULL)) { MessageBox (hWnd, "Error Making Call", "Error making call", MB_OK); break; } break; case IDM_ABOUT: break; case IDM_EXIT: PostMessage( hWnd, WM_CLOSE, 0, 0L ) ; break ; } } break ; case WM_PAINT: break ; case WM_SIZE: break ; case WM_DESTROY: PostQuitMessage( 0 ) ; break ; case WM_CLOSE: PostQuitMessage( 0 ) ; break ; // fall through default: return( DefWindowProc( hWnd, uMsg, wParam, lParam ) ) ; } return 0L ; } // end of SIMPLEWndProc() /**************************************************************************** FUNCTION: DialDialogProc ****************************************************************************/ LRESULT CALLBACK DialDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { char szBuf[MAXDSZ]; static char szCurArea[10], szCurCountry[10]; BOOL bForeignCountry= FALSE; if ((message == WM_COMMAND) && (LOWORD(wParam) == IDOK)) { szDialString[0] = 0; //handle tone vs pulse if (IsDlgButtonChecked(hwnd, IDC_USETONEDIALING)) strcat(szDialString, "T"); if (IsDlgButtonChecked(hwnd, IDC_USEPULSEDIALING)) strcat(szDialString, "P"); //get dial prefix GetDlgItemText(hwnd, IDC_DIALPREFIX, szBuf, MAXDSZ-1); strcat(szDialString, szBuf); //handle wait for dial tone if (IsDlgButtonChecked(hwnd, IDC_WAITFORDIALTONE)) strcat(szDialString, "W"); //get country code GetDlgItemText(hwnd, IDC_COUNTRYCODE, szBuf, MAXDSZ-1); MakeLettersIntoDigits (szBuf); if (strcmp(szBuf, szCurCountry)) { strcat(szDialString, szBuf); bForeignCountry = TRUE; } //get area code GetDlgItemText(hwnd, IDC_AREACODE, szBuf, MAXDSZ-1); MakeLettersIntoDigits (szBuf); if (strcmp(szBuf, szCurArea) || bForeignCountry) strcat(szDialString, szBuf); //get phone number GetDlgItemText(hwnd, IDC_PHONENUMBER, szBuf, MAXDSZ-1); MakeLettersIntoDigits (szBuf); strcat(szDialString, szBuf); EndDialog (hwnd, TRUE); return TRUE; } if ((message == WM_COMMAND) && (LOWORD(wParam) == IDCANCEL)) { EndDialog (hwnd, FALSE); return TRUE; } if (message == WM_INITDIALOG) { //get current country and area tapiGetLocationInfo (szCurCountry, szCurArea); // initialize dialog fields SetDlgItemText(hwnd, IDC_COUNTRYCODE, szCurCountry); SetDlgItemText(hwnd, IDC_AREACODE, szCurArea); CheckDlgButton (hwnd, IDC_USETONEDIALING, BST_CHECKED); return TRUE; } return FALSE; }