OWNDRAW.docx

上传人:b****6 文档编号:6836476 上传时间:2023-01-11 格式:DOCX 页数:8 大小:16.30KB
下载 相关 举报
OWNDRAW.docx_第1页
第1页 / 共8页
OWNDRAW.docx_第2页
第2页 / 共8页
OWNDRAW.docx_第3页
第3页 / 共8页
OWNDRAW.docx_第4页
第4页 / 共8页
OWNDRAW.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

OWNDRAW.docx

《OWNDRAW.docx》由会员分享,可在线阅读,更多相关《OWNDRAW.docx(8页珍藏版)》请在冰豆网上搜索。

OWNDRAW.docx

OWNDRAW

/*---------------------------------------------

OWNDRAW.C--Owner-DrawButtonDemoProgram

(c)CharlesPetzold,1998

---------------------------------------------*/

#include

#defineID_SMALLER1

#defineID_LARGER2

#defineBTN_WIDTH(8*cxChar)

#defineBTN_HEIGHT(4*cyChar)

LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);

HINSTANCEhInst;

intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,

PSTRszCmdLine,intiCmdShow)

{

staticTCHARszAppName[]=TEXT("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,

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;

}

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("button"),TEXT(""),

WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,

0,0,BTN_WIDTH,BTN_HEIGHT,

hwnd,(HMENU)ID_LARGER,hInst,NULL);

return0;

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,

cyClient/2-BTN_HEIGHT/2,

BTN_WIDTH,BTN_HEIGHT,TRUE);

return0;

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;

break;

}

MoveWindow(hwnd,rc.left,rc.top,rc.right-rc.left,

rc.bottom-rc.top,TRUE);

return0;

caseWM_DRAWITEM:

pdis=(LPDRAWITEMSTRUCT)lParam;

//Fillareawithwhiteandframeitblack

FillRect(pdis->hDC,&pdis->rcItem,

(HBRUSH)GetStockObject(WHITE_BRUSH));

FrameRect(pdis->hDC,&pdis->rcItem,

(HBRUSH)GetStockObject(BLACK_BRUSH));

//Drawinwardandoutwardblacktriangles

cx=pdis->rcItem.right-pdis->rcItem.left;

cy=pdis->rcItem.bottom-pdis->rcItem.top;

switch(pdis->CtlID)

{

caseID_SMALLER:

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;

Triangle(pdis->hDC,pt);

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].x=4*cx/8;pt[2].y=5*cy/8;

Triangle(pdis->hDC,pt);

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=4*cy/8;

Triangle(pdis->hDC,pt);

break;

caseID_LARGER:

pt[0].x=5*cx/8;pt[0].y=3*cy/8;

pt[1].x=3*cx/8;pt[1].y=3*cy/8;

pt[2].x=4*cx/8;pt[2].y=1*cy/8;

Triangle(pdis->hDC,pt);

pt[0].x=5*cx/8;pt[0].y=5*cy/8;

pt[1].x=5*cx/8;pt[1].y=3*cy/8;

pt[2].x=7*cx/8;pt[2].y=4*cy/8;

Triangle(pdis->hDC,pt);

pt[0].x=3*cx/8;pt[0].y=5*cy/8;

pt[1].x=5*cx/8;pt[1].y=5*cy/8;

pt[2].x=4*cx/8;pt[2].y=7*cy/8;

Triangle(pdis->hDC,pt);

pt[0].x=3*cx/8;pt[0].y=3*cy/8;

pt[1].x=3*cx/8;pt[1].y=5*cy/8;

pt[2].x=1*cx/8;pt[2].y=4*cy/8;

Triangle(pdis->hDC,pt);

break;

}

//Inverttherectangleifthebuttonisselected

if(pdis->itemState&ODS_SELECTED)

InvertRect(pdis->hDC,&pdis->rcItem);

//Drawafocusrectangleifthebuttonhasthefocus

if(pdis->itemState&ODS_FOCUS)

{

pdis->rcItem.left+=cx/16;

pdis->rcItem.top+=cy/16;

pdis->rcItem.right-=cx/16;

pdis->rcItem.bottom-=cy/16;

DrawFocusRect(pdis->hDC,&pdis->rcItem);

}

return0;

caseWM_DESTROY:

PostQuitMessage(0);

return0;

}

returnDefWindowProc(hwnd,message,wParam,lParam);

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1