Note that there are some explanatory texts on larger screens.

plurals
  1. POWin32 MessageBox doesn't appear
    primarykey
    data
    text
    <p>I'm stuck with a strange problem. I'm making a Win32 application in VC++ 2008, making a class to encapsulate most of the work for easy repetition when calling a <code>MessageBox</code>. The message box` is created (I think) but doesn't show up unless I press the Alt key!</p> <p>What happen exactly is :</p> <ol> <li><p>I run the program</p></li> <li><p>press Enter</p></li> <li><p>the main window lose focus</p></li> <li><p>give beep sound when i click on the main window as if a modal MessageBox is present</p></li> <li><p>either press Escape... focus is gained OR press Alt then the MessageBox appear with alt key pressed (i.e. menu will drop )!!!!!!</p></li> </ol> <p>P.S. It was working fine but suddenly this happened. I didn't find any difference - I even made a new project!</p> <p>This is supposed the Main program:</p> <pre><code>int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; CWnd cMainWindow(TEXT("DentoMan"), TEXT("Bejkoman")); // pass The class name and window name to the constructor cMainWindow.CreateDef(); //Create the Window while (GetMessage(&amp;msg, NULL, 0, 0)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } return (int)msg.wParam; } </code></pre> <p>While This is the Class file</p> <pre><code>CWnd::CWnd() { }; CWnd::CWnd(LPTSTR lpszClassName, LPTSTR lpszWindowName) { CWnd::lpszClassName = lpszClassName; CWnd::lpszWindowName = lpszWindowName; }; CWnd::~CWnd() { }; // Create the window with default parameters HWND CWnd::CreateDef(void) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = StaticWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = (HINSTANCE)GetModuleHandle(NULL); wcex.hIcon = 0; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 4); wcex.lpszMenuName = 0; wcex.lpszClassName = lpszClassName; wcex.hIconSm = 0; RegisterClassEx(&amp;wcex); g_hWnd = CreateWindowEx(0,lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, wcex.hInstance, this); hInst = wcex.hInstance; //Store hInstance in the class hInst variable if (!g_hWnd) return false; ShowWindow(g_hWnd, SW_SHOW); UpdateWindow(g_hWnd); return g_hWnd; } LRESULT CALLBACK CWnd::StaticWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { /* The Only Message we take here so we store the 'this' pointer within the window to identify messages comming from it by the 'this' pointer*/ if ( Message == WM_CREATE ) { SetWindowLong( hWnd, GWL_USERDATA, (LONG)((CREATESTRUCT FAR *)lParam)-&gt;lpCreateParams); } /* Store the window pointer in the class pointer we just created in order to run the right public WndPRoc */ CWnd *Destination = (CWnd*)GetWindowLong( hWnd, GWL_USERDATA ); // If the hWnd has a related class, pass it through if (Destination) { return Destination-&gt;WndProc( hWnd, Message, wParam, lParam ); } // No destination found, defer to system... return DefWindowProc( hWnd, Message, wParam, lParam ); }; LRESULT CWnd::WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { // Determine message type switch (Message) { case WM_LBUTTONDOWN: { /* this is a common trick for easy dragging of the window.this message fools windows telling that the user is actually dragging the application caption bar.*/ SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION,NULL); break; } /*case WM_CREATE: break; */ case WM_CLOSE: PostQuitMessage(0); break; case WM_DESTROY: UnregisterClass(lpszClassName, hInst); PostQuitMessage(0); break; case WM_KEYDOWN: //KeyBoard keys // Which key was pressed? switch (wParam) { case VK_ESCAPE: //close through escape key PostQuitMessage(0); return 0; case VK_RETURN: MessageBox(hWnd, TEXT("DFGDGD"), TEXT("DFGDFG"), NULL); return 0; } // End Switch break; case WM_COMMAND: /*switch(LOWORD(wParam)) { }*/ break; case WM_PAINT: break; default: return DefWindowProc(hWnd, Message, wParam, lParam); } // End Message Switch return 0; }; </code></pre> <p>The Class Header:</p> <pre><code>class CWnd { public: CWnd(); CWnd(LPTSTR lpszClassName, LPTSTR lpszWindowName); virtual ~CWnd(); virtual HWND CreateDef(void); // Create the window with default parameters virtual LRESULT WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam ); private: static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam); HWND g_hWnd; //Global window handle for this window HINSTANCE hInst; //Global instance for this window LPTSTR lpszClassName; LPTSTR lpszWindowName; }; </code></pre> <p>P.S. I included all needed header files, everything goes fine except MessageBox</p> <p>This is also a link to the code on <a href="http://ideone.com/ONBbD" rel="nofollow">here</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload