1. Add the following red code to the OnInitDialog () function in the dialog box:
BOOL CGSM_MessageDlg: OnInitDialog ()
{
CDialog: OnInitDialog ();
// Set the icon in this dialog box. When the application main window is not a dialog box, the framework will automatically
// Perform this operation
SetIcon (m_hIcon, TRUE); // you can specify a large icon.
SetIcon (m_hIcon, FALSE); // you can specify a small icon.
// TODO: add additional initialization code here
// Create an image list
M_ImageList.Create (32, 32, ILC_COLOR24 | ILC_MASK, 1, 1 );
// Add an icon to the image list
M_ImageList.Add (AfxGetApp ()-> LoadIcon (IDI_ICONBOOK ));
M_ImageList.Add (AfxGetApp ()-> LoadIcon (IDI_ICONNOTE ));
M_ImageList.Add (AfxGetApp ()-> LoadIcon (IDI_ICONSEND ));
M_ImageList.Add (AfxGetApp ()-> LoadIcon (IDI_ICONRECV ));
M_ImageList.Add (AfxGetApp ()-> LoadIcon (IDI_ICONSET ));
M_ImageList.Add (AfxGetApp ()-> LoadIcon (IDI_ICONUSER ));
UINT array [8];
For (int I = 0; I <8; I ++)
{
If (I = 2 | I = 5)
Array [I] = ID_SEPARATOR; // The separator is the nth button.
Else
Array [I] = I + 1001; // Set the index for the toolbar button
}
M_ToolBar.Create (this );
M_ToolBar.SetButtons (array, 8 );
// Associate the image list
M_ToolBar.GetToolBarCtrl (). SetImageList (& m_ImageList );
M_ToolBar.SetSizes (CSize (50, 60), CSize (32, 32); // you can specify the size of buttons and icons.
M_ToolBar.SetButtonText (0, L "phone book management ");
M_ToolBar.SetButtonText (1, L "common language Management ");
M_ToolBar.SetButtonText (3, L "short message sending ");
M_ToolBar.SetButtonText (4, L "short message receiving ");
M_ToolBar.SetButtonText (6, L "SMS cat settings ");
M_ToolBar.SetButtonText (7, L "operator Management ");
RepositionBars (AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0 );
Return TRUE; // return TRUE unless focus is set to the control.
}
2. From "array [I] = I + 1001; // you can see that the toolbar icon address starts with 1001. Therefore, the toolbar icons are 1001 1002 1003 1004, and so on.
3. Add a response function to the toolbar:
Add the red code to the. h header file in the dialog box:
// Implementation
Protected:
HICON m_hIcon;
// Message ing function generated
Virtual BOOL OnInitDialog ();
Afx_msg void OnPaint ();
Afx_msg HCURSOR OnQueryDragIcon ();
Afx_msg void OnPhoneBook ();
4. In the Dlg. cpp dialog box, add the following code:
BEGIN_MESSAGE_MAP (CGSM_MessageDlg, CDialog)
ON_WM_PAINT ()
ON_WM_QUERYDRAGICON ()
ON_COMMAND (1001, OnPhoneBook) // ID value of the first button at 1001. If you want to add a function for the second icon button, change it to ON_COMMAND (1002, OnPhoneBook)
//} AFX_MSG_MAP
END_MESSAGE_MAP ()
5. Add the response function in the Dlg. cpp dialog box:
Void CGSM_MessageDlg: OnPhoneBook ()
{
CPhoneBookDlg dlg;
Dlg. DoModal (); // used to link a dialog box
}
Void CFilterDlg: OnSize (UINT nType, int cx, int cy) {CDialog: OnSize (nType, cx, cy); if (m_list.m_hWnd) {CRect rect (0, 32, cx, cy); // GetWindowRect (& rect); // Obtain the window rect // ScreenToClient (& rect); // Convert the window size to the user area rect // rect. inflateRect (-10, 0,-10,-10); m_list.MoveWindow (& rect );}}
Add prompt information on the toolbar in the vs2008 dialog box
The prompt information on the toolbar on the dialog box cannot be added directly to the resource using the mfc application, because the dialog box cannot be managed by CFrameWnd.
1. Add the class header file in the dialog box. h.
BOOL OnToolTipNotify (UINT id, NMHDR * pNMHDR, LRESULT * pResult );
2. In the dialog box. cpp file, add
(1) add in message ING:
BEGIN_MESSAGE_MAP (CAssessMainDialog, CBCGPDialog)
// Control response, ranging from 0 to infinity
On_policy_ex (TTN_NEEDTEXT, 0, OnToolTipNotify)
// Control response, ranging from 0 to OxFFFF
// On_policy_ex_range (TIN_NEEDTEXT, 0, OxFFFF, OnToolTipNotify)
END_MESSAGE_MAP ()
(2) add a response function:
BOOL CAssessMainDialog: OnToolTipNotify (UINT id, NMHDR * pNMHDR, LRESULT * pResult)
{
BOOL bResult = TRUE;
TOOLTIPTEXT * pTTT = (TOOLTIPTEXT *) pNMHDR;
UINT_PTR uID = pNMHDR-> idFrom;
If (pTTT-> uFlags & TTF_IDISHWND)
{
// Int nID =: GetDlgCtrlID (HWND (uID,
// It may also be the cause of the compiler ......
CString strToolTips (_ TEXT (""));
Switch (uID)
{
Case ID_EXECUTE:
StrToolTips. Format (_ TEXT ("% s"), _ TEXT ("execution evaluation process "));
Break;
Case ID_SAVEFILE:
StrToolTips. Format (_ TEXT ("% s"), _ TEXT ("save evaluation process "));
Break;
Case ID_OPENFILE:
StrToolTips. Format (_ TEXT ("% s"), _ TEXT ("Open evaluation process "));
Break;
Default:
BResult = FALSE;
}
If (TRUE = bResult)
{
* PResult = 0;
_ Tcscpy (pTTT-> lpszText, strToolTips );
PTTT-> hinst = NULL;
}
}
Return bResult;
}
(3) enable tooltip
Added to the initialization function, not necessarily in the OnInitDialog function.
BOOL CAssessMainDialog: OnInitDialog ()
{
CBCGPDialog: OnInitDialog ();
CBCGPDialog: EnableVisualManagerStyle ();
M_ToolBar-> EnableToolTips (TRUE );
// The online example is to directly enable the prompt box tool. The test result can only display the prompt information on the entire toolbar, and then enable the prompt information on the toolbar. OK
// EnableToolTips (TRUE );
Return TRUE;
}
II. Status bar header file: CStatusBar m_StatBar; void CreateStatusBar (); source file: void CFilterDlg: CreateStatusBar () {// create status bar if (m_StatBar.Create (this )) {// ID static UINT indicators [] = {ID_SEPARATOR, indicator, ID_INDICATOR_NUM, indicator,}; // Set the status bar indicator ID and number of indicators m_StatBar.SetIndicators (indicators, sizeof (indicators)/sizeof (UINT); // Set the status bar indicator text m_StatBar.SetPaneText (0, L "indicator 1", 0); m_StatBar.SetPaneText (1, L "indicator 2 ", 0); m_StatBar.SetPaneText (2, L "indicator 3", 0); m_StatBar.SetPaneText (3, L "indicator 4", 0); // Set the status bar indicator attribute m_StatBar.SetPaneInfo (0, ID_SEPARATOR, SBPS_NORMAL, 100); values (1, average, SBPS_NORMAL, 100); m_StatBar.SetPaneInfo (2, average, SBPS_NORMAL, 100); m_StatBar.SetPaneInfo (3, minimum, ps_normal, 100 ); //// add an icon for the status bar indicator // HICON icon [2]; // icon [0] = AfxGetApp ()-> LoadIcon (IDI_ICON1 ); // icon [1] = AfxGetApp ()-> LoadIcon (IDI_ICON2); // m_StatBar.GetStatusBarCtrl (). setIcon (0, icon [0]); // m_StatBar.GetStatusBarCtrl (). setIcon (1, icon [1]); // m_StatBar.GetStatusBarCtrl (). setIcon (2, icon [0]); // m_StatBar.GetStatusBarCtrl (). setIcon (3, icon [1]); // set the height of the status bar m_StatBar.GetStatusBarCtrl (). setMinHeight (20); // display the status bar RepositionBars (AFX_IDW_CONTROLBAR_FIRST, priority, 0) ;}} void CFilterDlg: OnSize (UINT nType, int cx, int cy) {CDialog :: onSize (nType, cx, cy); if (m_list.m_hWnd) {// display the update status bar RepositionBars (AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); CRect rect (0, 40, cx, cy-20); // GetWindowRect (& rect); // Obtain the window rect // ScreenToClient (& rect); // Convert the window size to the user area rect // rect. inflateRect (-10, 0,-10,-10); m_list.MoveWindow (& rect); // list control position }}
VS2008 adds a response function to the icon toolbar-status bar