资源描述:
《一个简单的剪贴板浏览器》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一个简单的剪贴板浏览器剪贴板浏览器不一定要像Windows所提供的那样完善,例如,剪贴板浏览器可以只显示一种剪贴板数据格式。程序12-2中所示的CLIPVIEW程序是一种只能显示CF_TEXT格式的剪贴板浏览器。程序12-2CLIPVIEWCLIPVIEW.C#includeLRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance
2、,PSTRszCmdLine,intiCmdShow){staticTCHARszAppName[]=TEXT("ClipView");HWNDhwnd;MSGmsg;WNDCLASSwndclass;wndclass.style=CS_HREDRAW
3、CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hInstance=hInstance;wndclass.hIcon=
4、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("Thisprogr
5、amrequiresWindowsNT!"),szAppName,MB_ICONERROR);return0;}hwnd=CreateWindow(szAppName,TEXT("SimpleClipboardViewer(TextOnly)"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,iCmdShow);Upd
6、ateWindow(hwnd);while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;}LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam){staticHWNDhwndNextViewer;HGLOBALhGlobal;HDChdc;PTSTRpGlobal;PAINTSTRUCT
7、ps;RECTrect;switch(message){caseWM_CREATE:hwndNextViewer=SetClipboardViewer(hwnd);return0;caseWM_CHANGECBCHAIN:if((HWND)wParam==hwndNextViewer)hwndNextViewer=(HWND)lParam;elseif(hwndNextViewer)SendMessage(hwndNextViewer,message,wParam,lParam);return0;case
8、WM_DRAWCLIPBOARD:if(hwndNextViewer)SendMessage(hwndNextViewer,message,wParam,lParam);InvalidateRect(hwnd,NULL,TRUE);return0;caseWM_PAINT:hdc=BeginPaint(hwnd,&ps);GetClientRect(hwnd,&rect);OpenClipboard(hwnd);#ifdefUNICODEhGlobal=GetClipboardData(CF_UNICOD
9、ETEXT);#elsehGlobal=GetClipboardData(CF_TEXT);#endifif(hGlobal!=NULL){pGlobal=(PTSTR)GlobalLock(hGlobal);DrawText(hdc,pGlobal,-1,&rect,DT_EXPANDTABS);GlobalUnlock(hGlobal);}CloseClipboard();EndPaint(hwnd,&ps);return