Windows程序设计(第五版)源代码A(chap07)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

chap07-BlockOut1/*-----------------------------------------BLOKOUT1.C--MouseButtonDemoProgram(c)CharlesPetzold,1998-----------------------------------------*/#includewindows.hLRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,PSTRszCmdLine,intiCmdShow){staticTCHARszAppName[]=TEXT(BlokOut1);HWNDhwnd;MSGmsg;WNDCLASSwndclass;wndclass.style=CS_HREDRAW|CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hInstance=hInstance;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName=NULL;wndclass.lpszClassName=szAppName;if(!RegisterClass(&wndclass)){MessageBox(NULL,TEXT(ProgramrequiresWindowsNT!),szAppName,MB_ICONERROR);return0;}hwnd=CreateWindow(szAppName,TEXT(MouseButtonDemo),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,iCmdShow);UpdateWindow(hwnd);while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;}voidDrawBoxOutline(HWNDhwnd,POINTptBeg,POINTptEnd){HDChdc;hdc=GetDC(hwnd);SetROP2(hdc,R2_NOT);SelectObject(hdc,GetStockObject(NULL_BRUSH));Rectangle(hdc,ptBeg.x,ptBeg.y,ptEnd.x,ptEnd.y);ReleaseDC(hwnd,hdc);}LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam){staticBOOLfBlocking,fValidBox;staticPOINTptBeg,ptEnd,ptBoxBeg,ptBoxEnd;HDChdc;PAINTSTRUCTps;switch(message){caseWM_LBUTTONDOWN:ptBeg.x=ptEnd.x=LOWORD(lParam);ptBeg.y=ptEnd.y=HIWORD(lParam);DrawBoxOutline(hwnd,ptBeg,ptEnd);SetCursor(LoadCursor(NULL,IDC_CROSS));fBlocking=TRUE;return0;caseWM_MOUSEMOVE:if(fBlocking){SetCursor(LoadCursor(NULL,IDC_CROSS));DrawBoxOutline(hwnd,ptBeg,ptEnd);ptEnd.x=LOWORD(lParam);ptEnd.y=HIWORD(lParam);DrawBoxOutline(hwnd,ptBeg,ptEnd);}return0;caseWM_LBUTTONUP:if(fBlocking){DrawBoxOutline(hwnd,ptBeg,ptEnd);ptBoxBeg=ptBeg;ptBoxEnd.x=LOWORD(lParam);ptBoxEnd.y=HIWORD(lParam);SetCursor(LoadCursor(NULL,IDC_ARROW));fBlocking=FALSE;fValidBox=TRUE;InvalidateRect(hwnd,NULL,TRUE);}return0;caseWM_CHAR:if(fBlocking&(wParam=='\x1B'))//i.e.,Escape{DrawBoxOutline(hwnd,ptBeg,ptEnd);SetCursor(LoadCursor(NULL,IDC_ARROW));fBlocking=FALSE;}return0;caseWM_PAINT:hdc=BeginPaint(hwnd,&ps);if(fValidBox){SelectObject(hdc,GetStockObject(BLACK_BRUSH));Rectangle(hdc,ptBoxBeg.x,ptBoxBeg.y,ptBoxEnd.x,ptBoxEnd.y);}if(fBlocking){SetROP2(hdc,R2_NOT);SelectObject(hdc,GetStockObject(NULL_BRUSH));Rectangle(hdc,ptBeg.x,ptBeg.y,ptEnd.x,ptEnd.y);}EndPaint(hwnd,&ps);return0;caseWM_DESTROY:PostQuitMessage(0);return0;}returnDefWindowProc(hwnd,message,wParam,lParam);}chap07-BlokOut2/*---------------------------------------------------BLOKOUT2.C--MouseButton&CaptureDemoProgram(c)CharlesPetzold,1998---------------------------------------------------*/#includewindows.hLRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,PSTRszCmdLine,intiCmdShow){staticTCHARszAppName[]=TEXT(BlokOut2);HWNDhwnd;MSGmsg;WNDCLASSwndclass;wndclass.style=CS_HREDRAW|CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hInstance=hInstance;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName=NULL;wndclass.lpszClassName=szAppName;if(!RegisterClass(&wndclass)){MessageBox(NULL,TEXT(ProgramrequiresWindowsNT!),szAppName,MB_ICONERROR);return0;}hwnd=CreateWindow(szAppName,TEXT(MouseButton&CaptureDemo),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,iCmdShow);UpdateWindow(hwnd);while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;}voidDrawBoxOutline(HWNDhwnd,POINTptBeg,POINTptEnd){HDChdc;hdc=GetDC(hwnd);SetROP2(hdc,R2_NOT);SelectObject(hdc,GetStockObject(NULL_BRUSH));Rectangle(hdc,ptBeg.x,ptBeg.y,ptEnd.x,ptEnd.y);ReleaseDC(hwnd,hdc);}LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam){staticBOOLfBlocking,fValidBox;staticPOINTptBeg,ptEnd,ptBoxBeg,ptBoxEnd;HDChdc;PAINTSTRUCTps;switch(message){caseWM_LBUTTONDOWN:ptBeg.x=ptEnd.x=LOWORD(lParam);ptBeg.y=ptEnd.y=HIWORD(lParam);DrawBoxOutline(hwnd,ptBeg,ptEnd);SetCapture(hwnd);SetCursor(LoadCursor(NULL,IDC_CROSS));fBlocking=TRUE;return0;caseWM_MOUSEMOVE:if(fBlocking){SetCursor(LoadCursor(NULL,IDC_CROSS));DrawBoxOutline(hwnd,ptBeg,ptEnd);ptEnd.x=LOWORD(lParam);ptEnd.y=HIWORD(lParam);DrawBoxOutline(hwnd,ptBeg,ptEnd);}return0;caseWM_LBUTTONUP:if(fBlocking){DrawBoxOutline(hwnd,ptBeg,ptEnd);ptBoxBeg=ptBeg;ptBoxEnd.x=LOWORD(lParam);ptBoxEnd.y=HIWORD(lParam);ReleaseCapture();SetCursor(LoadCursor(NULL,IDC_ARROW));fBlocking=FALSE;fValidBox=TRUE;InvalidateRect(hwnd,NULL,TRUE);}return0;caseWM_CHAR:if(fBlocking&(wParam=='\x1B'))//i.e.,Escape{DrawBoxOutline(hwnd,ptBeg,ptEnd);ReleaseCapture();SetCursor(LoadCur

1 / 38
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功