Sreyan
Sreyan

Reputation: 367

Group Box look and feel

I am using Visual Studio 2008 Professional Edition. I have designed the following dialog in the dialog editor-: Dialog that I designed

Please pay close attention to the group box in the dialog called 'Tasks'. It looks fine over here but when I display it as a modeless dialog box from my application the look and feel of that GroupBox suddenly changes to -: Dialog box when displayed from application

Suddenly the original blue caption and rounded edges specified in the dialog editor are gone and are replaced with a black foreground and square edges. I want to know why this is suddenly happening and I want it to be displayed with the look and feel specified in the dialog editor.

The following code is present in my resource file(Timer.rc) for the dialog-:

IDD_FORMVIEW DIALOGEX 0, 0, 204, 118
STYLE DS_ABSALIGN | DS_SETFONT | DS_SETFOREGROUND | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW | WS_EX_NOACTIVATE
CAPTION "SR-Timer(Work in Progress)"
FONT 10, "Verdana", 400, 0, 0x0
BEGIN
    CONTROL         "Shutdown",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,73,37,48,10
    CONTROL         "Restart",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,73,54,39,10
    CONTROL         "Stand By",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON,73,70,44,10
    CONTROL         "Hibernate",IDC_RADIO4,"Button",BS_AUTORADIOBUTTON,73,87,47,10
    GROUPBOX        "Tasks",IDC_STATIC,59,28,90,78
END

Thanks in advance.

Upvotes: 1

Views: 2015

Answers (2)

Patrick
Patrick

Reputation: 23619

You should enable the XP common control style.

The easiest way to do this is to include this in your manifest file, e.g. by adding it to the linker, or adding a pragma in your code, like this:

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

EDIT: It might also be needed to explicitly initialize the common controls (not 100% sure), like this:

INITCOMMONCONTROLSEX    InitStr;
InitStr.dwSize = sizeof(InitStr);
InitStr.dwICC  = ICC_WIN95_CLASSES|ICC_DATE_CLASSES|ICC_COOL_CLASSES;
// Other classes are: ICC_COOL_CLASSES, ICC_INTERNET_CLASSES, ICC_PAGESCROLLER_CLASS, ICC_USEREX_CLASSES
InitCommonControlsEx(&InitStr);

It might also be needed to compile with the correct windows version defines. I compile using these command line options:

/D_WIN32_WINNT#0x0501 /DWINVER#0x0501 /D_WIN32_IE#0x0500

But this always implies that the application needs at minimum Windows XP.

EDIT2 (as an answer to sreyan's comment):

I tried compiling the following source file (called test.cpp):

#include <iostream>

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 

void main()
{
std::cout << "Hello World" << std::endl;
}

Using the following commands:

cl /EHsc /MD /c test.cpp
link test.obj

And the following files were generated:

23-04-12  10:49             9 728 test.exe
23-04-12  10:49               638 test.exe.manifest
23-04-12  10:49            16 812 test.obj

The test.exe.manifest file contains this:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*' />
    </dependentAssembly>
  </dependency>
</assembly>

So this seems to be working correctly.

Recheck the options you filled in in Visual Studio, and the pragma you've added. Try with a small app first (like the one above) until you get it working correctly. Then move on to your big application. If it doesn't work, compare what's different with the small app.

Success.

Upvotes: 4

Joey
Joey

Reputation: 354614

Apparently this requires a manifest and/or a call to InitCommonControls(). See Enabling Visual Styles for more information.

Upvotes: 3

Related Questions