Home > Software engineering >  Ask a question, how to draw a button on a picture
Ask a question, how to draw a button on a picture

Time:11-21

First, create a button via CreateWindow (WC_BUTTON,... )
Second, the 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 the draw button first, then draw the image, or the draw the image first, then the draw button
It 's not what I want to do. I want to draw the image first, then the draw button immediately. Or the button is covered by the image.

CodePudding user response:

DrawFrameControl DFC_BUTTON can draw button
Map the location of the record, the mouse and click, determine whether in this area, and then simulate button send WM_COMMAND BN_CLICKED message

CodePudding user response:

How to search the draw button, make your request

CodePudding user response:

Did the whole interface is a background, the button changes what is according to the state of the mouse, local map,

CodePudding user response:

Don't have to "first, create a button via CreateWindow (WC_BUTTON,... "
1 the draw the image first
2 then the draw the button later.

CodePudding user response:

reference 4 floor schlafenhamster response:
don't have to be first, create a button via CreateWindow (WC_BUTTON,... "
1 the draw the image first
2 then the draw the button later.

How to draw the button later?

CodePudding user response:

The following is a transparent button
Void CMyButton: : OnPaint ()
{
CPaintDC dc (this);//device context for painting
//TODO: Add your message handler code here
CRect rc;
GetClientRect (rc);
MapWindowPoints (GetParent (), the rc);
Dc. SetBrushOrg (- rc. Left - rc. Top);
GetClientRect (rc);
Dc. FillRect (& amp; Rc, m_brushPat);
//
Dc. SetBkMode (TRANSPARENT);
If (m_bHover) dc. SetTextColor (RGB (0, 255));//red
The else dc. SetTextColor (RGB (0, 0));
Dc. TextOut (45, 6, "transparent button");
//the Do not call CButton: : OnPaint () for painting the messages
}

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

//Operations
Public:
The CBrush * m_brushPat;

//
M_bitmap. LoadBitmap (IDB_CLOUDS);
M_brushPat. CreatePatternBrush (& amp; M_bitmap);
2 below is gradient buttons
Void COwnerBt: : DrawItem (LPDRAWITEMSTRUCT LPDRAWITEMSTRUCT)
{
//TODO: Add your code to draw the specified item
# define MULTI 256
CRect the rect.
GetClientRect (the rect);
CClientDC dc (this);
Int iHeight=the rect. Height ();
Int iWidth=the rect. Width ();
COLORREF crFrom=RGB (239255255);//0 x00ffffef;
COLORREF crTo=RGB (12169254);//0 x00fea90c;
Int iR=GetRValue (crFrom);
Int iG=GetGValue (crFrom);
Int the 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;
The iB *=MULTI;
//- & gt;
For (int I=the rect. Left; i <=iWidth; I++)
{
Dc. FillSolidRect (I, the rect. Top, 1, iHeight, RGB (iR/MULTI, iG/MULTI, iB/MULTI));
IR +=idR;
IG +=idG.
The iB +=idB;
}
If (lpDrawItemStruct - & gt; ItemState & amp;//0 x0010 ODS_FOCUS)
{//focus
The rect. DeflateRect (4, 4);
Dc. SelectObject (GetStockObject (NULL_BRUSH));
Dc. A Rectangle (& amp; The rect);
}
Dc. SetBkMode (TRANSPARENT);
Dc. TextOut (46, 6, "Button", 6);
}
  • Related