使用 CreateWindowEx 创建一个不带图标的窗口

发布于 2024-10-16 08:45:18 字数 745 浏览 7 评论 0原文

使用 C#,我可以轻松获得我想要的效果:

standard window without icon in title bar

但是,我在 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);

上面的代码生成:

standard windowWITH an icon in the title bar

标题栏中仍然有一个图标,但没有我想要什么。

With C#, I was easily able to get the effect I wanted:

standard window without icon in title bar

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:

standard window WITH an icon in the title bar

which still has an icon in the title bar and is not what I wanted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫性小仙女 2024-10-23 08:45:18

标准窗口需要一个图标,因为它需要在屏幕底部的任务栏中以某种形式表示。如果主窗口之一没有图标,则在窗口切换器中按 Alt+Tab 时应显示什么?

您需要指定WS_EX_DLGMODALFRAME扩展样式 。这与当您关闭标题栏中的图标时 WinForms 设置的效果相同。

需要确保在注册窗口类时没有指定图标。您需要将 WNDCLASSEX 结构的 hIconhIconSm 字段设置为 0。

将代码更改为以下内容:

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);

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 and hIconSm fields of the WNDCLASSEX structure to 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);
乞讨 2024-10-23 08:45:18

另外,请使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文