1。原代码
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
HWND hwnd;
MSG msg;
WNDCLASS wndcls;
wchar_t lpszClassName[] = L"sunxin2006";
wchar_t lpszTitle[] = L"http://www.sunxin.org";
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=NULL;
wndcls.lpszClassName;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
//RegisterClass(&wndcls);
if(!RegisterClass(&wndcls))
{
MessageBeep(0);
return FALSE;
}
//HWND hwnd;
hwnd=CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
0,
0,
600,
400,
NULL,
NULL,
hInstance,
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, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
//wchar_t szChar[20];
char szChar[20];
sprintf_s(szChar,"char code is %d",wParam); //sprintf -> sprintf_s
MessageBox(hwnd,(LPCWSTR)szChar,L"char",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,L"mouse clicked",L"message",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,L"程序员之家",strlen("程序员之家"));
//ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,L"http://www.sunxin.org",strlen("http://www.sunxin.org"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,L"是否真的结束?",L"message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
2。编译正常,运行以下看看?会有什么状况发生?
3。编译正常,不代表程序没有错误,VC2008还需要进一步完善。不知道2010怎么样。有知道的同仁告知一下。谢谢。
1604

被折叠的 条评论
为什么被折叠?



