Dialog
He Zhidan
main content:
1. Establish a model dialog and a modeless dialog
2, the control of the alignment and focus settings
3, instance
4, general dialog
5, common functions
The dialog can be divided into "modular" and "no mode" by its action mode. For the Mode dialog box, the user cannot do other work before the dialog is turned off. There is no mode dialog, and it still remains on the screen while the user can work in other windows of the application.
Build a dialog-based program Dialog.
Insert a dialog box in the Explorer, Ctrl W Create a Class CownerDiaog; plus a button in IDD_DIALOG_DIALOG, double-click on its editing code.
Void cdialogdlg :: onbutton1 ()
{
CownerDialog DLG;
Dlg.domodal ();
}
Don't forget #include "OwnerDialog.h". You don't close it, you can't get the command to the main dialog, but you can still open other programs. We delete the code just added.
Void cdialogdlg :: onbutton1 ()
{
CownerDialog * pdlg = new cownerdialog ();
PDLG-> CREATE (IDD_DIALOG1);
PDLG-> ShowWindow (sw_restore);
}
This is a non-Mode dialog that you can issue a command to the main dialog before processing sub-dialog box. Note If you turn off the master dialog, the sub-dialog is also closed.
There are four functions in layout to be very useful, Tab ORDER (Shortcut Ctrl D): Click the button in turn to determine their focus order.
In this way, when the user is switched on the focus, the sequence of the control is to be set. For example, a dialog box wants us to enter the username, the mouth is printed, then press OK. We set their focus order to 1, 2, 3, so that users entered the username, then press Tab, enter the mouth, enter the car.
Layout Align will be aligned in some way
Layout Space Evenly averages the interval of the selected control
Layout Make Same Size makes the selected control size
Let's compile a simple program, the program randomly generates a X, the user enters Y = x * x, the value, the program checks the right, if it is wrong, it also corrected.
Generate a dialog-based application, remove "TODO: Settings Control here", this static control is not used. Join the two editing controls (if the control is mostly changed to an easy understanding ID), Ctrl W will two controls
Associated with two shaping variables m_x, m_y (naming to be easily understood). Add a button, ID is changed to IDC_CHECK, double-click its editing code.
Void ccheckdlg :: oncheck ()
{
Updatedata ();
IF (m_y == m_x * m_x)
MessageBox ("you right);
Else
{
m_y = m_x * m_x;
Updatedata (FALSE);
MessageBox ("Think of the results");
}
}
Find constructor (preferably ininitdialog () processing), find m_x = 0; change
CTIME T = CTIME :: getcurrenttime ();
INT n = T. maxSecond ();
For (int i = 0; i In fact, RAND is not random, the first call return value is always the same, we can take the number of seconds of the current time to determine the number of calls. Set the caption of each control and set the focus as described above and adjust the size of each control. The value of the control display is not synchronized with the value of the value (member variable) associated with the control, and we must call Updatedata (); when we enter the data, call Updatedata (TRUE) to update member variables; Updatedata (false) Display the value of the member variable on the screen. CDialog's updatedata () updates all controls, if you just want to update a control, you can call the control class's updata (). General dialogs, often use ccolordialog, cfontdialog, cfiledialog, similar to CcolorDialog DLG; IF (idok == dlg.domodal ()) { ... dlg.getcolor (); } Note CFiledialog DLG (FALSE), indicating that it is saved as dialog, indicating that the TRUE is open, and the first parameter does not have the default. Common functions: CDIALOG :: CloseWindow (); Minimize dialog. CDIALOG :: DestroyWindow (); Close dialog, ONOK, ONCANCEL can also close dialog. CDIALOG :: getClientRect (); gets the customer area; CDIALOG :: getfocus (); get focus; CDIALOG :: getFont () get font; CDialog :: setWindowText); Set the dialog header; CDIALOG :: setMenu (); setup menu; CDIALOG :: setfocus (); set the focus; CDIALOG :: setFont (); set font; Some things we can't do in the constructor, such as setTimer, we can do in OnInitDialog () or in the WM_SHOWINDOW response function. ShowWindow (sw_hide); its parameters can also be: SW_HIDE SW_MINIMIZE SW_RESTORE SW_SHOWMAXIMIZED SW_SHOWMIMIMIZED SW_SHOWMINNOACTIVE SW_SHOWNA SW_SHOWNOACTIVATE SW_SHOWNORMAL