Visual c ++ programming skills 2
9. How do I change the window icon?
10. How can I change the default window style?
11. How to center the window display?
12. How can I maximize and minimize windows and MDI windows as soon as they are started?
13. How to keep the program in a very small state?
14. How do I limit the window size?
15. How to Make the window invisible?
16. How to keep the window at the forefront?
9. How do I change the window icon?
Send the wm_section message to the window.
Example:
Hicon = afxgetapp ()-> loadicon (idi_icon );
Assert (hicon );
Afxgetmainwnd ()-> sendmessage (wm_section, true, (lparam) hicon );
10. How can I change the default window style?
Resend cwnd: precreatewindow and modify the createstruct structure to specify the window style and other
Create information.
Example: Delete "Max" button and set original window's position and size
Bool cmainframe: precreatewindow (createstruct & CS)
{
CS. Style & = ~ Ws_maxinizemox;
CS. x = cs. Y = 0;
CS. Cx = getsystemmetrics (sm_cxscreen/2 );
CS. Cy = getsystemmetrics (sm_cyscreen/2 );
Return cmdiframewnd: precreatewindow (CS );
}
11. How to center the window display?
Easy, call function cwnd: center windows
Example (1): center window (); // relative to it's parent
// Relative to screen
Example (2): center window (cwnd: getdesktopwindow ());
// Relative to application's mainwindow
Afxgetmainwnd ()-> center window ();
12. How can I maximize and minimize windows and MDI windows as soon as they are started?
Let's talk about the window first.
Set the m_ncmdshow value in the initstance function.
M_ncmdshow = sw_showmaxmized; // maximize
M_ncmdshow = sw_showminmized; // minimized
M_ncmdshow = sw_shownormal; // Normal Mode
MDI window:
If you are creating a new application, you can use the advanced button of the MFC Appwizard and
Maximize or minimize the detection in the MDI child window style group. You can also reload
Precreatewindow function, set ws_maxmize or ws_minmize;
If it is derived from cmdichildwnd, call cwnd: Show in oninitialupdate Function
Window to specify the style of the MDI child window.
13. How to keep the program in a very small state?
Interesting question
In this case, Windows will send a WM_QUERY-OPEN message when the form of the Recovery Program is large,
Use classwizard to set the member function onqueryopen (), add following code:
Bool cmainframe: onqueryopen ()
{
Return false;
}
14. How do I limit the window size?
That is, the fixeddialog format. Windows sends wm_getmaxmininfo messages for tracking,
Respond to it and write the code in ongetmaxmininfo:
15. How to Make the window invisible?
It is easy to hide the window with sw_hide. You can use findwindow and showwindow to control the window.
16. How to keep the window at the forefront?
There are two ways.
Bringwindowtotop (handle );
Setwindowpos function, which specifies the top style of the window. Use ws_ex_topmost to extend the window style.
Example:
Void toggletopmost (cwnd * pwnd)
{
Assert_valid (pwnd );
Pwnd-> setwindowpos (pwnd-> getstyle () & ws_ex_topmost )?
& Wndnotopmost: & wndtopmost, 0, 0, 0, ssp_nosize | wsp_nomove );
}