win32程序
#include <windows.h> #include <stdio.h> #include <tchar.h> LRESULT CALLBACK WinYisProc(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,(LPCWSTR)IDI_ERROR); wndcls.hInstance = hInstance; wndcls.lpfnWndProc=WinYisProc; wndcls.lpszClassName=_T("h"); wndcls.lpszMenuName=NULL; wndcls.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(&wndcls); HWND hwnd; hwnd=CreateWindow(_T("h"),_T("tjjjj"),WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg; while( GetMessage(&msg,hwnd,0,0) ) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WinYisProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { case WM_CHAR: char szChar[20]; sprintf(szChar,"char is %d",wParam); MessageBox(hwnd,(LPCWSTR)szChar,_T("yis"),0); break; case WM_LBUTTONDOWN: MessageBox(hwnd, _T("mouse clicked"), _T("message"), 0); HDC hdc; hdc = GetDC(hwnd); TextOut(hdc, 0, 50, _T("我是个快乐的青年"), strlen("我是个快乐的青年")); break; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC=BeginPaint(hwnd,&ps); TextOut(hDC,0,0,_T("yisyisyis"),strlen("yisyisyis")); EndPaint(hwnd,&ps); break; case WM_CLOSE: if(IDYES==MessageBox(hwnd,(LPCWSTR)"是否真的结束?",(LPCWSTR)"yis",MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。