使用 CreateWindowEx 创建一个不带图标的窗口
使用 C#,我可以轻松获得我想要的效果:
但是,我在 C 中使用 Win32 API 做同样的事情时遇到困难。我不知道如何创建一个没有图标(根本)但仍然有标题、最小化按钮和的窗口一个关闭按钮。
我正确注册了我的课程,但我不知道要为窗口样式/扩展窗口样式添加什么。
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
上面的代码生成:
标题栏中仍然有一个图标,但没有我想要什么。
With C#, I was easily able to get the effect I wanted:
However, I'm having trouble doing the same thing using the Win32 API in C. I don't know how to create a window that has no icon (at all), but still has a caption, a minimize button, and a close button.
I registered my class properly, but I can't figure out what to put for the window styles/extended window styles.
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
The code above produced:
which still has an icon in the title bar and is not what I wanted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准窗口需要一个图标,因为它需要在屏幕底部的任务栏中以某种形式表示。如果主窗口之一没有图标,则在窗口切换器中按 Alt+Tab 时应显示什么?
您需要指定
WS_EX_DLGMODALFRAME
扩展样式 。这与当您关闭标题栏中的图标时 WinForms 设置的效果相同。您还需要确保在注册窗口类时没有指定图标。您需要将
WNDCLASSEX
结构的hIcon
和hIconSm
字段设置为 0。将代码更改为以下内容:
A standard window requires an icon because it needs some form of representation in the taskbar at the bottom of the screen. What should be displayed when you press Alt+Tab in the window switcher if one of the main windows doesn't have an icon?
You need to specify the
WS_EX_DLGMODALFRAME
extended style. This is the same effect that WinForms sets when you turn off the icon in the title bar.You also need to make sure that you do not specify an icon when you register the window class. You need to set the
hIcon
andhIconSm
fields of theWNDCLASSEX
structure to 0.Change your code to the following:
另外,请使用 Spy++ 或其他类似工具查看任何给定 HWND 实际使用的样式。将其指向 C# 窗口,然后在 C 代码中复制报告的样式。
On a side note, use Spy++ or other similar tool to see the styles that any given HWND actually uses. Point it at your C# window, then duplicate the reported styles in your C code.