Defining an Abort Dialog Function

In your application source code, provide a dialog function for the Abort dialog box. The function should process the WM_INITDIALOG and WM_COMMAND messages. To let the user choose the Cancel button with the keyboard, the function takes control of the input focus when the dialog box is initialized. It then ignores all messages until a WM_COMMAND message appears. Command input causes the function to destroy the window and set the abort flag to TRUE. The following example shows the required statements for the dialog function:

BOOL bAbort=FALSE; /* global variable */

.

.

.

int FAR PASCAL AbortDlg(hWnd, msg, wParam, lParam)

HWND hWnd;

unsigned msg;

WORD wParam;

LONG lParam;

{

/* Watch for Cancel button, RETURN key,

ESCAPE key, or SPACE BAR */

if(msg == WM_COMMAND) {

/* User has aborted operation */

bAbort = TRUE;

/* Destroy Abort dialog box */

DestroyWindow(hWnd);

return(TRUE);

}

else if(msg == WM_INITDIALOG) {

/* Need input focus for user input */

SetFocus(hWnd);

return(TRUE);

}

return(FALSE);

}