11

How do I display a popup window in a Win32 Console application in Microsoft Visual C++? This is for building a drowsiness detection system using OpenCv.

3
  • Do you want a modal popup? Mar 19, 2014 at 9:43
  • I just want to display the message "The driver is sleeping!!" Mar 19, 2014 at 9:48
  • If(eyesclosed for a certain no of frames){Display popup(Sleeping);} Mar 19, 2014 at 9:49

3 Answers 3

14
MessageBox( nullptr, TEXT( "The driver is sleeping!!" ), TEXT( "Message" ), MB_OK );

Make sure to include windows.h. The thread you call this on will block.

2
  • 1
    thats not a popup window. its a message box. Mar 19, 2014 at 9:54
  • 4
    @vlad_tepesch: it is an OS-provided popup. "I just want to display the message ..." is exactly what MessageBox() is designed for. Mar 19, 2014 at 15:38
4

You can just call something like :-

MessageBoxA(NULL, "Wake Up!", "Alert!", MB_OK | MB_ICONEXCLAMATION);

You have to include for this to work.

These APIS still work from a console app.

2
#include <windows.h> 

int main() { 
        MessageBox(NULL, L"The message", L"The caption", MB_OK);

        return 0; 
} 

remember to link with user32.lib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.