Placing a 3D Logo Text In the PropertySheet Button Area

I read Jeremy Davis's article named "Placing a bitmap in the PropertySheet button area" and liked the idea a lot, but when I tried to implement it I found one small thing, bitmap can not change color if background color is not (for example) gray.

So I made my own program which displays 3d text in PropertySheet button area.

sample1.jpg (5019 bytes)

sample2.jpg (4809 bytes)

Note that when the property sheet is in wizard mode, the OK button and Tab Control are not present and so special care has to be taken to avoid crashes in OnPaint while trying to get the dimensions of that two objects.

Here how it's done.


void CPropertySheetWithLogoDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	if (m_LogoText.IsEmpty())
	return;

	BOOL bWizMode; 
        
	// Get the current style from PROPSHEETHEADER structure 
	if( m_psh.dwFlags & PSH_WIZARD ) 
		bWizMode = TRUE;                // It's in wizard mode
	else 
		bWizMode = FALSE;               // It's in property sheet mode


	// If this is a Wizard, cannot retrieve the tab control dimension. 
	// So Get the Dialog's Window Rect  

	CRect rectTabCtrl;
	if( bWizMode ) 
	{ 
		GetWindowRect(rectTabCtrl); 
		rectTabCtrl.OffsetRect(14,0);	// A little correction
	} 
	else 
	{ 
		GetTabControl()->GetWindowRect(rectTabCtrl);
	} 
	ScreenToClient(rectTabCtrl);


	CRect rectOk;
	GetDlgItem(IDOK)->GetWindowRect(rectOk);
	ScreenToClient(rectOk);

	dc.SetBkMode(TRANSPARENT);

	CRect rectText;
	rectText.left = rectTabCtrl.left;
	rectText.top = rectOk.top;
	rectText.bottom = rectOk.bottom;
	rectText.right = rectOk.left;

	CFont * OldFont = dc.SelectObject(&m_fontLogo);

	// draw text in DC
	COLORREF OldColor = dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT));

	dc.DrawText(m_LogoText, rectText + CPoint(1,1), 
	            DT_SINGLELINE | DT_LEFT | DT_VCENTER);
	dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW));
	dc.DrawText( m_LogoText, rectText, DT_SINGLELINE | DT_LEFT | DT_VCENTER);

	// restore old text color
	dc.SetTextColor( OldColor);

	// restore old font
	dc.SelectObject(OldFont);

	// Do not call CPropertySheet::OnPaint() for painting messages
}

You can play with different combination of DrawText functions and make any appearance of the Text

Download Source Code and Example

Last Updated: 20 July 1998



Comments

  • Next Button does not show

    Posted by Legacy on 06/03/2003 12:00am

    Originally posted by: Benoit

    Sometime, when using the PropertySheet in wizard mode the next button does not show.

    Windows 2000.
    In GINA mode.

    We tried downloading the latest IE and the behavior is still seen from time to time.

    Reply
  • Removing of Help Button on Property Sheet

    Posted by Legacy on 09/12/2002 12:00am

    Originally posted by: Shridhar

    Hi..
    
    

    I am looking for adding our customised button on property sheet instead of Next/Back or canel and one more thing i need to know how to disable or remove it from the Property sheet the Help Button from the Property Sheet. plz if any body come across this mail it to me asap....

    Thanks in advance.....

    With warm regs,
    Shri

    Reply
  • Adding a button in the coomon area of Property Sheet

    Posted by Legacy on 05/24/2002 12:00am

    Originally posted by: Ritu Singal

    How can i add a button in the upper portion of the Property Sheet, i mean before the Tabs.
    I am able to add the buttons(or other controls) in the downside area and also in the right side. But not sure how to add at the top and left. Any pointers will be really helpful.

    Reply
  • changing the color of property sheet

    Posted by Legacy on 04/10/2002 12:00am

    Originally posted by: venkatesh


    Colud you please tell me how to change the color of a propertysheet.

    Reply
  • DirectShow and ATL

    Posted by Legacy on 05/15/1999 12:00am

    Originally posted by: Stephane Rodriguez

    Well ATL has some counter parts. If we talk only about the tiny CComPtr and CComQIPtr template classes, then you can check out the 'vidclip' sample in the DirectShow SDK. In this sample, they don't implement a source filter but rather hack a little around video codecs.
    Beware that CComPtr and CComQIPtr are tedious. If you declare them as local variables, it's fine, but if they are class members, you may encounter Release() problems depending on your code.

    If ATL is for you much more the ATL wizard then forget it, because it's very likely to add OLE implementations, and this might be out of context in an AX file.


    SR-

    Reply
  • Modification for reducing text dimensions if string doesn't fit

    Posted by Legacy on 01/15/1999 12:00am

    Originally posted by: Frumento Enrico

    This control have problems when the font is greater that the area reserverd for it.
    
    There are two situations that can happen when drawing text in the left bottom of a PropertySheet or a Wizard.
    -the selected font is unavailable
    -the selected font is greater than the reserved CRect (this is also the situation in which the system font, used in place of an unavailable font, is greater than the missing one).
    I experienced this problem building a fixed dialog based program on a Win95 station that should run also on an NT station (the font I used on the Win95 station was missing on NT).
    This patch tries to reduce the font Height till it fits its CRect.

    ....<omissis>
    // draw text in DC
    COLORREF OldColor = dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT));

    // START NEW/MODIFIED PART
    // before drawing calculate Rect size and if greater reduce font size
    CRect RealrectText;
    BOOL bOK=FALSE;
    BOOL bShouldDrawText=TRUE;
    LOGFONT LogFont;
    TEXTMETRIC tmText;
    CFont *resizedfontLogo=&m_fontLogo;
    RealrectText=rectText;
    while (!bOK) {
    CFont newfontLogo;
    dc.DrawText( m_LogoText, &RealrectText,
    DT_CALCRECT | DT_SINGLELINE | DT_LEFT | DT_VCENTER);
    dc.GetTextMetrics(&tmText);
    //leave space for a char on the right
    if (RealrectText.right < (rectText.right- mText.tmMaxCharWidth) )
    bOK=TRUE;
    resizedfontLogo->GetLogFont(&LogFont);
    //set lower bound if we can't draw even with the smallest font
    if (LogFont.lfHeight<8 && bOK==FALSE) {
    bShouldDrawText=FALSE;
    bOK=TRUE;
    }
    LogFont.lfHeight--;
    newfontLogo.CreateFontIndirect(&LogFont);
    resizedfontLogo= dc.SelectObject(&newfontLogo);
    }

    //doesn't draw if the font results too much little
    if (bShouldDrawText) {
    dc.DrawText( m_LogoText, rectText + CPoint(1,1),
    DT_SINGLELINE | DT_LEFT | DT_VCENTER);
    dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW));
    dc.DrawText( m_LogoText, rectText,
    DT_SINGLELINE | DT_LEFT | DT_VCENTER);
    }
    // END NEW/MODIFIED PART

    // restore old text color
    dc.SetTextColor( OldColor);
    ....<omissis>


    Reply
  • Fix for Wizard Mode

    Posted by Legacy on 11/04/1998 12:00am

    Originally posted by: Jeff Lundgren

    In wizard mode, which you detect, you may not have an OK button, so this replacement fixes this issue.
    
    

    CRect rectOk;
    if(bWizMode)
    GetDlgItem(IDCANCEL)->GetWindowRect(rectOk);
    else
    GetDlgItem(IDOK)->GetWindowRect(rectOk);

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • It's no secret what keeps CIOs up at night. Mobile, cloud, data, security, and social have become the "five imperatives," the drivers of business progress, innovation, and competitive differentiation. Business leaders around the world want to hear how other companies are succeeding. How are they applying the latest technologies? How did they get started? What outcomes are they achieving? Read this online magazine for success stories from organizations like the NBA, Pfizer, and San Jose State University as they …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds