views:

300

answers:

2

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?)

A: 

Do you call InitCommonControlsEx? Details are here.

Hans Passant
InitCommonControls is ignored by the Common Controls library version 6.
Pindatjuh
The non Ex version of InitCommonControls is a no-op on all versions, all it does is bring comctl32 into your address space (The point of that function is the dll function import, not the work the function does)
Anders
Yeah, that's what I meant. I blush when forced to write 'sex'. Relevant MSDN page: http://msdn.microsoft.com/en-us/library/dsezt3x7.aspx
Hans Passant
Thank you, it works now.
A: 

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.

  • Maybe common controls version 6.0 is not supported in Windows XP (?)
  • Perhaps the manifest must include all the needed controls, not only the version. Vista and may Wnd7 automatically initialize all the "common" common controls of the specified version, whereas Windows XP may not
valdo