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

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

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

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

资源描述

chap13-DevCaps2/*------------------------------------------------------------------DEVCAPS2.C--DisplaysDeviceCapabilityInformation(Version2)(c)CharlesPetzold,1998------------------------------------------------------------------*/#includewindows.h#includeresource.hLRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);voidDoBasicInfo(HDC,HDC,int,int);voidDoOtherInfo(HDC,HDC,int,int);voidDoBitCodedCaps(HDC,HDC,int,int,int);typedefstruct{intiMask;TCHAR*szDesc;}BITS;#defineIDM_DEVMODE1000intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,PSTRszCmdLine,intiCmdShow){staticTCHARszAppName[]=TEXT(DevCaps2);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=szAppName;wndclass.lpszClassName=szAppName;if(!RegisterClass(&wndclass)){MessageBox(NULL,TEXT(ThisprogramrequiresWindowsNT!),szAppName,MB_ICONERROR);return0;}hwnd=CreateWindow(szAppName,NULL,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;}LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam){staticTCHARszDevice[32],szWindowText[64];staticintcxChar,cyChar,nCurrentDevice=IDM_SCREEN,nCurrentInfo=IDM_BASIC;staticDWORDdwNeeded,dwReturned;staticPRINTER_INFO_4*pinfo4;staticPRINTER_INFO_5*pinfo5;DWORDi;HDChdc,hdcInfo;HMENUhMenu;HANDLEhPrint;PAINTSTRUCTps;TEXTMETRICtm;switch(message){caseWM_CREATE:hdc=GetDC(hwnd);SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));GetTextMetrics(hdc,&tm);cxChar=tm.tmAveCharWidth;cyChar=tm.tmHeight+tm.tmExternalLeading;ReleaseDC(hwnd,hdc);//fallthroughcaseWM_SETTINGCHANGE:hMenu=GetSubMenu(GetMenu(hwnd),0);while(GetMenuItemCount(hMenu)1)DeleteMenu(hMenu,1,MF_BYPOSITION);//Getalistofalllocalandremoteprinters////First,findouthowlargeanarrayweneed;this//callwillfail,leavingtherequiredsizeindwNeeded////Next,allocatespacefortheinfoarrayandfillit////Puttheprinternamesonthemenu.if(GetVersion()&0x80000000)//Windows98{EnumPrinters(PRINTER_ENUM_LOCAL,NULL,5,NULL,0,&dwNeeded,&dwReturned);pinfo5=malloc(dwNeeded);EnumPrinters(PRINTER_ENUM_LOCAL,NULL,5,(PBYTE)pinfo5,dwNeeded,&dwNeeded,&dwReturned);for(i=0;idwReturned;i++){AppendMenu(hMenu,(i+1)%16?0:MF_MENUBARBREAK,i+1,pinfo5[i].pPrinterName);}free(pinfo5);}else//WindowsNT{EnumPrinters(PRINTER_ENUM_LOCAL,NULL,4,NULL,0,&dwNeeded,&dwReturned);pinfo4=malloc(dwNeeded);EnumPrinters(PRINTER_ENUM_LOCAL,NULL,4,(PBYTE)pinfo4,dwNeeded,&dwNeeded,&dwReturned);for(i=0;idwReturned;i++){AppendMenu(hMenu,(i+1)%16?0:MF_MENUBARBREAK,i+1,pinfo4[i].pPrinterName);}free(pinfo4);}AppendMenu(hMenu,MF_SEPARATOR,0,NULL);AppendMenu(hMenu,0,IDM_DEVMODE,TEXT(Properties));wParam=IDM_SCREEN;//fallthroughcaseWM_COMMAND:hMenu=GetMenu(hwnd);if(LOWORD(wParam)==IDM_SCREEN||//IDM_SCREEN&PrintersLOWORD(wParam)IDM_DEVMODE){CheckMenuItem(hMenu,nCurrentDevice,MF_UNCHECKED);nCurrentDevice=LOWORD(wParam);CheckMenuItem(hMenu,nCurrentDevice,MF_CHECKED);}elseif(LOWORD(wParam)==IDM_DEVMODE)//Propertiesselection{GetMenuString(hMenu,nCurrentDevice,szDevice,sizeof(szDevice)/sizeof(TCHAR),MF_BYCOMMAND);if(OpenPrinter(szDevice,&hPrint,NULL)){PrinterProperties(hwnd,hPrint);ClosePrinter(hPrint);}}else//infomenuitems{CheckMenuItem(hMenu,nCurrentInfo,MF_UNCHECKED);nCurrentInfo=LOWORD(wParam);CheckMenuItem(hMenu,nCurrentInfo,MF_CHECKED);}InvalidateRect(hwnd,NULL,TRUE);return0;caseWM_INITMENUPOPUP:if(lParam==0)EnableMenuItem(GetMenu(hwnd),IDM_DEVMODE,nCurrentDevice==IDM_SCREEN?MF_GRAYED:MF_ENABLED);return0;caseWM_PAINT:lstrcpy(szWindowText,TEXT(DeviceCapabilities:));if(nCurrentDevice==IDM_SCREEN){lstrcpy(szDevice,TEXT(DISPLAY));hdcInfo=CreateIC(szDevice,NULL,NULL,NULL);}else{hMenu=GetMenu(hwnd);GetMenuString(hMenu,nCurrentDevice,szDevice,sizeof(szDevice),MF_BYCOMMAND);hdcInfo=CreateIC(NULL,szDevice,NULL,NULL);}lstrcat(szWindowText,szDevice);SetWindowText(hwnd,szWindowText);hdc=BeginPaint(hwnd,&ps);SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));if(hdcInfo){switch(nCurrentInfo){caseIDM_BASIC:DoBasicInfo(hdc,hdcInfo,cxChar,cyChar);break;caseIDM_OTHER:DoOtherInfo(hdc,hdcInfo,cxChar,cyChar);break;caseIDM_CURVE:caseIDM_LINE:caseIDM_POLY:caseIDM_TEXT:DoBitCodedCaps(hdc,hdcInfo,cxChar,cyChar,nCurrentInfo-IDM_CURVE);break;}DeleteDC(hdcInfo);}EndPaint(hwnd,&ps);return0;caseWM_DESTROY:PostQuitMessage(0);return0;}returnDefWindowProc(hwnd,message,wParam,lParam);}voidDoBasicInfo(HDChdc,HDChdcInfo,intcxChar,intcyChar){staticstruct{intnIndex;TCHAR*szDesc;}info[]={HORZSIZE,TEXT(HORZSIZEWidthinmillimeters:),VERTSIZE,TEXT(VERTSIZEHeightinmillimeters:),HORZRES,TEXT(HORZRESWidthinpixels:),VERTRES,TEXT(VERTRESHeightinrasterlines:),BITSPIXEL,TEXT(BITSPIXELColorbitsperpixel:),P

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

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

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

×
保存成功