Windows window operation functions

Source: Internet
Author: User

We can see the derived relationship of the window from the Derived Graph of the MFC class provided by VC,Derived GraphAll window classes are derived from cwnd. All member functions of cwnd can be used in Their Derived classes. This section describes some common functions.

Change the window status:
Bool enablewindow (bool benable = true); you can set the prohibited/allowed status of the window. Bool iswindowenabled (); you can query the prohibited/Permitted status of the window.
Bool modifystyle (DWORD dwremove, DWORD dwadd, uint nflags = 0)/bool modifystyleex (DWORD dwremove, DWORD dwadd, uint nflags = 0); you can modify the window style, you do not need to call setwindowlong.
Bool iswindowvisible () can check whether the window is displayed.
Bool showwindow (INT ncmdshow); the display status of the window will be changed. The ncmdshow value can be as follows:

  • Sw_hideHide window
  • Sw_minimize sw_showmaximizedMinimize window
  • Sw_restoreRestore window
  • Sw_showDisplay window
  • Sw_showminimizedMaximize window

Change the window position:
Void movewindow (lpcrect lprect, bool brepaint = true); you can move the window.
Void getwindowrect (lprect); you can obtain the rectangle position of the window.
Bool isiconic (); checks whether the window has been scaled down to an icon.
Bool setwindowpos (const cwnd * pwndinsertafter, int X, int y, int CX, int cy, uint nflags); you can change the Z sequence of the window and move the position of the window.

To make the window invalid, print and re-paint:
Void invalidate (bool berase = true); to invalidate the entire window, berase determines whether the window is repainted.
Void invalidaterect (lpcrect lprect, bool berase = true)/void invalidatergn (crgn * prgn, bool berase = true); invalidates the specified rectangle/polygon area.

Window search:
Static cwnd * Pascal findwindow (lpctstr lpszclassname, lpctstr lpszwindowname); you can search for a window by its class name and window name. If any of the parameters is set to null, the data represented by this parameter is randomly matched. For example, findwindow ("mywnd", null) indicates to query all windows whose class name is mywnd.
Bool ischild (const cwnd * pwnd) checks whether the window is a subwindow.
Cwnd * getparent () to get the parent window pointer.
Cwnd * getdlgitem (int nid) obtains the window pointer through the subwindow ID.
Int getdlgctrlid () to get the window id value.
Static cwnd * Pascal windowfrompoint (point); The Window pointer containing the point is obtained from the coordinates of a certain point on the screen.
Static cwnd * Pascal fromhandle (hwnd); construct a cwnd * pointer through hwnd, but this pointer will be deleted when idle, so it cannot be saved for future use.

Clock:
Uint settimer (uint nidevent, uint nelapse, void (callback Export * lpfntimer) (hwnd, uint, uint, DWORD); you can create a clock. If the lpfntimer callback function is null, the window will receive the wm_timer message, and you can arrange the processing code in afx_msg void ontimer (uint nidevent );
Bool killtimer (INT nidevent); deletes a specified clock.

You can use overload to add a virtual function for message processing:
Afx_msg int oncreate (maid); called when the window is created
Afx_msg void ondestroy (); called when the window is destroyed
Afx_msg void ongetminmaxinfo (minmaxinfo far * lpmmi); Called to obtain the window size
Afx_msg void onsize (uint ntype, int CX, int CY); called after the window size is changed
Afx_msg void onmove (int x, int y); called when the window is moved
Afx_msg void onpaint (); the window needs to be called from time to time. You can fill in the drawing Code. For the View class, you do not need to reload onpaint. All the drawing code should be in ondraw.
Afx_msg void onchar (uint nchar, uint nrepcnt, uint nflags); called when receiving Character Input
Afx_msg void onkeydown/onkeyup (uint nchar, uint nrepcnt, uint nflags); called when the key on the keyboard is pressed/released
Afx_msg void onlbuttondown/onrbuttondown (uint nflags, cpoint point); called when the left/right-click button is pressed
Afx_msg void onlbuttonup/onrbuttonup (uint nflags, cpoint point); called when the mouse is left/right-clicked
Afx_msg void onlbuttondblclk/onrbuttondblclk (uint nflags, cpoint point)
Afx_msg void onmousemove (uint nflags, cpoint point); called when the mouse moves over the window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.