【问题标题】:Creating a Win32 application for both XP and Vista/Windows 7为 XP 和 Vista/Windows 7 创建 Win32 应用程序
【发布时间】:2011-09-14 14:05:09
【问题描述】:

我使用纯 win32 api(没有 MFC 或 WPF)用 C++ 编写了一个应用程序。 我希望相同的 .exe 在 Window 的 XP 和 Windows Vista / Windows 7 下运行。

我正在使用清单将视觉样式添加到我的应用程序中的控件。但是,当我在 XP 机器上测试应用程序时,按钮不显示。只有编辑控件和菜单栏可以。

编辑:我想我忘了提及这一点,但该应用程序在 WIndows 7/Vista 上运行良好。 编辑 2: 我正在使用 MinGW 编译器 我认为这是清单的问题,所以我将其删除并重新编译了我的程序。但是按钮仍然没有出现。 我使用的清单如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="*"
    name="BlackJack.Viraj"
    type="win32"
/>
<description>Your application description here.</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.2600.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>

问题出在清单中还是其他原因?

【问题讨论】:

  • 您是否使用了带有 UAC 盾牌的新按钮样式?我不知道 XP 是否忽略了未知标志,或者它是否是一个未知按钮。
  • 没有。它们都是普通的按钮。
  • 能贴出按钮创建的代码吗?
  • 问题在于没有调用 InitCommonControls。

标签: c++ windows winapi manifest


【解决方案1】:

请务必致电InitCommonControlsEx

【讨论】:

  • 如果他甚至没有清单并且仍然有问题,那么我认为这不会有帮助 - 据我所知,您不必仅仅为了创建一个Win32 中的简单按钮。 (并不是说这不是一个好调用的函数!)
  • InitCommonControlsEx 与清单无关。它只是确保加载了公共控件 DLL
  • 是的,我知道 - 我查过了。但是按钮早于通用控件 DLL 的存在......我很惊讶如果甚至没有清单,就需要这个 API 调用!
  • 为什么会有任何不同?如果您不调用它,那么它在非主题中同样会失败?
  • 不确定。我只知道我从经验中遇到了同样的问题。
【解决方案2】:

这是另一回事。假设它们是正常的标准按钮,无论清单看起来如何,或者是否有一个,它们都应该显示出来。正在发生其他事情。

【讨论】:

    【解决方案3】:

    除非您使用新的 Windows 7 API,否则标准应用程序将在这两个平台上运行良好。如果您发现有问题,Windows 7 也有兼容模式。

    您确定在程序开始时调用了 InitCommonControls API 吗?

    了解为什么它很重要 - http://blogs.msdn.com/b/oldnewthing/archive/2005/07/18/439939.aspx

    我建议你参考一个纯 Win32 应用程序 http://blogs.msdn.com/b/oldnewthing/archive/2005/04/22/410773.aspx

    我还建议将清单放在源文件中的链接器选项中。

    #ifdef _UNICODE
    #if defined _M_IX86
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_IA64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif
    #endif
    

    【讨论】:

    • #pragma comment 我相信是 Visual C-ism,因此不适用于 Mingw。
    【解决方案4】:

    清单很好。因此问题必须出在您的代码中。创建主题应用程序与创建非主题应用程序并不完全相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 2011-03-08
      • 2012-02-20
      • 1970-01-01
      • 2010-12-20
      • 2014-06-16
      • 1970-01-01
      相关资源
      最近更新 更多