更改C ++应用程序的应用程序窗口图标

时间:2019-05-28 15:12:49

标签: c++ windows directx-11 visual-studio-2019

所以我在设置c ++图形应用程序窗口的默认图标时遇到问题。我正在关注DirectX 11的系列教程(找到here

任务栏图标改变得很好,生成的可执行文件使用了自定义图标,但由于某些原因,应用程序窗口却没有。

根据发现的here Microsoft文档,我应该在WNDCLASSEX内设置两个HICON属性:hIcon和hIconSm。根据研究,可以使用LoadIcon(hInstance, IDI_APPLICATION)进行设置,如本示例所示 LoadIcon

我不确定要重现此问题将采取的步骤。我不知道在制作.rc文件以将其加载到.ico映像时是否出了问题。或者,如果我加载的图像不正确,或者...好吧...有些晦涩的原因,它只能起到一半的作用。

这是我用于注册用于创建窗口的窗口类的代码

// The window class. This has to be filled BEFORE the window can be WNDCLASSEX wc;
/ Flags [Redraw on width/height change from resize/movement]
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
// Pointer to the window processing function for handling messages from this window
wc.lpfnWndProc = HandleMessageSetup;
// Number of extra bytes to allocate following the window-class structure
wc.cbClsExtra = 0;
// Number of extra bytes to allocate following the window instance
wc.cbWndExtra = 0;

// Handle to the instance that contains the window procedure
wc.hInstance = m_hInstance;
// Handle to the class icon. Must be a handle to an Icon resource
wc.hIcon =  LoadIcon(m_hInstance, IDI_APPLICATION);
// Handle to the small icon for the class
wc.hIconSm = LoadIcon(m_hInstance, IDI_APPLICATION);
// Handle to the class cursor. If null, an application must explicitly set the cursor shape whenever the mouse moves into the application window
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// Handle to the class background brush for the window's background colour. When NULL an application must paint its own background colour
wc.hbrBackground = NULL;
// Pointer to a null-terminated string for the menu
wc.lpszMenuName = NULL;
// Pointer to null-terminated string of our class name
wc.lpszClassName = m_windowClass.c_str();
wc.cbSize = sizeof(WNDCLASSEX);

// Register the class to make it usable
RegisterClassEx(&wc);

如果需要更多代码,可以在github上找到我的存储库 (有问题的主要类是engine / RenderWindow)

根据研究,然后应该可以使用CreateWindowEx创建一个窗口。我的任务栏图标更改了,但是应用程序窗口图标没有更改。 Screenshot

没有错误。代码编译并成功运行。

0 个答案:

没有答案