Originally Posted by
shrink_tubing
1)What is a DLGPROC variable? I've seen some strange stuff used here. In the source I've got which compiles ok I have the following:
The DLGPROC is a pointer to a windows message tosser function that you have to provide for each dialog box you create.
According to the Windows API the correct definition for this is:
Code:
INT_PTR CALLBACK DialogProc(
HWND hwndDlg, // contains the handle of the dialog box
UINT uMsg, // contains message from a control
WPARAM wParam, // message data
LPARAM lParam // message data
);
Windows UI is all about messages. You click a button, it sends a message to it's owner window, open a drop list... another message... close it... more messages... change selection on a treeview... yet another message... everything you do either causes or handles messages.
The normal way of handling these messages is in switch{case...} chains that can be rather complex depending what you are doing.
When you create a dialogbox with any of the various calls available CreateDialog(), DialogBox(), etc. you have to give it the address of a message "tosser" procedure which accepts and handles the messages controls in the dialog box are going to create.
For example Here is a complete dialog to get "Yes or No" from the user...
When the user clicks the Yes button a WM_COMMAND message is sent to ConfTosser, with IDOK in it's WPARAM... the switch case sorts this out and will exit the dialog with a return value of 1 (TRUE). If he presses "No" the same sequence happens with IDCANCEL and a return value of 0 (FALSE)...
confirm.c
Code:
// message handler
INT_PTR CALLBACK ConfTosser(HWND Dlg, UINT Msg, WPARAM wParm, LPARAM lParm)
{ switch (Msg)
{ case WM_COMMAND :
switch (LOWORD (wParm))
{ case IDOK :
EndDialog(Dlg,1);
break;
case IDCANCEL :
EndDialog(Dlg,0);
break; } }
return 0; }
// confirmation dialog, return 1 = yes, 0 = no
BOOL ConfirmAction(HWND Parent)
{ return DialogBox(PgmInst,L"CONFIRM",Parent,&ConfTosser); }
confirm.rc ...
Code:
CONFIRM DIALOGEX DISCARDABLE 6, 18, 117, 41
STYLE DS_SHELLFONT|WS_POPUP|DS_MODALFRAME|DS_3DLOOK|WS_CAPTION|WS_VISIBLE
CAPTION "Please Confirm..."
FONT 8, "MS Shell Dlg", 0, 0, 1
{
CONTROL "Yes", IDOK, "Button", BS_DEFPUSHBUTTON|BS_FLAT|WS_TABSTOP, 27, 25, 40, 12
CONTROL "No", IDCANCEL, "Button", BS_FLAT|WS_TABSTOP, 71, 25, 40, 12
CONTROL "This action cannot be undone...\r\nAre you sure\?\r\n", 4003, "Static", 0x00000000, 5, 3, 106, 18
}