Therefore intend to create dynamic button, unified to dynamically add bitmap button, but this problem again,
Button text is covered, button bitmap, too, can't distinguish between each button,
So I want to ask how the bitmap button displays text
MyButton * BTN=new MyButton ();
BTN - & gt; Create (pStr, dwStyle, CRect (left, top, right, bottom), and this - & gt; GetParent (), IDC_D_BTN + index);
BTN - & gt; LoadBitmaps (IDB_BITMAP_yp_c IDB_BITMAP_yp_d, IDB_BITMAP_yp_x IDB_BITMAP_yp_c);
Or have any other good ideas can, bosses give advice or comments
CodePudding user response:
Or how can I not use a control variable, using the control ID add bitmapCodePudding user response:
Can do pictures, text directly onto the reproduction, that's a lot of practical engineering;You can also find a third-party text images, search a handful:
https://www.codeproject.com/Articles/3873/Image-Button-Control
CodePudding user response:
You said that I think of, but, because I am a unified add bitmap, cause all button is the same picture, unable to distinguishCodePudding user response:
From a new class to handle CBitmapButton derived
//MyBitmapButton. H
# pragma once
The class CMyBitmapButton: public CBitmapButton
{
DECLARE_DYNAMIC (CMyBitmapButton)
Public:
CMyBitmapButton ();
Virtual ~ CMyBitmapButton ();
Protected:
DECLARE_MESSAGE_MAP ()
Virtual void DrawItem (LPDRAWITEMSTRUCT lpDIS);
};
//MyBitmapButton. CPP
# include "stdafx. H"
# include "MyBitmapButton. H"
IMPLEMENT_DYNAMIC (CMyBitmapButton CBitmapButton)
CMyBitmapButton: : CMyBitmapButton ()
{
}
CMyBitmapButton: : ~ CMyBitmapButton ()
{
}
BEGIN_MESSAGE_MAP (CMyBitmapButton CBitmapButton)
END_MESSAGE_MAP ()
//CMyBitmapButton message handler
Void CMyBitmapButton: : DrawItem (LPDRAWITEMSTRUCT lpDIS)
{
//operated by parent default map a
__super: : DrawItem (lpDIS);
//get window need to display the string
Cstrings szText;
GetWindowText (szText);
if(! SzText. IsEmpty ())
{
//by the different font color of different state
COLORREF txtColor=GetSysColor (COLOR_WINDOWTEXT);
UINT state=lpDIS - & gt; ItemState;
If (state & amp; ODS_SELECTED)
TxtColor=RGB (0, 0, 255);
Else if (state & amp; ODS_FOCUS)
TxtColor=RGB (200, 100, 0).
Else if (state & amp; ODS_DISABLED)
TxtColor=RGB (100, 100, 100);
//the CDC handle
The CDC * pDC=CDC: : FromHandle (lpDIS - & gt; HDC);
//save DC
Int nSaveDC=pDC - & gt; SaveDC ();
//draw area
CRect the rect (lpDIS - & gt; RcItem);
//set the font color
PDC - & gt; SetTextColor (txtColor);
//draw the font
PDC - & gt; DrawText (szText, & amp; The rect, DT_CENTER | DT_VCENTER);
//restore DC
PDC - & gt; RestoreDC (nSaveDC);
}
}
CodePudding user response:
Not give you a class? Button you can add text, this kind of a lot of people have written,Your "button to use the same image" the demand is not very reasonable, normal circumstances you will dynamically create button by different ID, different functions and different images,
CodePudding user response:
I also want to give each button to add different images, but they will not get