简体   繁体   English

群组框外观

[英]Group Box look and feel

I am using Visual Studio 2008 Professional Edition. 我正在使用Visual Studio 2008专业版。 I have designed the following dialog in the dialog editor-: 我在对话框编辑器中设计了以下对话框: 我设计的对话框

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 -: 在这里看起来不错,但是当我从应用程序中将其显示为无模式对话框时,该GroupBox的外观突然变为-: 从应用程序显示时的对话框

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-: 我的对话框的资源文件(Timer.rc)中包含以下代码:

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. 提前致谢。

You should enable the XP common control style. 您应该启用XP通用控件样式。

The easiest way to do this is to include this in your manifest file, eg 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: 编辑:可能还需要显式初始化公用控件(不是100%确定),如下所示:

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. 可能还需要使用正确的Windows版本定义进行编译。 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. 但这始终意味着该应用程序至少需要Windows XP。

EDIT2 (as an answer to sreyan's comment): EDIT2(作为对sreyan的评论的答复):

I tried compiling the following source file (called test.cpp): 我尝试编译以下源文件(称为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: test.exe.manifest文件包含以下内容:

<?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. 重新检查您在Visual Studio中填写的选项以及已添加的编译指示。 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. 成功。

Apparently this requires a manifest and/or a call to InitCommonControls() . 显然,这需要清单和/或对InitCommonControls()的调用。 See Enabling Visual Styles for more information. 有关更多信息,请参见启用视觉样式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM