VC no burden implementation XP style interface

xiaoxiao2021-03-06  89

Regarding the issue of XP style, there are many discussions on the Internet. Most of the practices are written a .manifest file, then change the file name, such as .exe file is Test.exe, will this. The Manifest file is renamed Test.exe.Manifest and puts it and test.exe in the same directory so that Test.exe will present XP interface style when running in XP or 2003 (must start the theme service).

Additional things must be said that according to the above method, Test.exe must first call the INITCOMMONCONTROLS function (abolition, not recommended) or the INITCOMMONCONTROLSEX function registers the component class from chactl32.dll. This step is required in VB, but in the VC (MFC program), we seem to call this function, but why can the compiled program implement XP style? The reason is that MFC has done this thing for us. If we are a window class that makes the MFC registration, it will call the _afxinitcommonControls function, and the main operation of _afxinitcommonControls is to load comctl32.dll, and then determine if there is any InitcommonControlsex function in the .dll file, if there is called, no call INITCOMMONCONTROLS, to this truth. Someone may be like me, watching the name of the window that starts with "AFX" is very uncomfortable, so I like to register the window class, but when we register your own window class, you must make sure to call the InitCommonControlsex function, this must remember If you forget, you will see a blank window.

Said so much, I have a bit run, huh, huh. Now return to the topic. The method I mentioned above has been introduced many websites, but there is a fatal shortcomings, that is, there must be that .manifest files like the shadow, the exe file, which is of course we don't want to see. Is there a way to "comb" in the EXE file? The answer is affirmative, this is also the meaning of "no burden" in this article.

Of course, that manifest file is still there, but not the .exe file in the same directory, but put it in the resource file, build .res file, naturally and .exe file after Link "Combined" together.

First, please come out. Manifest file:

Name = "xp style manifest"

Processrarchitecture = "x86"

Version = "

1.0.0

.0 "

TYPE = "Win32" />

TYPE = "Win32"

Name = "Microsoft.windows.common-controls" version = "

6.0.0

.0 "

Processrarchitecture = "x86"

PublickeyToken = "6595b64144ccf1df"

Language = "*"

/>

Everyone also saw it, this is actually an XML file, open the notepad, copy the above content, then the reply, the file name is arbitrary, here I save XPStyle.Manifest.

Then create a new MFC AppWizard (Exe) project in the VC, and Document / View or Dialog can then copy XPStyle.manifest to the project where the project is located, and then manually modify the resource files under the project directory with Notepad or other text editing tools. .rc), in the final plus one line:

1 24 "XPStyle.Manifest"

Compile and connect the project in the VC to generate .exe executable, run a look.

It's that simple? It's that simple. : D

Here I explain more, and finally the line, "1" represents the resource ID, must be "1". "24" represents the resource type, I think we are very familiar with RT_ACCELERATOR, RT_BITMAP, RT_MENU, RT_String and other resources, and "24" is actually RT_Manifest. I will no longer be embarrassed in the final number.

Ok, the compiled this .exe file gets where it can be, all the XP-style interface, no need to rely on the .manifest file. Oh, of course, you must be under XP or 2003 system.

Good effect? ! :)

Source code download:

http://9cbsgoodname008.51.net/xpstylevc.zip

* ------------------------------------------- *

* Please inform the author and indicate the source, 9CBS welcomes you! *

* Author: Lu Peipei (goodname008) *

* Email: GoodName008@163.com *

* Column: http://blog.9cbs.net/goodname008 *

* ------------------------------------------- *

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

New Post(0)