windows 使用 CreateWindowEx 创建一个没有图标的窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4905465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a window using CreateWindowEx without an icon
提问by Neal P
With C#, I was easily able to get the effect I wanted:
使用 C#,我可以轻松获得我想要的效果:
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.
但是,我在 C 中使用 Win32 API 做同样的事情时遇到了麻烦。我不知道如何创建一个没有图标(根本没有)但仍然有标题、最小化按钮和关闭的窗口按钮。
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.
标题栏中仍然有一个图标,这不是我想要的。
回答by Cody Gray
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+Tabin the window switcher if one of the main windows doesn't have an icon?
标准窗口需要一个图标,因为它需要在屏幕底部的任务栏中进行某种形式的表示。如果主窗口之一没有图标,当您在窗口切换器中按Alt+时应该显示什么Tab?
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.
您需要指定WS_EX_DLGMODALFRAME
扩展样式。这与关闭标题栏中的图标时 WinForms 设置的效果相同。
You alsoneed to make sure that you do not specify an iconwhen you register the window class. You need to set the hIcon
and hIconSm
fields of the WNDCLASSEX
structure to 0.
您还需要确保在注册窗口类时没有指定图标。您需要将结构体的hIcon
和hIconSm
字段设置WNDCLASSEX
为 0。
Change your code to the following:
将您的代码更改为以下内容:
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);
回答by Remy Lebeau
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.
附带说明一下,使用 Spy++ 或其他类似工具查看任何给定 HWND 实际使用的样式。将其指向 C# 窗口,然后在 C 代码中复制报告的样式。