Reputation: 736
Okay, so i'm pretty new to C++ & the Windows API and i'm just writing a small application. I wanted my application to make use of visual styles in both XP, Vista and Windows 7 so I added this line to the top of my code:
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
It seemed to work perfectly on my Windows 7 machine and also Vista machine. But when I tried the application on XP the application wouldn't load any controls (e.g. buttons, labels etc.) - not even messageboxes would display.
This image shows a small test application which i've just put together to demonstrate what i'm trying to explain: http://img704.imageshack.us/img704/2250/myapp.png
In this test application i'm not using any particularly fancy or complicated code. I've effectively just taken the most basic sample code from the MSDN Library (http://msdn.microsoft.com/en-us/library/ff381409.aspx) and added a section to the WM_CREATE message to create a button:
MyBtn = CreateWindow(L"Button", L"My Button", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 25, 25, 100, 30, hWnd, NULL, hInst, 0);
But I just can't figure out what's going on and why its not working. Any ideas guys? Thank you in advanced.
(By the way the application works in XP if i remove the manifest section from the top - obviously without visual styles though. I should also probably mention that the app was built using Visual C++ 2010 Express on a Windows 7 machine - if that makes a difference?)
Upvotes: 3
Views: 5353
Reputation: 11
I too came across this issue today after upgrading to Win7 and VC++ 2010 pro.
I first thought perhaps my manifest was corrupt and what made it worst was this was my second project in VC++ 2010 and the first one worked fine on Win7 and XP.
So I came to the conclusion that including InitCommonControls() at the beginning of my program fixed this issue, why?
So I added this at the top of my code:
#include <Commctrl.h>
#pragma comment (lib, "Comctl32.lib")
And this in my init code:
InitCommonControls();
Plus further to my searching for answers, VC+ 2010 now has the SysLink control in the list of controls, and this is the reason my first project run fine. Add one of these to a dialogbox and as long as code is added to handle a notification the Comctl32.lib and InitCommonControls or InitCommonControlsEx isn't needed? The built program will too run in Win7 and XP as long as a manifest with the common controls is embedded!
Upvotes: 1
Reputation: 12923
Hans Passant:
The idea of having the "manifest" included in the executable is to avoid calling the InitCommonControls
.
Without the manifest the OS automatically initializes the use of the most "common" comomn controls. And if the manifest is found in the executable resources - exactly those controls are initialized.
Well, I don't know the exact cause of the problem, I only can try to guess.
Upvotes: 1