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); 
}

Recommended Answers

All 2 Replies

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.

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

UpdateWindow(hWnd);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.