LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char szclassname[]="Mainclass";
WNDCLASSEX wndclass;
wndclass.cbSize=sizeof(wndclass);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=MainWndProc;
wndclass.cbWndExtra=NULL;
wndclass.cbClsExtra=NULL;
wndclass.hbrBackground=(HBRUSH)::GetStockObject(WHITE_BRUSH);
wndclass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=::LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szclassname;
::RegisterClassEx(&wndclass);
HWND hwnd =::CreateWindowEx(0,szclassname,"我的第一个程序",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
if(hwnd==NULL)
{
::MessageBox(NULL,"创建窗口出错","error",MB_OK);
return -1;
}
::ShowWindow(hwnd,nCmdShow);
::UpdateWindow(hwnd);
MSG msg;
while(::GetMessage(&msg,NULL,0,0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return 0;}
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
char szText[]="组简单的程序!";
switch(message)
{
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc=::BeginPaint(hwnd,&ps);
::TextOut(hdc,10,10,szText,strlen(szText));
::EndPaint(hwnd,&ps);
return 0;
}
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProc(hwnd,message,wParam ,lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char szclassname[]="Mainclass";
WNDCLASSEX wndclass;
wndclass.cbSize=sizeof(wndclass);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=MainWndProc;
wndclass.cbWndExtra=NULL;
wndclass.cbClsExtra=NULL;
wndclass.hbrBackground=(HBRUSH)::GetStockObject(WHITE_BRUSH);
wndclass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=::LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szclassname;
::RegisterClassEx(&wndclass);
HWND hwnd =::CreateWindowEx(0,szclassname,"我的第一个程序",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
if(hwnd==NULL)
{
::MessageBox(NULL,"创建窗口出错","error",MB_OK);
return -1;
}
::ShowWindow(hwnd,nCmdShow);
::UpdateWindow(hwnd);
MSG msg;
while(::GetMessage(&msg,NULL,0,0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return 0;}
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
char szText[]="组简单的程序!";
switch(message)
{
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc=::BeginPaint(hwnd,&ps);
::TextOut(hdc,10,10,szText,strlen(szText));
::EndPaint(hwnd,&ps);
return 0;
}
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProc(hwnd,message,wParam ,lParam);
}
{
::MessageBox(NULL,"创建窗口出错","error",MB_OK);
return -1;
} 直接hwnd =NULL了,不知道为什么返回不了窗口的句柄
WNDCLASSEX wndclass={0};