Click here to Skip to main content
14,979,090 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Is it possible to programmatically close a MFC MessageBox?
Or would I need to create a custom dialog?

TIA

Tony
Posted

You have to create your custom message box dialog. There are examples here at CodeProject [^].
:)
   
v3
Create a Messagebox by applying its caption
for Example ::Messagebox(hWnd,"TEXT","YOURTITLE",MB_OK);

Now from other thred find window like
HWND hWnd = ::FindWindow(NULL,"YOURTITLE");
if(hWnd)
{
::PostMessage(hWnd,WM_CLOSE,0,0);

}
   
If you are referring to AfxMessageBox, no. You need to click in a button or close it with the "x" manually.

if you want your programm to close your MessageBox then it should create it before, meaning you need to do your own one.
   
Not sure what you mean. If you call AfxMessageBox, you will be blocked there until the user closes it. How can you even issue a request to close that message box? Unless you have a backgound thread...
   
Create a Messagebox by applying its caption
for Example ::Messagebox(hWnd,"TEXT","YOURTITLE",MB_OK);

Now from other thred find window like
HWND hWnd = ::FindWindow(NULL,"YOURTITLE");
if(hWnd)
{
::PostMessage(hWnd,WM_CLOSE,0,0);

}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900