Non blocking message box?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<windows.h>
#include<stdio.h>

 int int_AppRunning = 1;
 
 LRESULT CALLBACK OurWindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)
 {
     switch(uint_Message)
     {
		 case WM_LBUTTONUP:
         {
             int_AppRunning = WM_LBUTTONUP;
             break;
         }
		 case WM_LBUTTONDOWN:
         {
             int_AppRunning = WM_LBUTTONDOWN;
             break;
         }
		 case WM_RBUTTONDOWN:
         {
             int_AppRunning = WM_RBUTTONDOWN;
             break;
         }
         case WM_KEYDOWN:
         {
             int_AppRunning = 0;
             break;
         }
         break;
     }
 
     return DefWindowProc(han_Wind,uint_Message,parameter1,parameter2);
 }
 
 HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height)
 {
     WNDCLASSEX wnd_Structure;
 
     wnd_Structure.cbSize = sizeof(WNDCLASSEX);
     wnd_Structure.style = CS_HREDRAW | CS_VREDRAW;
     wnd_Structure.lpfnWndProc = OurWindowProcedure;
     wnd_Structure.cbClsExtra = 0;
     wnd_Structure.cbWndExtra = 0;
     wnd_Structure.hInstance = GetModuleHandle(NULL);
     wnd_Structure.hIcon = NULL;
     wnd_Structure.hCursor = NULL;
     wnd_Structure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
     wnd_Structure.lpszMenuName = NULL;
     wnd_Structure.lpszClassName = "WindowClassName";
     wnd_Structure.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
 
     RegisterClassEx(&wnd_Structure);
 
     return CreateWindowEx(WS_EX_CONTROLPARENT, "WindowClassName", str_Title, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, int_XPos, int_YPos, int_Width, int_Height, NULL, NULL, GetModuleHandle(NULL), NULL);
 }
 
 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreviousInstance,LPSTR lpcmdline,int nCmdShow)
 {
     MSG msg_Message;
	 FILE *outFile;
	 char name[100];
	 int count = 0;
	 
 
     HWND han_Window = NewWindow("DirectX C++ Tutorial",100,100,500,500);
 
     while(int_AppRunning > 0)
     {
		 count++;
         if(PeekMessage(&msg_Message,han_Window,0,0,PM_REMOVE))
         {
             if(!IsDialogMessage(han_Window,&msg_Message))
             {
                 DispatchMessage(&msg_Message);
             }
         }
		 if (int_AppRunning == WM_LBUTTONUP)
		 {
			 MessageBox(han_Window,"left mouse up","InitializeDevice()",MB_OK);
         }
		 else if (int_AppRunning == WM_LBUTTONDOWN)
		 {
			 MessageBox(han_Window,"left mouse down","InitializeDevice()",MB_OK);
         }
		 else if (int_AppRunning == WM_RBUTTONDOWN)
		 {
			 MessageBox(han_Window,"right mouse down","InitializeDevice()",MB_OK);
         }
		 else if (int_AppRunning == 0)
		 {
			 MessageBox(han_Window,"you pressed a key, exiting","InitializeDevice()",MB_OK);
         }
		 if (int_AppRunning > 0) int_AppRunning = 999;
	 }
 
     DestroyWindow(han_Window);
 
     return 0;
 }


A simple event loop, I want to display incoming main window events in some sort of message box, but in above code WM_LBUTTONUP is never processed because messagebox blocks everything from WM_LBUTTONDOWN up to and including WM_LBUTTONUP. Is there a non blocking version of messageBox and/or a way to get messageBox to pass on events to its parent window? I want separate window output, not something like "OutputDebugString".
There is no non-blocking version of the MessageBox function.

But all MessageBox does is display a modal (blocking) dialog using the DialogBox function. So you can display an equivalent dialog template but as a modeless (non-blocking) dialog using CreateDialog.

Is this just for diagnostic purposes?

If so, do you know about DebugView.exe? It's app which displays the strings sent to OutputDebugString when an app is run normally (not under a debugger.)

It's also possible to create a console for a GUI process and then write to it as normal, using cout. (But it takes a bit of setting up.)

Or you could even write your output to file and then use a tail application?

Andy

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

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

DebugView
http://technet.microsoft.com/en-gb/sysinternals/bb896647.aspx
Last edited on
msdn coding is very helpful thank you
Topic archived. No new replies allowed.