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 按钮图标?


- 如何对自定义类的向量使用std::find()? 2022-11-07
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01