|
Creating a Modal Dialog Box
You create a modal dialog box by using the DialogBox function. You must specify the identifier or name of a dialog box template
resource and the address of the dialog box procedure. The DialogBox function loads the template, displays the dialog box, and processes all user
input until the user closes the dialog box.
In the following example, the application displays a modal dialog box when the
user chooses a Delete Item command from an application menu. The dialog box
contains an edit control (in which the user enters the name of an item) and OK
and Cancel buttons. The control identifiers for these controls are ID_ITEMNAME,
IDOK, and IDCANCEL, respectively.
The first part of the example consists of the statements that create the modal
dialog box. These statements, in the window procedure for the application's
main window, create the dialog box when the system receives a WM_COMMAND message having the IDM_DELETEITEM command identifier. The second part of the
example is the dialog box procedure, which retrieves the contents of the edit
control and closes the dialog box upon receiving a WM_COMMAND message.
The following statements create the modal dialog box. The dialog box template
is a resource in the application's executable file and has the resource
identifier DLG_DELETEITEM:
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDM_DELETEITEM:
if (DialogBox(hinst,
MAKEINTRESOURCE(DLG_DELETEITEM),
hwnd, (DLGPROC)DeleteItemProc)==IDOK)
.
. // Complete the command; szItemName
. // contains the name of the item to
. // delete.
.
else
.
. // Cancel the command.
.
break;
}
return 0L;
In this example, the application identifies its main window as the owner
window for the dialog box. When Windows initially displays the dialog box, its
position is relative to the upper left corner of the owner window's client area. The
application uses the return value from DialogBox to determine whether to proceed with the command or cancel it. The following
statements define the dialog box procedure.
char szItemName[80]; // receives name of item to delete.
BOOL CALLBACK DeleteItemProc(hwndDlg, message, wParam, lParam)
HWND hwndDlg;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
switch (message) {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
if (!GetDlgItemText(hwndDlg, ID_ITEMNAME,
szItemName, 80))
*szItemName=0;
// Fall through.
case IDCANCEL:
EndDialog(hwndDlg, wParam);
return TRUE;
}
}
return FALSE;
}
In this example, the procedure uses GetDlgItemText to retrieve the current text from the edit control identified by ID_ITEMNAME.
The procedure then calls the EndDialog function to set the dialog box's return value to either IDOK or IDCANCEL,
depending on the message received, and to begin the process of closing the dialog
box. The IDOK and IDCANCEL identifiers correspond to the OK and Cancel buttons.
After the procedure calls EndDialog, Windows sends additional messages to the procedure to destroy the dialog box
and returns the dialog box's return value back to the function that created
the dialog box.
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|