重温 孙鑫 VC++ 笔记

来源:互联网 发布:mac修改管理员名字 编辑:程序博客网 时间:2024/06/04 19:28
#include <afxwin.h>#define  WINDOWNAME "ryan2013"LRESULT CALLBACK WndRyanProc( HWND, UINT, WPARAM, LPARAM );ATOM MyRegisterClass( HINSTANCE hInstance ){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=WndRyanProc;wndcls.lpszClassName = WINDOWNAME;wndcls.lpszMenuName=NULL;wndcls.style=CS_HREDRAW | CS_VREDRAW;return RegisterClass(&wndcls);}BOOL InitInstance( HINSTANCE hInstance, int nCmdShow ){HWND hWnd;HINSTANCE hInst = hInstance;hWnd = CreateWindow(WINDOWNAME, "test",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);if ( !hWnd ){return FALSE;}ShowWindow( hWnd, SW_SHOWNORMAL );UpdateWindow( hWnd );return TRUE;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){UNREFERENCED_PARAMETER(hPrevInstance);UNREFERENCED_PARAMETER(lpCmdLine);MyRegisterClass(hInstance);InitInstance(hInstance,nShowCmd);MSG msg;while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}return 0;}LRESULT CALLBACK WndRyanProc(HWND hwnd,      // handle to windowUINT uMsg,      // message identifierWPARAM wParam,  // first message parameterLPARAM lParam   // second message parameter){switch(uMsg){case WM_CHAR:char szChar[20];sprintf_s(szChar,"char is %d",wParam);MessageBox(hwnd,szChar,"weixin",0);break;case WM_LBUTTONDOWN:MessageBox(hwnd,"mouse clicked","weixin",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,"是否真的结束?","weixin",MB_YESNO)){DestroyWindow(hwnd);}break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hwnd,uMsg,wParam,lParam);}return 0;}