Use cMenux to enable the application with cMenuxp in the VC.
With the introduction of Windows XP and Office XP, the Office XP interface style of gorgeous and refreshing temperament has gradually replaced the Windows classic interface style and has become the popular "fashion" of the current application, so how to make their own apps have OFFICE. The XP-style interface has also become the problem of the majority of programmers. For this purpose of the French programmer Jean-Michel Le FOL for Visual C , you can easily have your own application interface with the CMenux class. Let's take a detailed introduction to the steps to use CMenuxp.
First create a single document called "SDIXP". Before we can use cMenuxp, you must do a few steps:
1. Put the folder where cMenux's source files and header files (generally placed in "Tools") to the SDIXP source file.
2. Switch Visual C to "FileView", join the source files and header files of CMenuxp. Specifically, in the tree of FileView, expand SDI Files, click Right-click on the Source Files Directory, create a new directory ("New Folder ..."), you may wish to take the name "Tools", click on the Tools directory Right-click, choose to join the file ("Add Files To Folder ...", add all the source files (* .cpp) under the Tools folder. Similarly, in the header files directory of the file view, you will be called "Tool Headers", and all the header files (* .h) under the Tools folder are all added to the Tool Headers directory.
3. (1) The header file (for SDI program is usually mainfrm.h) in the control menu: The header file name of the required CMenuxp class:
#include "Tools / Menuxp.h"
#include "Tools / Toolbarxp.h"
#include "Tools / Statusbarxp.h"
#include "Tools / ComboBoxxp.h"
Then add the following macro in mainfrm.h:
Declare_MenuXP ()
The above statement can be added behind the macro definition "declare_message_map ()" in the CMAINFRAME declaration.
(2) Join in the source file of the class of the control menu:
Implement_menuxp (class name, base class name);
For the SDI project
Implement_menuxp (cmainframe, cframewnd);
The above statement is added behind "Implement_DyncRAME (CFrameWnd" at the beginning of CMAINFRAME.
(3) Then continue in the message mapping:
Begin_MESSAGE_MAP (ClassName, Baseclass)
// ...
ON_MENUXP_MESSAGES () // Add this line
END_MESSAGE_MAP ()
(4) InitInstance () functions in the class inherited in CWINAPP (here is CSDIXPAPP) join:
CMenuxP :: Initializehook ();
Can be added behind "AFXENABLECONTROLCONTAINER ();" statement.
Then, then reload the exitInstance () function for the CSDIXPAPP class, you can click on the "ClassView" in the Class View. Add it in the exitInstance () function:
CMenuxP :: uninitializehook ();
You can press F7 after completing the steps. If everything is no problem, we can start using CMenuxp to beautify our menu and toolbar.
First, let's turn the menu and menu item XP. This is very simple, just join in the cmainframe :: oncreate () function:
CMenuxP :: UpdateMenubar (this);
CMenuxP :: SetXPlooknfeel (this);
OK is OK. Now you compile, see if your program menu is changed to change?
If you want to customize the icon for your own menu item, we can be implemented with the cMenuxp :: setmenuitemage (Unit Nid, HimageList Himglist, INT NINDEX) function. To do this, we create a menu "Fruit" and menu item "Apple" (ID settings to ID_MenuItem_Apple), open the classwizard to add message processing functions onMenuiteMApple (). Then import a bitmap resource "apple.bmp", which is set to IDB_Apple.
Then we add a CIMAGELIST type member variable m_imglist to CMAINFRAME, then add: CMENUXP :: SetXPlookNFeel (this); ";
m_imglist.create (IDB_Apple, 0, 0, RGB (192, 192, 192);
CMenuXP :: setMenuitemImage (id_menuitem_apple, m_imglist, 0);
Where the m_imglist.create () function is the top left corner coordinate of the image copy of the bitmap file, the last parameter is the background color of the image. It is recommended to use 16 × 16 bitmaps. The last parameter of the setMenuItemImage () function refers to the index of the middle element of m_imglist, because m_imglist. Only one bitmap is included, it takes zero. After compiling, check out how much an apple icon in front of the "Fruit | Apple" menu item?
Below we will make the toolbar and status bar XP, this is more easy. As long as the CMAINFRAME declaration
CSTATUSBAR M_WNDSTATUSBAR;
CToolbar M_Wndtoolbar;
become
CSTATUSBARXP M_WNDSTATUSBAR;
CToolbarXP m_wndtoolbar;
Just get it! Don't believe, you have compiled and run, ^ _ *
CMenux can also turn buttons and drop-down list boxes into Office XP style. To this end, we create a new dialog IDD_APPLE. OK and CANCEL buttons keep do not move, we only add a drop-down list box control IDC_COMBO1. Then press CTRL W to open ClassWizard to create a CAPPLEDLG class for the dialog. The variable M_CMBX1 of the Control type is added to IDC_COMBO1 in the Member Variable in ClassWizard. Then, for CAPPLDLG, ONInitDialog () is used to initialize the control:
Bool cappledlg :: oninitdialog ()
{
CDIALOG :: OnInitdialog ();
m_cmbx1.addstring ("Red Apple"); M_CMBX1.AddString ("Green Apple");
Return True;
}
Then pop up the Apple dialog box in the message processing function of the "Apple" menu item:
Void CMAINFRAME :: onMenuiteMapple ()
{
// Todo: add your command handler code here
Cappledlg dialog;
Dialog.domodal ();
}
If you are compiling, you will see a dialog box when you open the "Fruit | Apple" menu item, but the above control is not Office XP style, let's start our XP, in fact, this is also very easy of!
First include "Tools / ComboBoxXP.H" and "Tools / Buttonxp.h" in the appledlg.h file, then find the location of the definition m_cmbx1, will
CCOMBOBOX M_CMBX1;
become
CCOMBOBOXXP M_CMBX1;
This way, the drop-down list box has the XP style, do not believe that you can compile it. About OK and Cancel buttons are slightly a little because they are the default button identified directly with IDOK and IDCANCEL, but in order to make them XP, we have to add control variables for the two buttons. Therefore, add: Declaration of CAPPLEDLG class:
CButtonXP M_BTNOK;
CButtonXP M_BTNCANCAL;
Add data exchange in the cappledlg :: DODataExchange () function:
DDX_Control (PDX, IDOK, M_BTNOK);
DDX_Control (PDX, IDCANCEL, M_BTNCANCEL);
In this way, the OK and Cancel buttons are also XP. Everyone compiles to run, see how the effect is.
In summary, CMenUXP using Jean-Michel Le FOL is very nice to replace the application of Visual C . It is also very good, and it is relatively simple to operate. The only less than a lot of other controls, such as the text box, etc., or there is no Office XP style, which is looking forward to the original author and our customers continue to improve the CMenuxp class.
Reference website:
http://www.codeproject.com/menu/Menuxp2.asp