Note: I am using the VC ++ 2010 development environment for testing.
When using the VC development Dialog Box program, it is not as convenient as the development single document program and multi-document program. Many resources need to be manually added. Recently, when developing a program, I want to try to addToolbarAndButton tooltipSo I had this article and hoped to sum up my experience to facilitate future queries and inquiries from colleagues!
1. Create a dialog box Program
1. Add toolbar resources, add several buttons in toolbar resources, and change the width and height of the buttons to 24. You can also change the size as needed, you also need to set an ID for the corresponding button. Operations
2. Create a toolbar
1. Add toolbar objects and bitmap resources in *** DLG. h.
PRIVATE: ctoolbar m_toolbar; // bitmap resource cbitmap m_bitmap1; cbitmap m_bitmap2; cbitmap m_bitmap3; cimagelist m_imagelist;
2. Add the following code to the oninitdialog () function to create the toolbar.
If (! M_toolbar.createex (this, tbstyle_flat, ws_child | ws_visible | cbrs_align_top | cbrs_gripper | cbrs_tooltips) |! M_toolbar.loadtoolbar (idr_toolbar1) {trace0 ("failed to create Toolbar \ n"); afxmessagebox (_ T ("failed to create Toolbar \ n"); Return false; // failed to create} m_toolbar.showwindow (sw_show); // control bar positioning repositionbars (afx_idw_controlbar_first, afx_idw_controlbar_last, 0 );
3. Load a few 24*24 size bitmaps. Note that the size is set based on the size of the buttons above.
4. Add the code for loading bitmap in the Code following step 3 above.
If (! M_toolbar.createex (this, tbstyle_flat, ws_child | ws_visible | cbrs_align_top | cbrs_gripper | cbrs_tooltips) |! M_toolbar.loadtoolbar (idr_toolbar1) {trace0 ("failed to create Toolbar \ n"); afxmessagebox (_ T ("failed to create Toolbar \ n"); Return false; // failed to create} m_toolbar.showwindow (sw_show); // control bar positioning repositionbars (Region, region, 0); reverse (idb_bitmap_multimeter); reverse (idb_bitmap_phone); reverse (idb_bitmap_speaker ); m_imagelist.create (24, 24, ilc_color32 | ilc_mask,); m_imagelist.add (& m_bitmap1, RGB (0, 0, 0); m_imagelist.add (& m_bitmap2, RGB (0, 0, 0, 0); m_imagelist.add (& m_bitmap3, RGB (255,255,255); m_toolbar.gettoolbarctrl (). setimagelist (& m_imagelist );
Now, the program has been run. You can see that the toolbar button icon of the above sentence is added to the program interface,
The above function has been implemented to add icons for toolbar buttons. How can we add tooltip for toolbar buttons? For example:
Next, I will continue to introduce the operation steps:
1. Add the message processing function declaration in the *** DLG. h header file:
Afx_msg bool ontooltiptext (uint, nmhdr * pnmhdr, lresult * presult); // toolbar prompt
2. Add message ing in *** DLG. cpp
BEGIN_MESSAGE_MAP(CSageRemoteKeyTestDlg, CDialogEx) ......ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xffff, OnToolTipText)END_MESSAGE_MAP()
3. Add function definitions
Bool *** DLG: ontooltiptext (uint, nmhdr * pnmhdr, lresult * presult) {tooltiptext * pttt = (tooltiptext *) pnmhdr; uint uid = pnmhdr-> idfrom; // It is equivalent to wparam (low-order) in the original wm_command transmission mode. The ID of the control is put in wparam. If (pttt-> uflags & ttf_idishwnd) uid =: getdlgctrlid (hwnd) UID); If (uid = NULL) return false; Switch (UID) {Case idok: pttt-> lpsztext = _ T ("press this key to start testing"); break; Case idm_power_multimeter: pttt-> lpsztext = _ T ("electric meter configuration"); break; case idm_shieldingbox_com: pttt-> lpsztext = _ T ("serial port configuration"); break; Case idm_beep: pttt-> lpsztext = _ T ("buzzer configuration"); break ;} return true ;}
So far, compile and run the tooltip function that can be implemented by the program!
VC Dialog Box program add toolbar button icon and its button tooltip