在Messagebox中使用C ++ Win32 API禁用右上方的X-Button图标? [英] Disable X-Button Icon on the top of the right in Messagebox Using C++ Win32 API?
问题描述
我有一个Windows消息框包含 OKCANCEL
按钮..
消息框在右上角有一个关闭(X-Button)...
retun1 = MessageBox(hDlg,TEXT(您的密码将过期,您必须更改密码),TEXT(登录消息),MB_OK | MB_ICONINFORMATION);
我只想使用 CANCEL
按钮关闭消息框
所以,我想要禁用X-Button图标...
我已经尝试了 MB_ICONMASK
但我不能得到它,我需要什么...
如何解决?
我们已经给了我们一个方法,但是关闭按钮的一种方法就是将类样式设置为包含 CS_NOCLOSE
,您可以使用窗口句柄和 SetClassLongPtr
。请考虑以下完整示例:
#include< windows.h>
DWORD WINAPI CreateMessageBox(void *){//线程,所以我们仍然可以使用它
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))); // Ex版本适用于您
LONG_PTR style = GetWindowLongPtr(msg,GWL_STYLE); //获取当前样式
SetWindowLongPtr(msg,GWL_STYLE,style&〜WS_SYSMENU); //删除系统菜单
WaitForSingleObject(thread,INFINITE); //查看效果,直到你关闭
}
i am using C++ win32 API...
i have a Windows messagebox contain OKCANCEL
Button...
the messagebox have a close(X-Button) on the right top...
retun1=MessageBox(hDlg,TEXT("Your password will expired,you must change the password"),TEXT("Logon Message"),MB_OK | MB_ICONINFORMATION);
i only want to close the messagebox using the CANCEL
Button...
So,i want to disable the X-Button Icon...
i am already try MB_ICONMASK
MB_MODEMASK
Somethink like that.
But i cant get it,what i need...
How can i Resolve it?
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
}
这篇关于在Messagebox中使用C ++ Win32 API禁用右上方的X-Button图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!