|
m_buttonctrl.SetFont(...) doesn't look to work
The following code perfectly works with CButton and doesn't with CXPButton:
CFont *pFont = new CFont;
pFont->CreateFont( 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Tahoma");
m_btn1.SetFont(pFont, TRUE);
|
|
|
|
|
Try declairing pFont as a member variable or global, as the code above will become invalid / out of scope as soon as your function ends.
I feel like I'm diagonally parked in a parallel universe
Jerry Davis
http://www.astad.org http://www.jvf.co.uk
|
|
|
|
|
To change the XPButton font in the class (for all buttons):
1) In CXPButton.h add bold lines.
class CXPButton : public CButton
{
DECLARE_DYNCREATE(CXPButton)
// Construction
private:
CFont pFont;
public:
CXPButton();
2) In CXPButton.cpp, add bold lines:
CXPButton::CXPButton()
{
pBoundryPen.CreatePen(PS_INSIDEFRAME|PS_SOLID,1,RGB(0,0,0));
pInsideBoundryPenLeft.CreatePen(PS_INSIDEFRAME|PS_SOLID,3,RGB(250,196,88));
pInsideBoundryPenRight.CreatePen(PS_INSIDEFRAME|PS_SOLID,3,RGB(251,202,106));
pInsideBoundryPenTop.CreatePen(PS_INSIDEFRAME|PS_SOLID,2,RGB(252,210,121));
pInsideBoundryPenBottom.CreatePen(PS_INSIDEFRAME|PS_SOLID,2,RGB(229,151,0));
pFillActive.CreateSolidBrush(RGB(222,223,236));
pFillInactive.CreateSolidBrush(RGB(222,223,236));
pInsideBoundryPenLeftSel.CreatePen(PS_INSIDEFRAME|PS_SOLID,3,RGB(153,198,252));
pInsideBoundryPenTopSel.CreatePen(PS_INSIDEFRAME|PS_SOLID,2,RGB(162,201,255));
pInsideBoundryPenRightSel.CreatePen(PS_INSIDEFRAME|PS_SOLID,3,RGB(162,189,252));
pInsideBoundryPenBottomSel.CreatePen(PS_INSIDEFRAME|PS_SOLID,2,RGB(162,201,255));
pFont.CreateFont(14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
m_bOverControl = m_bTracking = m_bSelected = Focus = 0;
}
CXPButton::~CXPButton()
{
// TODO: Cleanup your control's instance data here.
pBoundryPen.DeleteObject();
pFillActive.DeleteObject();
pFillInactive.DeleteObject();
pFont.DeleteObject();
pInsideBoundryPenLeft.DeleteObject();
pInsideBoundryPenRight.DeleteObject();
pInsideBoundryPenBottom.DeleteObject();
pInsideBoundryPenTop.DeleteObject();
pInsideBoundryPenLeftSel.DeleteObject();
pInsideBoundryPenTopSel.DeleteObject();
pInsideBoundryPenRightSel.DeleteObject();
pInsideBoundryPenBottomSel.DeleteObject();
}
void CXPButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
...
// Draw the text
if (!m_title.IsEmpty()/*!strText.IsEmpty()*/)
{
CFont *pOldFont = pDC->SelectObject(&pFont);
// Don't draw ambersands meant for hotkeys.
m_title.Replace("&", "");
CSize Extent = pDC->GetTextExtent(m_title/*strText*/);
CPoint pt( rect.CenterPoint().x - Extent.cx/2,
rect.CenterPoint().y - Extent.cy/2 );
if (state & ODS_SELECTED)
pt.Offset(1,1);
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
pDC->DrawState(pt, Extent, m_title/*strCaption*/, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
else
pDC->TextOut(pt.x, pt.y, m_title/*strCaption*/);
pDC->SelectObject(pOldFont);
pDC->SetBkMode(nMode);
}
}
-- modified at 14:20 Thursday 13th October, 2005
|
|
|
|
|
Anyone know how to use this with PropertySheets?
|
|
|
|
|
how about this:
CXPButton m_butOK;
CXPButton m_butCancel;
In OnInitDialog() of PropertySheet drived class add:
m_butOK.SubclassDlgItem(IDOK, this);
m_butCancel.SubclassDlgItem(IDCANCEL, this);
|
|
|
|
|
SubclassWindow() no effect! I use it by WTL...Help
|
|
|
|
|
Hi, can this cool button program be converted to a dll to work with vb.net? I'm not good at c++ and was wondering if anyone has converted it?
Thanks
|
|
|
|
|
VB.NET already supports XP buttons, just place a normal button on a form and set the button's FlatStyle to system. (Of course you need to add a manifest to your project for it to use XP themes)
--------------------------------
Mladen Mihajlovic
|
|
|
|
|
But what if you wanted to use the control in an app that runs on 2k and you build it with .NET? I've been searching for a control that will do just that .. anyone found one (or developed one)?
TIA!
M.
|
|
|
|
|
I downloaded the small demo ZIP file for your program and tried to compile it. It fails to do so. It seems as if a file named dlg.rc is is missing from your ZIP file. Can you provide an update with that file?
MJK
|
|
|
|
|
I have sent the complete updated project to Chris and he will be uploading it soon.
But you can create a new dlg based application and place buttons on it directly.
|
|
|
|
|
What about when the text is wider than the button??
Thanks!
|
|
|
|
|
Button adjust long text automatically. It depends. It is a normal button being painted. So like normal button if text is large it will be truncated. For the multiline I think you have to check DrawText in the DrawItem()
|
|
|
|