简体   繁体   中英

Creating a window doesn't work but gives no error messages

I'm trying to create a window, none appear but I don't get an error message anywhere except for the one I put in testing hWnd.

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

#include "entity.h"

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

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc= (WNDPROC)WndProc;
    wcex.cbClsExtra= 0;
    wcex.cbWndExtra= 0;
    wcex.hInstance= hInstance;
    wcex.hIcon= 0;
    wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName= 0;
    wcex.lpszClassName= "Extt";
    wcex.hIconSm= 0;

    if(!RegisterClassEx(&wcex))
    {
        MessageBox(NULL, "FAILED TO REGISTER WINDOW CLASS", "ERROR", MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    HWND hWnd = CreateWindow("WinD", "Chair", WS_OVERLAPPEDWINDOW, 480, 480, 480, 480, NULL, NULL, hInstance, NULL);

    if (hWnd == NULL)
    {
        MessageBox(NULL, "FAILED TO CREATE WINDOW", "ERROR", MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return (int)msg.wParam;
}

I just don't know what to do anymore.

I did everything like the guy said, I've read and re-read the page several times and can not understand why this won't work.

Your classname parameters do not match. If you had used GetLastError() it would have returned 1407, which is:

ERROR_CANNOT_FIND_WND_CLASS
    1407 (0x57F)
    Cannot find window class.

Either change wcex.lpszClassName = "Extt"; to wcex.lpszClassName = "WinD"; or change the first parameter to CreateWindow to "Extt" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM