Disable X-Button Icon on the top of the right in Messagebox Using C++ Win32 API?(使用 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 按钮图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 C++ Win32 API 禁用消息框右上角的 X 按钮图标?


基础教程推荐
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01