MFC fourth day

Source: Internet
Author: User

An MFC Menu
1 Questions about the menu
Win32--hmenu
MFC----CMenu Class Object------Map for menu handle
The CMenu class encapsulates the various API functions of the Action menu
Encapsulates a member Cmenu::m_hmenu save menu Handle
2. Menu Usage
1. Add a menu Resource
2. Set the menu to the window
1) in the WM_CREATE message of the Frame class window
CMenu menu;
Menu. LoadMenu
Cframewnd::setmenu--Set the menu to the window

2) in the CFrameWnd::Create parameter settings menu

3. Handling of menu item messages (WM_COMMAND)
Frame processing the app does not handle frame precedence over app processing, determined by cframewnd::oncmdmsg internal code execution sequencing
4. Setting Menu state
On_wm_initmenupopup
Checkmenuitem EnableMenuItem
3. Right-click menu
On_wm_contextmenu
Cmenu::getsubmenu get a drop-down menu for a top-level menu

Windows standard messages, frequently used, typically on_wm_xxx () macros
Two toolbars
1, toolbar related classes
CToolBarCtrl-The parent class is CWnd, encapsulating API functions for various operations on Toolbarctrl.
CFrameWnd is equivalent to a container that contains various windows inside. child window, docking relationship,
CToolbar-The parent class is CControlBar, encapsulates the relationship between toolbars and frame windows, and also includes the creation of toolbars

2. Use of toolbars
1. Add Toolbar resources
2. Create a toolbar Ctoolbar::create/createex
3. Load the toolbar resource Ctoolbar::loadtoolbar
4. Dock the toolbar.
Set where the toolbar will be docked
Ctoolbar::enabledocking
Where the frame window allows docking
CFrameWnd::EnableDocking
Where the toolbar can be docked
CframeWnd::D Ocktoolbar
5. Toolbars for meals and hide
Cframewnd::showcontrolbar
void Cframewnd::showcontrolbar (ccontrolbar* pBar, bool bShow, bool bdelay); Bdelay now has no effect.
Cwnd::iswindowvisible--Determine whether the window is a display state to judge any window


The style of the window toolbar

Cbrs_size_dynamic--You can change the shape of the toolbar
Cbrs_tooltips--Change hint style
Cbrs_gripper--CLAMP/handle
Tbstyle_flat--toolbar button smoothing style
Tbstyle_transparent--toolbar button protrusion style

Status bar
Related classes
CStatusBarCtrl-Parent class CWnd, encapsulates various API functions for STATUSBARCTRL operations
CStatusBar--The parent class CControlBar, encapsulates the relationship between the status bar and the main frame window, including the creation of the status bar.

Use:
To create a status bar:
Cstatusbar::create/createex
Set the status bar indicator
CStatusBar::SetIndicators
Set the width and style of the indicator
Cstatusbar::setpaneinfo
Set the contents of the indicator

Cstatusbar::setpanetext


void EnableDocking (DWORD dwstyle); Specifies whether the control bar supports docking and the sides of its parent window to which the control bar can be dock Ed, if supported. Can is one or more of the following flags:cbrs_align_top allows docking at the TOP of the client area. Cbrs_align_bottom allows docking at the BOTTOM of the client area. Cbrs_align_left allows docking on the left side of the client area. Cbrs_align_right allows docking on the right side of the client area. Cbrs_align_any allows docking on any side of the client area. Cbrs_float_multi allows multiple control bars to being floated in a single mini-frame window. If Zero, that's, indicating no flags, the control bar does not the dock. void DockControlBar (CControlBar * PBar, UINT ndockbarid = 0, Lpcrect lpRect = NULL); Parameterspbarpoints to the control bar to being docked.ndockbariddetermines which sides of the frame window to consider for Docking. It can be 0, or one or more of the Following:afx_idw_dockbar_top Dock to the TOP side of the frame window. Afx_idw_dockbar_bottom Dock to the BOTTOM side of the frame window. Afx_idw_dockbar_left Dock to the left side of the frame window. Afx_idw_dockbar_right Dock to the right side of the frame window. If 0, the control bar can be docked to any side-enabled for docking in the destination frame window.lprectdetermines, in S Creen coordinates, where the control bar is docked in the nonclient area of the destination frame window. Cframewnd::showcontrolbarvoid Showcontrolbar (ccontrolbar* pBar, bool bShow, bool bdelay); Parameterspbarpointer to the control bar to being shown or hidden.bshowif TRUE, specifies that the control bar was to be shown . If FALSE, specifies that the control bar was to be hidden.bdelayif TRUE, delay showing the control bar. If FALSE, show the control bar immediately.void setpaneinfo (int nIndex, uint NID, uint nstyle, int cxwidth); BOOL setpanetext (int nIndex, LPCTSTR lpsznewtext, BOOL bupdate = TRUE); On_wm_initmenupopup () afx_msg void Oninitmenupopup (CMenu *, UINT, BOOL); #define ON_WM_INITMENUPOPUP () {wm_initmenupopup, 0, 0, 0, AFXSIG_VMWB, (afx_pmsg) (AFX_PMSGW) (void (Afx_msg_call CWnd::* ) (cmenu*, UINT, BOOL)) &oninitmenupopup},***************************************************************_ Afxwin_inline BOOL Cmenu::loadmenu (UINT nidresource) {return Attach (:: LoadMenu (AfxFindResourceHandle ( Makeintresource (nIDResource), Rt_menu), Makeintresource (nIDResource)); }_afxwin_inline hinstance AFXAPI AfxGetResourceHandle () {ASSERT (Afxcurrentresourcehandle! = NULL); return Afxcurrentresourcehandle; }afx_module_state* AFXAPI afxgetmodulestate () {_afx_thread_state* pState = _afxthreadstate;  afx_module_state* presult;if (pstate->m_pmodulestate! = NULL) {//thread state ' s MODULE state serves as Overridepresult = Pstate->m_pmodulestate;} else{//Otherwise, use global app StateprEsult = _afxbasemodulestate.getdata ();} ASSERT (PResult! = NULL); return pResult;}        &&&&&bool Cmenu::attach (HMENU HMENU) {ASSERT (M_hmenu = = NULL); Only attach once, detach on destroyif (HMenu = = NULL) return FALSE; chandlemap* PMap = Afxmaphmenu (TRUE);   Create map if not Existassert (pMap! = NULL);p map->setpermanent (M_hmenu = HMenu, this); This=menureturn TRUE;} &&&&&chandlemap* PASCAL Afxmaphmenu (BOOL bcreate) {afx_module_thread_state* pState = Afxgetmodulethreadstate (); if (Pstate->m_pmaphmenu = = NULL && bcreate) {BOOL benable = AfxEnableMemoryTracking (FALSE); #ifndef _AFX_PORTABLE_PNH Pnholdhandler = Afxsetnewhandler (& Afxcriticalnewhandler); #endifpState->m_pmaphmenu = new Chandlemap (Runtime_class (Ctempmenu), Offsetof (CMenu, m_ HMenu)),//This sentence is not executed, still with the previous bound window when the Map#ifndef _afx_portableafxsetnewhandler (Pnholdhandler); Endifafxenablememorytracking (benable);} return pstate->m_pmaphmenu;} void Chandlemap::setpermanent (HANDLE h, Cobject* permob) {BOOL benable = afxenablememorytracking (FALSE); m_permanentmap[(LPVOID) h] = Permob; AfxEnableMemoryTracking (benable);} BOOL cframewnd::create (lpctstr lpszclassname,lpctstr lpszwindowname,dword dwstyle,const RECT& rect,CWnd* Pparentwnd,lpctstr Lpszmenuname,dword dwexstyle,ccreatecontext* pContext) {HMENU HMENU = null;if (lpszmenuname! = NULL) { Load in a menu that would get destroyed when window gets destroyedhinstance hInst = AfxFindResourceHandle (Lpszmenuname, Rt_menu); if ((HMenu =:: LoadMenu (HInst, lpszmenuname)) = = NULL) {TRACE0 ("warning:failed to load menu for cframewnd.\n");            PostNcDestroy (); Perhaps delete the C + + Objectreturn FALSE;}}    M_strtitle = lpszWindowName; Save title for Laterif (! CreateEx (dwExStyle, lpszClassName, lpszWindowName, Dwstyle,rect.left, Rect.top, Rect.right-rect.left, Rect.bottom- Rect.top,pparentwnd->getsafehwnd (), HMenu, (LPVOID) pContext) {TRACE0 ("warning:failed to create cframewnd.\n"); (HMenu! = NULL) DestroyMenu (HMenu); return FALSE;} return TRUE;} void CFrameWnd::P Ostncdestroy () {//default for frame windows are to allocate them on the heap//the default Post-cleanup i S to ' delete this './/Never explicitly call ' delete ' in a CFrameWnd, use DestroyWindow insteaddelete this; _afxwin_inline HWND Cwnd::getsafehwnd () const{return this = = NULL? Null:m_hwnd; }///********************cmywinapp::onnew () line 44_afxdispatchcmdmsg (CCmdTarget * 0x00531c88 class CMyWinApp theApp, unsigned int 40001, int 0, void (void) * 0x00401046 cmywinapp::onnew (void), void * 0x00000000, unsigned int, afx_cmdhand Lerinfo * 0x00000000) line 88ccmdtarget::oncmdmsg (unsigned int 40001, int 0, void * 0x00000000, Afx_cmdhandlerinfo * 0x000 00000) Line 302 + bytescframewnd::oncmdmsg (unsigned int 40001, int 0, void * 0x00000000, Afx_cmdhandlerinfo * 0x0000000 0) Line 903 + bytescwnd::oncommand (unsigned int. 40001, long 0) line 2099cframewnd::oncommand (unsigned int 40001, long 0 ) Line 321cwnd::onwndmsg (unsigned int. 273, unsigned inT 40001, long 0, long * 0X0018FCBC) line 1608 + bytescwnd::windowproc (unsigned int 273, unsigned int 40001, long 0) Lin E 1596 + bytesafxcallwndproc (CWnd * 0x02673da8 {cmyframewnd hwnd=???}, hwnd__ * 0x00010c6a, unsigned int 273, unsigned int 40001, long 0) line 215 + bytesafxwndproc (hwnd__ * 0x00010c6a, unsigned int 273, unsigned int. 40001, long 0) Line 3 79user32! 75E162FA () user32! 75E16D3A () user32! 75E177C4 () user32! 75E17BCA () CWinThread::P umpmessage () line 853cwinthread::run () line 487 + one bytescwinapp::run () line 400AfxWinMain ( hinstance__ * 0x00400000, hinstance__ * 0x00000000, char * 0x0069588e, int 1) line + one byteswinmain (hinstance__ * 0x00 400000, hinstance__ * 0x00000000, char * 0x0069588e, int 1) line 30WinMainCRTStartup () line 198 + byteskernel32! 761233CA () ntdll! 77319ed2 () ntdll! 77319EA5 () *****************************///
Source


MFC fourth day

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.