C++ 窗口不显示';不出现

C++ 窗口不显示';不出现,c++,windows,window,C++,Windows,Window,我写了一个创建窗口的小程序。我以前做过这个程序,但现在我试着自己回忆所有的事情。 当我写完程序后,窗口不会出现,当我将代码与我正在学习的书进行比较时,也是如此。我错过了什么/做错了什么 #include <windows.h> #include <WindowsX.h> LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI Win

我写了一个创建窗口的小程序。我以前做过这个程序,但现在我试着自己回忆所有的事情。 当我写完程序后,窗口不会出现,当我将代码与我正在学习的书进行比较时,也是如此。我错过了什么/做错了什么

#include <windows.h>
#include <WindowsX.h>


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
    HWND hWnd;

    // information for the window class
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));


    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
     wc.lpfnWndProc = WindowProc;
     wc.hInstance = hInstance;
     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
     wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
     wc.lpszClassName = "WindowClass1";

     RegisterClassEx(&wc);

     // Create Window
     hWnd = CreateWindowEx( NULL,
                            "WindowClass",
                            "My Program",
                            WS_OVERLAPPEDWINDOW,
                            100,
                            100,
                            600,
                            480,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);


     ShowWindow(hWnd, SW_SHOWDEFAULT);



     MSG msg;

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


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        } break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}
#包括
#包括
LRESULT回调WindowProc(HWND-HWND,UINT消息,WPARAM-WPARAM,LPARAM-LPARAM);
int WINAPI WinMain(HINSTANCE HINSTANCE、HINSTANCE HPPreInstance、LPSTR lpCmdLine、int nCmdShow)
{
HWND-HWND;
//窗口类的信息
WNDCLASSEX wc;
零内存(&wc,sizeof(WNDCLASSEX));
wc.cbSize=sizeof(WNDCLASSEX);
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=WindowProc;
wc.hInstance=hInstance;
wc.hCursor=LoadCursor(空,IDC_箭头);
wc.hbrBackground=(HBRUSH)彩色窗口;
wc.lpszClassName=“WindowClass1”;
注册类别(&wc);
//创建窗口
hWnd=CreateWindowEx(空,
“窗口类”,
“我的程序”,
WS_重叠窗口,
100,
100,
600,
480,
无效的
无效的
hInstance,
无效);
显示窗口(hWnd、SW_显示默认值);
味精;
while(GetMessage(&msg,NULL,0,0))
{
翻译信息(&msg);
发送消息(&msg);
}
返回msg.wParam;
}
LRESULT回调WindowProc(HWND-HWND,UINT消息,WPARAM-WPARAM,LPARAM-LPARAM)
{
开关(信息)
{
案例WM_销毁:
{
PostQuitMessage(0);
返回0;
}中断;
}
返回DefWindowProc(hWnd、message、wParam、lParam);
}
比较类名:

wc.lpszClassName=“WindowClass1”

hWnd=CreateWindowEx(空,“WindowClass”


找到这些错误的最好方法是检查每个API的返回代码。< /P>当你运行它时,到底发生了什么?为什么不只是定义MyOrthCyraseNo.t(“WiDOWCHIL1”)?@ Ajay:因为OP使用C++, CordSchar * CaseNe= =“WiDOWCHILL1”;< /C> >更合适。为什么不>代码> const Tchar * CaseNox=?:)