“BS_COMMANDLINK”未在此范围内声明!
由于BS_COMMANDLINK 在commctrl.h 中需要NTDDI_VERSION >= 0x06000000,因此需要高于0x0600 的NTDDI 版本。
您可以像这样在源文件中定义它:
#define _WIN32_WINNT 0x0601
这样的工作代码示例:
#define _WIN32_WINNT 0x0601
#include <windows.h>
#include <commctrl.h>
//...
int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
InitCommonControls();
HWND hCmdLnk = CreateWindowW(
L"BUTTON", // Predefined class; Unicode assumed
L"", // Text will be defined later
WS_VISIBLE | BS_COMMANDLINK, // Styles
200, // x position
10, // y position
200, // Button width
100, // Button height
NULL, // Parent window
NULL, // No menu
hInstance,
NULL); // Pointer not needed
SendMessage(hCmdLnk, WM_SETTEXT, 0, (LPARAM)L"Command link 2");
SendMessage(hCmdLnk, BCM_SETNOTE, 0, (LPARAM)L"Line 2");
//...
}
像这样使用 MinGw 编译它:
i686-w64-mingw32-g++ hello.cpp -mwindows
更多详细信息请参考“Using the Windows Headers”。
为了使命令链接按钮正确显示,Comctl32 库需要被链接,XML 清单指定 Windows 通用控件库的版本 6 必须由 Windows 加载,并将其嵌入到您的应用程序作为类型为“RT_MANIFEST”的资源。
manifest.xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="Win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
</assembly>
资源文件(resource.rc):
#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
#define RT_MANIFEST 24
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "manifest.xml"
编译代码和资源文件并将它们全部链接到一个可执行应用程序中。通过-municode选项选择UNICODE。
i686-w64-mingw32-g++ -municode -c commandLinkTest.cpp -o commandLinkTest.o
windres -i resource.rc -o resource.o
i686-w64-mingw32-g++ -o commandLinkTest.exe commandLinkTest.o resource.o -s -lcomctl32 -Wl,--subsystem,windows -municode
文件列表:
命令链接按钮窗口如下所示: