Making dynamically popped dialog boxes with VC
In "Network Ants", if there is an error in the download process, or when the download is complete, you can see a small, dynamic pop-up dialog box, then this dynamically popped conversation How is the box implementation?
First, choose how
Typically, we can add some initial settings of the dialog in the response function of the WM_INITDIALOG event of the dialog, such as changing the location and size of the window. Similarly, we can also make the dialog box from a small to earth in the response function of the WM_INITDIALOG event. However, how do I change the size of the dialog? In programming, we usually use the MoveWindow function to dynamically adjust the size of the dialog, but the MoveWindow function has its limitations: one is that it is slower; the second is due to the reason for the known MFC memory leak, if repeated call MoveWindow Function to change the size of the dialog, MoveWindow cannot "clean" the screen (this can be programs in actual programming), which is obviously not what we need. Can you find another way to change the size of the window? We know that the SETWINDOWRGN function can change the display area of the window, then allow the program to hide the dialog box before the dialog box is displayed, and then let the display area of the dialog continue to become large, so that the dynamic display of the dialog is implemented. .
Before continuing to introduce, let's introduce the specific usage of setWindowRGN, the following is its call format:
INT setwindowrgn (HRGN HRGN, BOOL BREDRAW);
HRGN: Points the handle of a region, usually this parameter is created by the CRGN object.
BREDRAW: Indicates whether the system is redaking the window after setting the window display area.
Second, the application example
Next we take the "Help dialog" of the program to dynamically pop up as an example, describe how to implement the dynamic pop-up display of the dialog box by programming. Add mapping for WM_INITDIALOG in the CaboutDLG class, and edit its response function OnInitDialog, the specific content setting of this function is as follows:
Bool caboutdlg :: oninitdialog ()
{
CDIALOG :: OnInitdialog ();
File: // Hide dialog
ShowWindow (SW_HIDE);
CRECT DLGRECT;
GetClientRect (&& DlgRect);
Cpoint centerpoint;
Centerpoint.x = DLGRECT.WIDTH () / 2;
Centerpoint.y = DLGRECT.HEIGHT () / 2;
File: // Get the midpoint coordinates of the dialog
CRGN TESTRGN;
This-> showwindow (sw_hide);
INT m = getSystemMetrics (SM_CYSIZEFRAME);
File: // The following code implements the dynamic pop-up of the dialog
For (int I = 10; i { Testrign.createRectrgn (Centerpoint.x-i, centerpoint.x i, centerpoint.y i); SetwindowRgn ((HRGN) TESTRGN, TRUE; ShowWindow; CenterWindow (); Testrign.deleteObject (); } Return True; } The code is relatively simple, and then enter the program's help menu, you will see a small-changing dialog over the screen. Third, in-depth discussion It should be noted that the main purpose of this article is to introduce the programming idea, so in the programming, it is first assumed that the help dialog is square or basically square, if your help dialog has a larger shape, The interface effect of the program is not ideal. At this time, you can consider the display area of other shapes in the programming of the dialog box. ///