#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.hIcon = LoadIcon (NULL,IDI_ERROR);
wndcls.hCursor = LoadCursor (NULL,IDC_CROSS);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = "wenxin";
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.lpszMenuName = NULL;
RegisterClass(&wndcls); //注册窗口类
HWND hwnd;
hwnd = CreateWindow ("wenxin","sun", 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);
}//endof while
return 0;
} //endof winMain()
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf (szChar , "char is %d",wParam);
MessageBox(hwnd,szChar,"wenxin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","wenxin",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,"是否真的结束?","要退出第一个写的程序吗?",MB_YESNO))
{
DestroyWindow(hwnd);
}//ENDOF IF
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg, wParam, lParam);
}//endof swith()
return 0;
}//end of WinSunProc()
红色那里好象有错误。