如何使用WINAPI更改标题栏图标 [英] How to change the title bar icon using winapi

查看:934
本文介绍了如何使用WINAPI更改标题栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Windows API的应用程序,并已使用的资源文件夹的图标更改为自定义的我做了。现在的计划是用我的桌面图标但是在标题栏中有默认的图标,这一个是准确的。

现在怎么了,我想将其更改为我的自定义图标?
我使用MSVC ++

  WNDCLASS WNDCLASS;wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc的;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance =实例句柄;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor =使用LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
HWND = CreateWindow的(szAppName,
    TEXT(随机),
    WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    300,
    120,
    空值,
    空值,
    实例句柄,
    空值);


解决方案

如果您使用 RegisterClassEx 来注册窗口类,在 WNDCLASSEX 结构具有 hIconSm 字段,可以让你指定一个小图标。如果你走这条路,不要忘了也初始化 CBSIZE 字段。

另外,你可以创建后使用 WM_SETICON 消息分配一个小图标的窗口。

I have made an application using Windows API and have used the resource folder to change the icon to a custom one I made. Now the program is using my icon on the desktop however in the title bar there is the default icon, this one to be exact.

Now how am I suppose to change it to my custom icon? I am using MSVC++

WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;


hwnd = CreateWindow(szAppName,
    TEXT("Random"),
    WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    300,
    120,
    NULL,
    NULL,
    hInstance,
    NULL);

解决方案

If you use RegisterClassEx to register your window class, the WNDCLASSEX structure has a hIconSm field that lets you specify a small icon. If you go this way, don't forget to also initialize the cbSize field.

Alternatively, you can assign a small icon to a window after creation using the WM_SETICON message.

这篇关于如何使用WINAPI更改标题栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆