Use Visual C ++ to create IE browser (1)

xiaoxiao2021-03-06  48

Foreword

The IE browser uses a browsing tool sold by Microsoft Windows system, used to browse the pose-state webpage, and it has already occupied the half-waters of the browser market, becoming an indispensable tool for Windows users. First, its interface is very beautiful, such as the flat button (the image on the button is gray, when the mouse is placed on the button, the button protrudes, this state is called the handle, and the image on which it is bright) , The text description on the button and the small black triangle shape on the edge of the button (displays the drop-down menu when you click), and the address input bar on the toolbar reflects the style of Windows2000; second, its collection can Collect users' favorite network address, all of this has made a solid foundation for IE. Said so much, perhaps readers and friends feel very difficult, in fact, IE is also a "paper tiger", and the difficult point of achieving it is mainly on the interface effect and display favorites, the author has targeted narrative in this article. The implementation of the IE interface, the collection web page display, the browsing of the web page, after reading this article, believe that readers can create a browser that belongs to their own browser. The code in this article compiles in Windows2000, Visual C 6.0, and the program is operating normally. The program running interface is as follows:

Figure 1. Browser running interface

First, the browser interface is implemented

First start Visual C 6.0, generate a MYIE single document project, not to select the toolbar and status options during this process, so that we can more convenient for us to use the code to implement the Windwos2000 style toolbar, state Bar; add an address bar in the toolbar; the base class of the project's view class is ChtmlView, which is specifically used to realize the documentation in the hyperbrae format. Defined in the main frame class CmainFrame CStatusBar m_wndStatusBar (status bar object), CToolBar m_wndToolBar (toolbar objects), CReBar m_wndReBar (, CComboBoxEx m_wndAddress (extended combo box object used as the address field), CAnimateCtrl m_wndAnimate (animation control, with To display an animation on the toolbar), the image list object CIMAGELIST IMG (icon displayed on the toolbar) and other objects. To the current project AVI resource file, ID flag idR_mfcavi, add Bitmap (bitmap) resources, ID flag is IDB_COLDTOOLBAR, IDB_HOTTOOLBAR, as shown below:

Figure 2, bitmap containing button icons

1) IE style toolbar

The implementation of the IE-style interface is mainly implemented in the CMAINFRAME :: oncreate () function of the main framework class, its main idea is as follows: Crebar objects are used as a toolbar, address bar, animation control container, CIMAGELIST object, and then load tools The image is displayed on the hotspot image of the button and the image shown in the normal state, and the object is attached to the toolbar object, which is associated. To display the flat toolbar, you need to create a CREATEEX () function to create a CToolbar object m_wndtoolbar, with the modifyStyle () function Set the toolbar's style to a flat type, note that you cannot use CToolBar :: Create () or CToolbar :: setbarstyle () settings This new style. The CToolbar class does not support TBStyle_flat, to solve this problem, you must bypass the CToolbar class, use CWnd :: ModifyStyle (). To set a toolbar button to attach a drop-down button, you can call the setButTonInfo () Setting button to TBStyle_Dropdown. As for the button with a Chinese prompt, it can be easily implemented with setButtonTontext () in the toolbar. Below is a code and annotation that implements the IE style interface:

INT CMAINFRAME :: OnCreate (lpcreatestruct lpcreatestruct) {cimagelist img; // image list object; CString str; // string object; if (cframeWnd :: oncreate (lpcreateStruct) == -1) Return -1; if (! m_wndrebar .Create (this)) // Create a crebar object; {trace0 ("failed to create rebar / n"); return -1;} if (! M_wndtoolbar.createex (this)) // Create a toolbar using createex () function Object; {trace0 ("failed to create toolbar / n"); return -1;} // set the maximum minimum size in the toolbar; m_wndtoolbar.gettoolbarctrl (). SetButtonWidth (50, 150); // Setting toolbar The button supports the drop-down arrow style; m_wndtoolbar.gettoolbarctrl (). SetExtendedStyle (TBSTYLE_EX_DRAWDDARROWS); / / List of hotspot image resources to the image list, IDB_HOTTOOLBAR is a hot image resource ID img.create (IDB_HOTTOOLBAR, 22, 0, RGB (255, 0 , 255); m_wndtoolbar.gettoolbarctrl (). Sethotimagelist (& img); img.detach (); // Image list loaded image resources, IDB_COLDTOOLBAR is image resource idimg.create (IDB_COLDTOOLBAR, 22, 0, RGB ( 255, 0, 255); m_wndtoolbar.gettoolbarctrl (). Setimagelist (& img); img.detach (); // Setting toolbar is flat-style m_wndtoolbar.ModifyStyle (0, tbstyle_flat | tbstyle_transparent); // Setting tool bars The number of buttons is 9; m_wndtoolbar.setButtons (NULL, 9); // Loading string resources, the identification number of the text and button on the set button; m_wndtoolbar .SetButtonInfo (0, ID_GO_BACK, TBSTYLE_BUTTON, 0); str.LoadString (IDS_BACK); m_wndToolBar.SetButtonText (0, str); m_wndToolBar.SetButtonInfo (1, ID_GO_FORWARD, TBSTYLE_BUTTON, 1); str.LoadString (IDS_FORWARD); m_wndToolBar. SetButtonText (1, str); m_wndToolBar.SetButtonInfo (2, ID_VIEW_STOP, TBSTYLE_BUTTON, 2); str.LoadString (IDS_STOP); m_wndToolBar.SetButtonText (2, str); m_wndToolBar.SetButtonInfo (3, ID_VIEW_REFRESH, TBSTYLE_BUTTON, 3); str .LoadString (IDS_REFRESH); m_wndToolBar.SetButtonText (3, str); m_wndToolBar.SetButtonInfo (4, ID_GO_START_PAGE, TBSTYLE_BUTTON, 4); str.LoadString (IDS_HOME); m_wndToolBar.SetButtonText (4, str);

转载请注明原文地址:https://www.9cbs.com/read-53202.html

New Post(0)