高分请教重画按钮的具体步骤,最好详细点。

Toogo 2004-08-11 08:36:06
内容如题
...全文
123 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
palluo 2004-08-12
  • 打赏
  • 举报
回复
我的总结是:

1,设置BS_OWNERDRAW 属性 
2,重载 DrawItem 函数,并在里面写入画图的代码。
3,可以重载鼠标的一些消息处理函数,来动画你的按钮。

网上有很多实例,不防参考一下。不管怎样,一定是按上面三个步骤来的。
无敌魔仙 2004-08-12
  • 打赏
  • 举报
回复
Using Owner Drawn Buttons
The parent window of an owner-drawn button typically responds to at least three messages for the button:

WM_INITDIALOG
WM_COMMAND
WM_DRAWITEM
When you must paint an owner-drawn button, the system sends the parent window a WM_DRAWITEM message whose lParam parameter is a pointer to a DRAWITEMSTRUCT structure. Use this structure with all owner-drawn controls to provide the application with the information it requires to paint the control. The itemAction and itemState members of the DRAWITEMSTRUCT structure define how to paint an owner-drawn button.

The following example shows how to process WM_INITDIALOG, WM_DRAWITEM, and WM_COMMAND messages for owner-drawn buttons. This example demonstrates how to draw one of two bitmaps for a control, depending on whether the control is selected. You would typically use the wParam parameter of the WM_DRAWITEM message to identify the control; in this example, only one control is assumed.

Hide Example

BOOL CALLBACK OwnDrawProc(HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam)
{
HDC hdcMem;
LPDRAWITEMSTRUCT lpdis;

switch (message)
{
case WM_INITDIALOG:

// hinst, hbm1 and hbm2 are defined globally.
hbm1 = LoadBitmap((HANDLE) hinst, "OwnBit1");
hbm2 = LoadBitmap((HANDLE) hinst, "OwnBit2");
return TRUE;

case WM_DRAWITEM:
lpdis = (LPDRAWITEMSTRUCT) lParam;
hdcMem = CreateCompatibleDC(lpdis->hDC);

if (lpdis->itemState & ODS_SELECTED) // if selected
SelectObject(hdcMem, hbm2);
else
SelectObject(hdcMem, hbm1);

// Destination
StretchBlt(
lpdis->hDC, // destination DC
lpdis->rcItem.left, // x upper left
lpdis->rcItem.top, // y upper left

// The next two lines specify the width and
// height.
lpdis->rcItem.right - lpdis->rcItem.left,
lpdis->rcItem.bottom - lpdis->rcItem.top,
hdcMem, // source device context
0, 0, // x and y upper left
32, // source bitmap width
32, // source bitmap height
SRCCOPY); // raster operation

DeleteDC(hdcMem);
return TRUE;

case WM_COMMAND:
if (wParam == IDOK
|| wParam == IDCANCEL)
{
EndDialog(hDlg, TRUE);
return TRUE;
}
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
case IDC_OWNERDRAW:

// application-defined processing

break;
}
}
break;

case WM_DESTROY:
DeleteObject(hbm1); // delete bitmaps
DeleteObject(hbm2);

break;

}
return FALSE;
UNREFERENCED_PARAMETER(lParam);
}
huwei001982 2004-08-12
  • 打赏
  • 举报
回复
就是重载 DrawItem函数, 另外必须设置 BS_OWNERDRAW
lixiaosan 2004-08-12
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc/?id=551
Kudeet 2004-08-11
  • 打赏
  • 举报
回复
这里有n多的按钮,下几个去看看
http://www.vckbase.com/english/code/buttonctrl/
flyelf 2004-08-11
  • 打赏
  • 举报
回复
到网上下载CButtonST的源代码研究研究
holyeagle 2004-08-11
  • 打赏
  • 举报
回复
是指Button的绘制过程?没见过,只是在drawitem里面自己画过。就是算大小,画边框,添背景颜色,字体。

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧