孙鑫视频第一节程序不运行。。。
根据视频编的,也没错误也没warning,但是不弹出窗口啊。。。
谢谢
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg, WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszMenuName="LeiZhen";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("LeiZhen","第一次作业",WS_OVERLAPPEDWINDOW,0,
0,600,400,NULL,NULL,hPrevInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg, WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_CHAR:
char s[20];
sprintf(s,"char is %d",wParam);
MessageBox(hwnd,s,"nihao",MB_OK);
break;
case WM_LBUTTONDBLCLK:
MessageBox(hwnd,"mouse clicked","hehe",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"计算机编程语言",strlen("计算机编程语言"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc=BeginPaint(hwnd,&ps);
TextOut(hDc,0,0,"计算机编程语言",strlen("计算机编程语言"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的关闭","aa",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}