请教一个问题,如何在一个图片上画一个按钮

zyx040404 2019-10-21 09:35:31
first, create a button via CreateWindow(WC_BUTTON, ...)
second, draw a image via StretchDIBits(hdc, x, ...), the image memory is gotten with a camera
then, I want to draw the button created above on the image
I try to use ShowWindow, it will send a message to windows to draw the button
so ShowWindow and StretchDIBits maybe be draw button first, then draw image, or draw image first, then draw button
it's not what I want to do. I want to draw image first, then draw button immediately. Or the button is covered by the image.
...全文
88 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2019-11-16
  • 打赏
  • 举报
回复
下面是一个 透明 按钮
void CMyButton::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rc;
GetClientRect(rc);
MapWindowPoints(GetParent(),rc);
dc.SetBrushOrg(-rc.left,-rc.top);
GetClientRect(rc);
dc.FillRect(&rc,m_brushPat);
//
dc.SetBkMode(TRANSPARENT);
if(m_bHover) dc.SetTextColor(RGB(255,0,0));// red
else dc.SetTextColor(RGB(0,0,0));
dc.TextOut(45,6,"透明按钮");
// Do not call CButton::OnPaint() for painting messages
}

BOOL CMyButton::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
return CButton::OnEraseBkgnd(pDC);
}

// Operations
public:
CBrush *m_brushPat;

//
m_bitmap.LoadBitmap(IDB_CLOUDS);
m_brushPat.CreatePatternBrush(&m_bitmap);
2 下面是 渐变色 按钮
void COwnerBt::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
#define MULTI 256
CRect rect;
GetClientRect(rect);
CClientDC dc(this);
int iHeight = rect.Height();
int iWidth = rect.Width();
COLORREF crFrom=RGB(239,255,255);//0x00ffffef;
COLORREF crTo =RGB(12,169,254 );//0x00fea90c;
int iR = GetRValue( crFrom );
int iG = GetGValue( crFrom );
int iB = GetBValue( crFrom );
//
int idR = (MULTI*(GetRValue(crTo)-iR)) / iWidth;// -379
int idG = (MULTI*(GetGValue(crTo)-iG)) / iWidth;// -143
int idB = (MULTI*(GetBValue(crTo)-iB)) / iWidth;// -1
// =0
iR *= MULTI;
iG *= MULTI;
iB *= MULTI;
// ->
for(int i = rect.left; i <= iWidth; i++)
{
dc.FillSolidRect(i,rect.top,1,iHeight,RGB(iR/MULTI,iG/MULTI,iB/MULTI));
iR += idR;
iG += idG;
iB += idB;
}
if (lpDrawItemStruct->itemState & ODS_FOCUS)// 0x0010
{// focus
rect.DeflateRect(4,4);
dc.SelectObject(GetStockObject(NULL_BRUSH));
dc.Rectangle(&rect);
}
dc.SetBkMode(TRANSPARENT);
dc.TextOut(46,6,"Button",6);
}
zyx040404 2019-11-16
  • 打赏
  • 举报
回复
引用 4 楼 schlafenhamster 的回复:
不必“first, create a button via CreateWindow(WC_BUTTON, ...)”
1 draw image first
2 then draw the button later.

how to draw the button later?
schlafenhamster 2019-10-22
  • 打赏
  • 举报
回复
不必“first, create a button via CreateWindow(WC_BUTTON, ...)”
1 draw image first
2 then draw the button later.
zyrr159487 2019-10-22
  • 打赏
  • 举报
回复
曾经做过整个界面就是一张背景图,按钮什么的变化是根据鼠标状态的变化,局部贴图。
叶恭介叶恭介 2019-10-22
  • 打赏
  • 举报
回复
可以搜索怎么自绘按钮,实现你的要求
zgl7903 2019-10-22
  • 打赏
  • 举报
回复
DrawFrameControl DFC_BUTTON 就可以绘制按钮 记录绘制的位置, 鼠标移动和点击的时候,判断是否在这个区域中, 然后模拟按钮发送 WM_COMMAND BN_CLICKED 消息

19,469

社区成员

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

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