0

I have Visual Studio 2012 Ultimate. I tried creating a Win32 Program and there are no debugging errors. However, when I debug it, the window I am creating should be shown on screen, but there is no window. All I see is my code. Why would this happen?

#include <Windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prev, PSTR cmd, int show)
{
    HWND hWnd; 
    WNDCLASS wc; 

    wc.style            = CS_HREDRAW | CS_VREDRAW; 
    wc.lpszClassName    = "MyWindow"; 
    wc.hbrBackground    = (HBRUSH)COLOR_BACKGROUND; 
    wc.hCursor          = LoadCursor(hInstance, IDC_ARROW); 
    wc.hInstance        = hInstance; 
    wc.lpfnWndProc      = WndProc; 

    RegisterClass(&wc); 

    hWnd = CreateWindow("MyWindow", "My First Window", WS_OVERLAPPEDWINDOW, 300, 300, 480, 600, NULL, NULL, hInstance, NULL); 

    ShowWindow(hWnd, show); 

    MSG msg; 

    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }

    return msg.wParam; 
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0); 
        return 0; 
        break; 
    case WM_QUIT: 
        DestroyWindow(hWnd); 
        return 0; 
        break; 
    }

    return DefWindowProc(hWnd, msg, wParam, lParam); 
}
3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by nullptr
0

You should clear out the WNDCLASS wc structure to empty with this:

ZeroMemory(&wcex, sizeof(WNDCLASSEX));

Try using ShowWindow(hWnd, SW_SHOW) with SW_SHOW as a second argument.

0

Initialize WNDCLASS as already suggested and after your call to ShowWindow(...), call

UpdateWindow(hWnd);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.