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.

解决方案 »

  1.   

    DrawFrameControl DFC_BUTTON 就可以绘制按钮 
    记录绘制的位置, 鼠标移动和点击的时候,判断是否在这个区域中, 然后模拟按钮发送 WM_COMMAND BN_CLICKED 消息
      

  2.   

    不必“first, create a button via CreateWindow(WC_BUTTON, ...)”
    1 draw image first
    2 then draw the button later. 
      

  3.   

    how to draw the button later?
      

  4.   

    下面是一个 透明 按钮
    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);
    }