An Implementation of the MFC beautifying Interface

Source: Internet
Author: User

Post address: http://blog.csdn.net/likezhaobin/article/details/6764415

Users who are familiar with VC/MFC programming interfaces often encounter the following problems: the small software functions they have compiled have been fully implemented, but the interface is extremely ugly, because Windows Default menus are used, dialog box, Status Bar, and other elements.
Therefore, the software's later beautification interface is a very important task. I searched the internet and summarized it as follows:
There are many solutions to beautify the interface:


A. Using Skin, there are many ready-made skin loading solutions on the Internet
B. Use CDialogSk and CButtonST to beautify the dialog box (that is, map)
C. use Flash as the interface
D. Use web pages for interface creation
E. Use WPF
The first solution is the dummies, and is also used more often. As long as the software functions are implemented, you can add a few lines of simple code to achieve beautification.

The first solution is to use SkinMagic for skin replacement. SkinMagic has many cracked versions on the Internet, and many beautiful skins are provided by netizens, you only need to add several lines of initialization code in the middle of the program to make the program very beautiful instantly. The general usage is as follows:
(1) Copy SkinMagicTrial. lib, SkinMagicTrial. dll, and SkinMagicLib. h to the project root directory and add them to the project;
(2) Put the Skins folder under the project root directory;
(3) Copy # include "SkinMagicLib. h" to the StdAfx. h file;
(4) Open the InitInstance () function in the C ** App class and add
VERIFY (1 = InitSkinMagicLib (AfxGetInstanceHandle (), _ T ("ReadUI"), NULL, NULL ));
VERIFY (1 = LoadSkinFile ("Skins \ corona. smf "));
VERIFY (1 = SetDialogSkin (_ T ("Dialog ")));
(5) At the end of the InitInstance () function, but before the following code,
M_pMainWnd-> ShowWindow (SW_SHOW );
M_pMainWnd-> UpdateWindow ();
Add the following code:
VERIFY (1 = SetWindowSkin (m_pMainWnd-> m_hWnd, _ T ("MainFrame ")));
(6) use the Class Wizard to add the ExitInstance () function to the C ** App. The content is as follows:
ExitSkinMagicLib ();
Return CWinApp: ExitInstance ();
In this way, you can easily beautify the interface.

However, in my own practice, this method will cause a problem: after skin replacement, the main menu items cannot be operated as before; for example, if I want to operate the first sub-menu, you can use CMenu * pMenu = GetMenu ()-> GetSubMenu (0) to obtain control. However, after SkinMagic is used, the compilation is still normal, but an error occurs during running !!!


The cause is that SkinMagic removes the default menu bar on the form during skin replacement and uses the SetMenu (NULL) method. The purpose is to remove the default menu bar from the original position during operations. The menu bar you see is actually drawn by SkinMagic through the HMenu saved internally. Therefore, if the value returned by the user during GetMenu () is NULL and CMenu * pMenu = GetMenu ()-> GetSubMenu (2), errors will naturally occur.


Check the SkinMagicLib. h file multiple times and finally find the solution as follows:
SkinMagic's dynamic library provides such a function HMENU _ stdcall GetSkinMenu (HWND hWnd). What does it mean? At that time, you can get the menu handle, so that you can combine the API function HMENU GetSubMenu (HMENU hMenu, int nPos) to get the sub-menu handle, and then perform some operations:
For example, to disable the first menu item of the first sub-menu, you can use the following statement:
EnableMenuItem (GetSubMenu (GetSkinMenu (* AfxGetApp ()-> m_pMainWnd), 0), 0, MF_BYPOSITION | MF_GRAYED | MF_DISABLED );

Enjoy the fun of changing the interface at will .....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.