MFC MessageBox does not appear at the top of all windows

I created the application in VC ++, the problem is that if an error occurs, I display a MessageBox. but this MessageBox is not displayed in front. I have to press the ALT key to stand in front of this application. My application becomes active until I press ALT. and click OK on the MessageBox.

Here is the attached code.

MessageBox(NULL,"Invalid File, Parsing is going to be terminate"); 

AfxMessageBox("Win32 MessageMessage",MB_OK | MB_ICONEXCLAMATION | MB_TOPMOST);

I am very grateful if anyone help me

+4
source share
1 answer

You need to pass the Handle to display the Messagebox on the screen, you can use HWND WINAPI GetDesktopWindow (void); to get the handle to the desktop and pass it to the MessageBox () function.

You can get additional help from

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633504%28v=vs.85%29.aspx

GetDesktopWindoe retrieves the handle to the desktop window. The desktop window covers the entire screen. The desktop window is the area over which other windows are painted. Thus, this will work for OpenGL as well.

+1
source

Source: https://habr.com/ru/post/1390795/


All Articles