(2) The drop-down menu on the toolbar When the user clicks on the drop-down arrow on the button, the corresponding menu will appear. In order to implement this function, add a message mapping in the message map of the CMAINFRAME.CPP file: ON_NOTIFY (TBN_DropDown, AFX_IDW_TOOLBAR Ontropdown; add message mapping function in the cmainframe.h file: AFX_MSG Void OnDropdown (NmHDR * PNOTIFYSTRUCT, LRESULT * PRESULT); finally add the following code:
void CMainFrame :: OnDropDown (NMHDR * pNotifyStruct, LRESULT * pResult) {NMTOOLBAR * pNMToolBar = (NMTOOLBAR *) pNotifyStruct; CRect rect; // get down arrow position; m_wndToolBar.GetToolBarCtrl () GetRect (pNMToolBar-> iItem, & rect. ); Rect.top = Rect.bottom ;:: ClientToscreen (pnmtoolbar-> hdr.hwndfrom, & review.topleft ()); if (pnmtoolbar-> iItem == id_font_dropdown) // Judging whether or not the drop-down arrow of selecting font; { CMenu menu; CMenu * pPopup; menu.LoadMenu (IDR_FONT_POPUP); pPopup = menu.GetSubMenu (0); pPopup-> TrackPopupMenu (TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top 1, AfxGetMainWnd ());} else if (pNMToolBar-> iItem == ID_FAVORITES_DROPDOWN) {// determines whether the drop-down arrow collection page; CMenu * pPopup; pPopup = GetMenu () -> GetSubMenu (3); pPopup-> TrackPopupMenu (TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left , Rect.top 1, AFXGETMAINWND ());} * PRESULT = TBDDRET_DEFAULT;
3) Animation implementation on the toolbar
In order to beautify the interface interface, a movie control is placed on the composite toolbar of the program to play an animation fragment in an appropriate timing to achieve the animation effect. The following code implements the creation of an animation control object, and opens AVI resource IDR_MFCAVI: M_Wndanimate.create (WS_CHILD | WS_VISIBLE, CRECT (0, 0, 0, 10, 10), this, AFX_IDW_TOOLBAR 2); M_Wndanimate.Open (iDR_MFCAVI);
The CanimateCtrl class provides play (), seek (), stop (), close () and other functions to play video file services, they are very simple, and they will not be described here.
4) Operation of the address bar
When the user enters the web address on the address bar and press the Enter key, the browser will display the content of the web page and will record the address in the address bar. Because the response key is pressed for the corresponding message ID, for this, you need to add a message map to the CMAINFRAME class to map ON_COMMAND (IDOK, ONNEWADDRESSENTER) and message response functions AFX_MSG Void OnnewadDressenter (). This function implements the code as follows: void cmainframe :: onnewaddressenter () {cstring str; // Get strings in the address bar; m_wnddress.GetItCtrl () -> getWindowText (STR); ((cmfcieview *) getActiveView ()) -> NaviGate2 (STR, 0, NULL); // Displays the web page; // Add this URL in the combo box corresponding to the address bar; item.mask = cbeif_text; item.iitem = -1; item.psztext = (LPTSTSTSTSTR) Str; M_Wndaddress.Insertitem (& item);}
Similarly, you have to add a message to the address bar (ID_IDW_TOOLBAR 1) in the CMAINFRAME class (AFX_IDW_TOOLBAR 1, ONNEWADDRESS) and message response functions onnewaddress, to handle the user from the address bar combination box to select the URL operation The implementation code of this function is as follows:
Void cmainframe :: onnewaddress () {cstring str; m_wndaddress.getlbtext (m_wndaddress.getcursel (), str); (CMYIEVIEW *) getActiveView ()) -> NaviGate2 (Str, 0, null);}