OWNDRAW文档格式.docx
- 文档编号:19857987
- 上传时间:2023-01-11
- 格式:DOCX
- 页数:8
- 大小:16.30KB
OWNDRAW文档格式.docx
《OWNDRAW文档格式.docx》由会员分享,可在线阅读,更多相关《OWNDRAW文档格式.docx(8页珍藏版)》请在冰豆网上搜索。
OwnDraw"
);
MSGmsg;
HWNDhwnd;
WNDCLASSwndclass;
hInst=hInstance;
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,TEXT("
Owner-DrawButtonDemo"
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&
msg,NULL,0,0))
TranslateMessage(&
msg);
DispatchMessage(&
returnmsg.wParam;
}
voidTriangle(HDChdc,POINTpt[])
SelectObject(hdc,GetStockObject(BLACK_BRUSH));
Polygon(hdc,pt,3);
SelectObject(hdc,GetStockObject(WHITE_BRUSH));
LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam)
staticHWNDhwndSmaller,hwndLarger;
staticintcxClient,cyClient,cxChar,cyChar;
intcx,cy;
LPDRAWITEMSTRUCTpdis;
POINTpt[3];
RECTrc;
switch(message)
caseWM_CREATE:
cxChar=LOWORD(GetDialogBaseUnits());
cyChar=HIWORD(GetDialogBaseUnits());
//Createtheowner-drawpushbuttons
hwndSmaller=CreateWindow(TEXT("
button"
),TEXT("
WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
0,0,BTN_WIDTH,BTN_HEIGHT,
hwnd,(HMENU)ID_SMALLER,hInst,NULL);
hwndLarger=CreateWindow(TEXT("
hwnd,(HMENU)ID_LARGER,hInst,NULL);
caseWM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
//Movethebuttonstothenewcenter
MoveWindow(hwndSmaller,cxClient/2-3*BTN_WIDTH/2,
cyClient/2-BTN_HEIGHT/2,
BTN_WIDTH,BTN_HEIGHT,TRUE);
MoveWindow(hwndLarger,cxClient/2+BTN_WIDTH/2,
caseWM_COMMAND:
GetWindowRect(hwnd,&
rc);
//Makethewindow10%smallerorlarger
switch(wParam)
caseID_SMALLER:
rc.left+=cxClient/20;
rc.right-=cxClient/20;
rc.top+=cyClient/20;
rc.bottom-=cyClient/20;
break;
caseID_LARGER:
rc.left-=cxClient/20;
rc.right+=cxClient/20;
rc.top-=cyClient/20;
rc.bottom+=cyClient/20;
MoveWindow(hwnd,rc.left,rc.top,rc.right-rc.left,
rc.bottom-rc.top,TRUE);
caseWM_DRAWITEM:
pdis=(LPDRAWITEMSTRUCT)lParam;
//Fillareawithwhiteandframeitblack
FillRect(pdis->
hDC,&
pdis->
rcItem,
(HBRUSH)GetStockObject(WHITE_BRUSH));
FrameRect(pdis->
(HBRUSH)GetStockObject(BLACK_BRUSH));
//Drawinwardandoutwardblacktriangles
cx=pdis->
rcItem.right-pdis->
rcItem.left;
cy=pdis->
rcItem.bottom-pdis->
rcItem.top;
switch(pdis->
CtlID)
pt[0].x=3*cx/8;
pt[0].y=1*cy/8;
pt[1].x=5*cx/8;
pt[1].y=1*cy/8;
pt[2].x=4*cx/8;
pt[2].y=3*cy/8;
Triangle(pdis->
hDC,pt);
pt[0].x=7*cx/8;
pt[0].y=3*cy/8;
pt[1].x=7*cx/8;
pt[1].y=5*cy/8;
pt[2].x=5*cx/8;
pt[2].y=4*cy/8;
pt[0].x=5*cx/8;
pt[0].y=7*cy/8;
pt[1].x=3*cx/8;
pt[1].y=7*cy/8;
pt[2].y=5*cy/8;
pt[0].x=1*cx/8;
pt[0].y=5*cy/8;
pt[1].x=1*cx/8;
pt[1].y=3*cy/8;
pt[2].x=3*cx/8;
pt[2].y=1*cy/8;
pt[2].x=7*cx/8;
pt[2].y=7*cy/8;
pt[2].x=1*cx/8;
//Inverttherectangleifthebuttonisselected
if(pdis->
itemState&
ODS_SELECTED)
InvertRect(pdis->
rcItem);
//Drawafocusrectangleifthebuttonhasthefocus
ODS_FOCUS)
pdis->
rcItem.left+=cx/16;
rcItem.top+=cy/16;
rcItem.right-=cx/16;
rcItem.bottom-=cy/16;
DrawFocusRect(pdis->
caseWM_DESTROY:
PostQuitMessage(0);
returnDefWindowProc(hwnd,message,wParam,lParam);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- OWNDRAW
![提示](https://static.bdocx.com/images/bang_tan.gif)