?? extapiasync.cpp
字號:
}
// set the currently selected item
SendMessage(g_hwndOpList, LB_SETCURSEL, 0, 0);
break;
case WM_COMMAND:
switch (wParam) {
case IDM_EXTAPIA_QUIT:
CleanupLB();
EndDialog(hDlg, 0);
break;
case IDM_EXTAPIA_REG:
{
RegisterNewOperator();
break;
}
default:
bProcessedMsg = FALSE;
break;
}
break;
default:
bProcessedMsg = FALSE;
break;
}
return bProcessedMsg;
}
// ***************************************************************************
// Function Name: InitDialog
//
// Purpose: Sizes a dialog box to be full screen and adds the menus
//
// Arguments:
// hDlg = the HWND of the dialog box
// nToolBarId = the ID of the menu bar to add
//
// Return Values:
// TRUE if successful, FALSE otherwise
//
// Description:
// This function simply takes an HWND for a dialog, makes it full screen, adds
// a menu bar, and sets the title bar to be the title of the application.
BOOL InitDialog(const HWND hDlg, UINT nToolBarId)
{
// Specify that the dialog box should stretch full screen
SHINITDLGINFO shidi;
ZeroMemory(&shidi, sizeof(shidi));
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
// set up Soft Keys menu
SHMENUBARINFO mbi;
ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hDlg;
mbi.nToolBarId = nToolBarId;
mbi.hInstRes = g_hInstance;
// If we could not initialize the dialog box, return an error
if (!(SHInitDialog(&shidi) && SHCreateMenuBar(&mbi))) {
return FALSE;
}
// set the title bar
VERIFY(SetWindowText(hDlg, g_szTitle));
// In order to make Back work properly, it's necessary to
// override it and then call the appropriate SH API
(void)SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
return TRUE;
}
// ***************************************************************************
// Function Name: TAPIProc
//
// Purpose: Callback function for asynchronous TAPI calls
//
// Arguments: Standard TAPI callback arguments
//
// Return Values: None
//
// Description:
// Normally, this function would respond to any messages created by calls to
// asynchronous TAPI functions. One would definitely want to keep track of the
// request numbers so they could be matched to their replies. However, since this
// program only has one asynchronous call, we just assume that anything that passes
// through here was a reply to that call.
void CALLBACK TAPIProc(DWORD hDevice, DWORD dwMessage, DWORD dwInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
// since we only made one asynch request, we just want to see if it was
// successful or not. A dwParam2 of 0 indicates success.
if (dwMessage == LINE_REPLY) {
if (!dwParam2) {
MessageBox(g_hDlg, TEXT("LINE_REPLY: Success!"),
g_szTitle, MB_OK | MB_ICONINFORMATION);
} else {
MessageBox(g_hDlg, TEXT("LINE_REPLY: Failure"),
g_szTitle, MB_OK | MB_ICONERROR);
}
// Update the Current Operator text box
GetCurrentOperator(g_hDlg);
}
}
// ***************************************************************************
// Function Name: GetCurrentOperator
//
// Purpose: Get the current operator and update the dialog display
//
// Arguments:
// hDlg - the dialog containing the IDC_EXTAPIA_CUROP control
//
// Return Values:
// TRUE if successful, FALSE otherwise
//
// Side Effects:
// Updates the text for control IDC_EXTAPIA_CUROP
//
// Description:
// This function simply calls the lineGetCurrentOperator function and updates
// the display with the results.
BOOL GetCurrentOperator(HWND hDlg)
{
LINEOPERATOR CurrentOperator;
if (lineGetCurrentOperator(g_hLine, &CurrentOperator)) {
return FALSE;
}
SetDlgItemText(hDlg, IDC_EXTAPIA_CUROP, CurrentOperator.lpszLongName);
return TRUE;
}
// ***************************************************************************
// Function Name: GetAvailableOperators
//
// Purpose: Get the available operators and update the dialog display
//
// Arguments:
// hDlg - the dialog containing the IDC_EXTAPIA_CUROP control
//
// Return Values:
// TRUE if successful, FALSE otherwise
//
// Side Effects:
// Updates the text in the listbox with HWND g_hwndOpList
// Allocates memory to copy the operator strings
//
// Description:
// This function simply calls the lineGetOperatorStatus function and updates
// the display with the results. If there are more operators than can fit in pbInit
// it also temporarily allocates memory.
BOOL GetAvailableOperators(HWND hDlg)
{
// set up the initial mega data structure
BYTE pbInit[REASONABLE_BUFFER];
LPLINEOPERATORSTATUS plosOperatorStatus = (LPLINEOPERATORSTATUS)pbInit;
LPBYTE pLineOperatorStatusBytes = NULL;
LPTSTR lpszItemData;
DWORD dwNeededSize;
int iResult;
plosOperatorStatus->dwTotalSize = REASONABLE_BUFFER;
if (lineGetOperatorStatus(g_hLine, plosOperatorStatus)) {
return FALSE;
}
// check to see if our buffer was large enough
if (plosOperatorStatus->dwNeededSize >= plosOperatorStatus->dwTotalSize) {
// allocate a byte array and cast it to a LPLINEOPERATORSTATUS
dwNeededSize = plosOperatorStatus->dwNeededSize;
pLineOperatorStatusBytes = new BYTE[dwNeededSize];
if (!pLineOperatorStatusBytes) {
return FALSE;
}
plosOperatorStatus = (LPLINEOPERATORSTATUS)pLineOperatorStatusBytes;
// call lGOS again to fill the new structure
plosOperatorStatus->dwTotalSize = dwNeededSize;
if (lineGetOperatorStatus(g_hLine, plosOperatorStatus)) {
delete[] pLineOperatorStatusBytes;
return FALSE;
}
}
// set the pointer to the first available operator and iterate
LPLINEOPERATOR ploOperator;
DWORD dwOperatorNumber;
ploOperator = (LPLINEOPERATOR)((LPBYTE)plosOperatorStatus+(plosOperatorStatus->dwAvailableOffset));
for(dwOperatorNumber = 0;
dwOperatorNumber < plosOperatorStatus->dwAvailableCount;
dwOperatorNumber++) {
// add the element to the listbox
iResult = SendMessage(g_hwndOpList, LB_ADDSTRING, 0, (LPARAM) ploOperator->lpszLongName);
// copy the lpszNumName and store the pointer as ItemData
if (iResult >= LB_OKAY) {
lpszItemData = _tcsdup(ploOperator->lpszNumName);
if (!lpszItemData) {
delete[] pLineOperatorStatusBytes;
return FALSE;
}
SendMessage(g_hwndOpList, LB_SETITEMDATA, iResult, (LPARAM) lpszItemData);
} else {
delete[] pLineOperatorStatusBytes;
return FALSE;
}
// increment the pointer
ploOperator++;
}
// cleanup
delete[] pLineOperatorStatusBytes;
return TRUE;
}
// ***************************************************************************
// Function Name: RegisterNewOperator
//
// Purpose: call lineRegister on the currently selected operator
//
// Arguments: none
//
// Return Values: none
//
// Description:
// This function simply takes the currently selected member of g_hwndOpList and
// tries to register it as a new operator. lineRegister is asynchronous, so the
// result of this call is posted to TAPIProc.
void RegisterNewOperator()
{
LPTSTR lpszNumName;
int iCurSel, iResult;
iCurSel = SendMessage(g_hwndOpList, LB_GETCURSEL, 0, 0);
if (iCurSel != LB_ERR) {
// get the provider name
lpszNumName = (LPTSTR) SendMessage(g_hwndOpList, LB_GETITEMDATA,
(WPARAM) iCurSel, (LPARAM) 0);
// now try to set the current provider
// normally we would store this ID and verify it in TAPIProc, but since we are
// only making one asynchronous request, we ignore this value...
iResult = lineRegister(g_hLine, LINEREGMODE_MANUAL,
lpszNumName, LINEOPFORMAT_NUMERIC);
} else {
MessageBox(NULL, TEXT("Unable to get current selection"),
TEXT("Error!!!"), MB_OK | MB_ICONERROR);
}
}
// ***************************************************************************
// Function Name: CleanupLB
//
// Purpose: free the strings pointed to by a listbox's itemdata
//
// Arguments: none
//
// Return Values: none
//
// Description:
// This function simply iterates through the members of a listbox, gets their
// item data values, which should be pointers to strings, and frees them.
void CleanupLB()
{
int iResult;
LPTSTR lpszNumName;
// get the number of items in the listbox
iResult = SendMessage(g_hwndOpList, LB_GETCOUNT, 0, 0);
if (iResult != LB_ERR) {
for (int i = 0; i < iResult; i++) {
lpszNumName = (LPTSTR) SendMessage(g_hwndOpList, LB_GETITEMDATA, (WPARAM) i, (LPARAM) 0);
free(lpszNumName);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -