#include <windows.h> #include <stdio.h> #include <TCHAR.h> #include <string.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(WHITE_BRUSH); wndcls.hIcon = LoadIcon (NULL,IDI_ERROR); wndcls.hCursor = LoadCursor (NULL,IDC_CROSS); wndcls.hInstance = hInstance; wndcls.lpfnWndProc = WinSunProc; //这个是什么函数?自己写的吗?
wndcls.lpszClassName = _T("cj"); wndcls.style = CS_HREDRAW | CS_VREDRAW; wndcls.lpszMenuName = NULL;
RegisterClass(&wndcls); //注册窗口类
HWND hwnd; hwnd = CreateWindow (_T("cj"),_T("cj"), 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,_T(""),_T("wenxin"),0); break; case WM_LBUTTONDOWN: MessageBox(hwnd,_T("mouse clicked"),_T("wenxin"),0); HDC hdc; hdc = GetDC(hwnd); TextOut (hdc,0,50,_T("like you"),strlen("like you")); ReleaseDC (hwnd,hdc); break; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint(hwnd,&ps); TextOut(hDC,0, 0, _T("我的第一个程序"),lstrlen(_T("我的第一个程序"))); EndPaint(hwnd,&ps); break; case WM_CLOSE: if(IDYES == MessageBox(hwnd,_T("是否真的结束?"),_T("要退出第一个写的程序吗?"),MB_YESNO)) { DestroyWindow(hwnd); }//ENDOF IF
break; case WM_DESTROY: PostQuitMessage(0);
break; default: return DefWindowProc(hwnd,uMsg, wParam, lParam); }//endof swith()
return 0; }
|