使用 C++ Win32 API 禁用消息框右上角的 X 按钮图标? [英] Disable X-Button Icon on the top of the right in Messagebox Using C++ Win32 API?

查看:30
本文介绍了使用 C++ Win32 API 禁用消息框右上角的 X 按钮图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C++ win32 API...

i am using C++ win32 API...

我有一个包含 OKCANCEL 按钮的 Windows 消息框...

i have a Windows messagebox contain OKCANCEL Button...

消息框的右上角有一个关闭(X-Button)...

the messagebox have a close(X-Button) on the right top...

retun1=MessageBox(hDlg,TEXT("您的密码将过期,必须更改密码"),TEXT("登录消息"),MB_OK | MB_ICONINFORMATION);

我只想使用 CANCEL 按钮关闭消息框...

i only want to close the messagebox using the CANCEL Button...

所以,我想禁用 X 按钮图标...

So,i want to disable the X-Button Icon...

我已经在尝试 MB_ICONMASK MB_MODEMASK 这样想.

i am already try MB_ICONMASK MB_MODEMASK Somethink like that.

但我无法得到它,我需要什么......

But i cant get it,what i need...

我该如何解决?

推荐答案

除了你给我们的问题之外,很可能还有一个更大的问题,但禁用关闭按钮的一种方法是将类样式设置为包含 CS_NOCLOSE,您可以使用窗口句柄和 SetClassLongPtr 来完成.考虑以下完整示例:

There's most likely a bigger problem beyond what you've given us, but one way to disable the close button is to set the class style to include CS_NOCLOSE, which you can do with a window handle and SetClassLongPtr. Consider the following full example:

#include <windows.h>

DWORD WINAPI CreateMessageBox(void *) { //threaded so we can still work with it
    MessageBox(nullptr, "Message", "Title", MB_OKCANCEL);
    return 0;
}

int main() {
    HANDLE thread = CreateThread(nullptr, 0, CreateMessageBox, nullptr, 0, nullptr);

    HWND msg;
    while (!(msg = FindWindow(nullptr, "Title"))); //The Ex version works well for you

    LONG_PTR style = GetWindowLongPtr(msg, GWL_STYLE); //get current style
    SetWindowLongPtr(msg, GWL_STYLE, style & ~WS_SYSMENU); //remove system menu 

    WaitForSingleObject(thread, INFINITE); //view the effects until you close it
}

这篇关于使用 C++ Win32 API 禁用消息框右上角的 X 按钮图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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