Abstract: This article introduces a programming method for adding and dynamically replacing the skin for application toolbars. Introduction If you can also have a dynamic replacement of your skin in your own procedure, you will make the software to add a few highlights to make it easier for users. With the text of the article, there is less information on this technology, and it is very uncoordinated with its prevalence, and the existing small amount of information is mostly based on the dialog. It is nothing more than to cover a layer of pictures on the dialog. Replace the picture to realize the dynamic skin of the program. Although this is also one of the dynamic skin, this paper will focus on another dynamic skin-free technology of the toolbar, which is also a common use of software, such as software. Skating technology. Program supports dynamic regeneration Since the skinning function is an extension of the program frame, the relevant processing code is now taken in the main frame class. In order for the program to have the ability to have a lot of life, the program must first have the basic conditions for skin. First of all, it can be clearly: handling objects for ordinary tool bars, and its base class is CToolbar. By MSDN help can understand the inheritance relationship between this class and its "close relative" as shown. Through the review of these related classes, it can be found that the CREBAR class is special, it is not used in itself, which is mainly used for other toolbars, for example, can use its member function addbar () toolbar (Toolbar) The toolbar of the dialogbar is added to the composite strip, allowing the toolbar to display multiple toolbars. So you can draw this design idea: The toolbar of the program frame is no longer implemented directly, but is based on the composite strip, and the original toolbar is added to it through the CREBAR's AddBar () function. The skin can be tiled on the composite strip by setting the RebarBandInfo structure associated with CREBAR, and because there is a tool baff, it must modify the style when the toolbar is created, so that the background is transparent, so It can only penetrate the skin in the lower layer.
Since CREBAR is used in the program design, it is more troublesome in a normal program. You can select the "Internet Explorer rebars" option in the fourth step when you create the project, so that the toolbar that creates will add a toolbar on the composite strip and A dialogue. Simply remove the declaration of the instance object M_WndDlgbar of the dialog bar CDialogbar from the onCreate () function of the primary framework class and the partial correlation code. Next, the window style such as TBStyle_Transparent is required to make it background, and then add a background transparent toolbar to the background after the completion of the composite strip:
m_wndToolBar.CreateEx (this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect (0,0,0,0), AFX_IDW_TOOLBAR) ...... m_wndReBar.AddBar (& m_wndToolBar, NULL, NULL, RBBS_GRIPPERALWAYS | RBBS_FIXEDBMP | RBBS_BREAK) After these few Step processes the main framework of the program to make it basically have a necessary condition for dynamic skin. Skin loading and dynamic replacement skin is typically published in the form of external resources, and then dynamically loaded by the program during use. The skin loaded into the toolbar can be divided into two steps: first load the skin from the file to memory, and then directly drawn directly to the composite strip. For the first step, you can use the API function loadImage to load the external file back.bmp from the file to the memory, and the returned handle can get the HBitmap type bitmap handle M_BmpBack:
m_bmpback = (hbitmap) loadImage (AFXGetInstanceHandle (), // application instantial handle "Back.bmp", image_bitmap, 0, 0, lr_loadfromfile | lr_createdibsection); After the skin is loaded, it needs to be set by setting the RebarBandInfo structure. The tile of the skin bitmap in the compound bar, which has more than 20 member variables, but here is only used to set the tile of the background bitmap, so only set FMASK to be RBBIM_BACKGROUND to specify HBMBACK valid, and put the front The bitmap handle M_BmpBack is delivered to the memory to the member variable to complete the loading and display of the skin, the following is the detailed code of this part: CrebarCtrl & rc = m_wndrebar.getRebarCtrl (); // Get the composite strip control pointer rebarbandInfo Info MEMSET (& INFO, 0, SIZEOF (RebarbandInfo)); // Clear info.cbsize = sizeof (info); info.fmask = rbbim_backround; // Specify HBMBACK valid // If the bitmap handle is not available, it is silver gray Background, otherwise this bitmap is used as a composite strip info.hbmback = m_bmpback! = INVALID_HANDLE_VALUE? M_BmpBack: Null; rc.setBandInfo (0, & info); // Setting Rc.UpdateWindow (); // Update window When skin It has been displayed on the toolbar to dynamically replace it, and only the simple call copy file function will be copied to back.bmp in the form of a new skin plug, and call the new skin plug-in again. Loading to realize dynamic skin replacement of the program. The copy file function is generally implemented with an API function CopyFile (), and the first two parameters of the function are the source file path and destination file path. The last Boolean parameter specifies the way the file copy is required, which is specified as false, that is, if the destination file already has, it is overwritten, otherwise the replacement of the skin will not be implemented. Small junctions This article achieves dynamic skin replacement of applications under VC by using the use of composite strips and CREBAR classes. The Crebar class is very rich, and this article is limited to the paramount failure to introduce, please refer to Microsoft's MSDN Help for details on this class. The procedures described herein are compiled by Microsoft Visual C 6.0 under Windows 98.