6. How to create a scalable dialog
In the design of the dialog, we sometimes need to design a scalable dialog that pops up or hide the lower part of the dialog box when the user presses a button.
(1) First, establish a picture control in the dialog box to set the ID to IDC_DIVIDER, TYPE set to rectangle, and the color is set to black, and set it to a line, drag and drop in the appropriate position as a scaling dialog box. The split line is invisible.
(2), the principle of implementation: First obtain the size of the dialog box, then determine the reduction dialog size according to the position, in fact, the change in the dialog expansion is the value, after the reduction dialog, we want to make it invisible Some controls are disabled to prohibit the operation of the accelerator and the Tab key, after the extended dialog, the originally prohibited control is also enabled.
Add a message processing function on the dialog box first:
Void c *** dlg :: onbuttonexpand ()
{
Static int bexpand = false; // set the initial time to expand
ExpandDialog (IDC_DIVIDER, BEXPAND); // Call the extension or reduction processing function
BEXPAND =! Bexpand; // Inverse, prepare for the next click
}
/ / Add a member function expandDialog in the dialog, used to extend or reduce
Void C *** DLG :: ExpandDialog (int NResourceID, Bool BEXPAND)
{
// Parameter nresourceID represents the ID of the split line
/ / The parameter bexpand indicates that the dialog is to be extended when the parameter bexpand is True. Otherwise, the dialog box
Static CRECT RCLARGE;
Static CRECT RCSMALL;
IF (RcLarge.Inectnull ()) // Maximum, Minimum size of the dialog box in the first time
{
CRECT RCLANDMARK;
CWND * pwndland = getdlgitem (nresourceId);
Assert (PWndland);
GetWindowRect (rcline);
PWNDLAND-> getWindowRect (rclandmark);
Rcsmall = rclarge;
Rcsmall.bottom = rclandmark.bottom;
}
IF (BEXPAND)
{
SetwindowPos (NULL, 0, 0, RCLARGE.WIDTH (), RCLARGE.HEIGHT (),
SWP_NOMOVE | SWP_NOZORDER);
Enablevisible ();
}
Else
{
SetwindowPos (NULL, 0, 0, RCSMALL.WIDTH (), RCSMall.Height (),
SWP_NOMOVE | SWP_NOZORDER);
Enablevisible ();
}
}
/ / Add a member function enablevisible in the dialog box to use and disable part controls
Void C *** DLG :: enablevisible ()
{
CWND * PWND = getDLGITEM (gw_child);
CRECT RETEST;
CRECT RCCONTROL;
CRECT RCSHOW;
GetWindowRect (rcshow);
While (PWND! = Null)
{
PWND-> GetWindowRect (RcControl);
IF (rctest.intersectRect (rcshow, rccontrol))
PWND-> EnableWindow;
Else
PWND-> EnableWindow (false);
PWND = PWND-> getWindow (gw_hwndnext);
}
7. Why is there a richedit control dialog that cannot be displayed?
If you put a RicheDit control on the dialog, the discovery dialog is not normal, because the application has not prepared for the RicheDit control editing function, the solution is the application's initInstance () function call Afxinitrichedit ( ) Function initialization Richedit control
8. How to specify the default button of the dialog
When establishing a dialog, under the default condition, the determination button (IDOK) is the default button, if you need to change the default button, there are two methods:
One: Directly remove the Default Button style option directly in the properties of the button (IDOK)
2: Implement with code when running, such as:
// Remove the default button of the determination button (IDOK)
CButton * pokbutton = (cbutton *) getdlgitem (IDOK);
Pokbutton-> ModifyStyle (BS_DEFPUSHBUTTON, 0);
// Add iDCancel's default button style
CButton * pcancelbutton = (cbutton *) getdlgitem (IDCANCEL);
PcancelButton-> setButtonStyle (BS_DEFPUSHBUTTON);