简体   繁体   English

试图学习winapi。 制作了第一个程序,该程序必须显示一个窗口。 CMD显示但没有窗口

[英]Trying to learn winapi. made a first program which has to show me a window. CMD shows but there is no window

#include<windows.h>

LPSTR NazwaKlasy = "Klasa Okienka";
MSG Komunikat;

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

int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASSEX wc;

wc.cbSize = sizeof( WNDCLASSEX );
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = NazwaKlasy;
wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );

//tutaj kłądż okienka
HWND hwnd;
hwnd = CreateWindowEx ( WS_EX_CLIENTEDGE,NazwaKlasy,"Okienko",WS_EX_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,400,400,NULL,NULL,hInstance,NULL);

//koniec obszaru okienek

ShowWindow( hwnd, nShowCmd ); // Pokaż okienko...
UpdateWindow( hwnd );

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

return Komunikat.wParam;
}
    LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
 case WM_CLOSE:
        DestroyWindow( hwnd );
     break;

 case WM_DESTROY:
        PostQuitMessage( 0 );
     break;

    default:
        return DefWindowProc( hwnd, msg, wParam, lParam );
}

return 0;
}

the editor shows no errors and runs the program without any problems but there are no signs of the window im not very experienced at programming so its most probably a stupid error which i cant just find but everyone has to start somewhere 编辑器没有显示任何错误,并且运行程序没有任何问题,但是没有任何窗口的迹象表明我不是非常有经验的编程人员,因此它很可能是一个愚蠢的错误,我无法找到,但是每个人都必须从某个地方开始
i think i formated the post correctly 我认为我正确格式化了帖子

You're not registering the window class. 您没有注册窗口类。 You fill out the WNDCLASSEX structure ok, but you neglect to call RegisterClassEx to actually register it. 好的,您填写了WNDCLASSEX结构,但是您忽略了调用RegisterClassEx进行实际注册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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