从Windows终端删除最小化按钮时,行为不一致

发布于 2025-02-04 14:28:28 字数 838 浏览 2 评论 0 原文

我正在使用Windows API从当前控制台窗口(Windows终端)禁用最小化按钮。

这是代码:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>


bool disableMinimize ( HWND hwnd )
{
    // use styles
    DWORD style = GetWindowLong( hwnd, GWL_STYLE );
    DWORD exStyle = GetWindowLong( hwnd, GWL_EXSTYLE );
    // set the window styles
    style &= ~WS_MINIMIZEBOX;
    exStyle &= ~WS_EX_APPWINDOW;
    // set the window styles
    SetWindowLong( hwnd, GWL_STYLE, style );
    SetWindowLong( hwnd, GWL_EXSTYLE, exStyle );
    // return
    return true;
}

int main() {
    disableMinimize( GetConsoleWindow() );
}

期望的是,窗口上的( - )按钮被弄清楚或无法访问,但是当我在Windows终端运行时,这似乎不起作用。

我拥有的理论是,Windows终端强迫WS_Minimizebox是真实的,否则我会感到困惑。

我想念什么?

I am using the Windows API to disable the minimize button from the current console window (Windows Terminal).

Here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>


bool disableMinimize ( HWND hwnd )
{
    // use styles
    DWORD style = GetWindowLong( hwnd, GWL_STYLE );
    DWORD exStyle = GetWindowLong( hwnd, GWL_EXSTYLE );
    // set the window styles
    style &= ~WS_MINIMIZEBOX;
    exStyle &= ~WS_EX_APPWINDOW;
    // set the window styles
    SetWindowLong( hwnd, GWL_STYLE, style );
    SetWindowLong( hwnd, GWL_EXSTYLE, exStyle );
    // return
    return true;
}

int main() {
    disableMinimize( GetConsoleWindow() );
}

What is expected is that the minimize (-) button on the window is greyed out or inaccessible, but this doesn't seem to be working when I am running on Windows Terminal.

The theory I have is that Windows Terminal is forcing WS_MINIMIZEBOX to be true, otherwise I am stumped.

What am I missing?

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

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

发布评论

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

评论(1

淡紫姑娘! 2025-02-11 14:28:28

该终端绘制了自己的最小化按钮(在XAML中),并且根本不依赖Win32样式。如果您想从终端中删除最小化按钮,则可能应该在

&lt;这是龙&gt;

从理论上讲,您可以通过禁用 showtabsintitlebar 。但是,知道 getConsolewindow 不会为您提供实际终端HWND的处理 - 它只会使您与该选项卡相关联。我不能高度强调这一点 - 不要惹 getConsolewindow 。这是一个不好的API,而且终端确实不太好。

&lt;/

The Terminal draws its own minimize button (in XAML), and doesn't rely on the win32 styling at all for this. If you'd like to remove the minimize button from the Terminal, you should probably file a feature request on the Terminal repo.

<here be dragons>

Theoretically, you can get the win32 titlebar back by disabling showTabsInTitlebar. Know, however, that GetConsoleWindow isn't going to get you the handle of the actual Terminal HWND - it will only get you a hidden HWND associated with that tab. I cannot stress this highly enough - don't mess with GetConsoleWindow. It's a bad API, and it really does NOT play nice with the Terminal.

</????>

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