Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtLabel Bitmap display problem Collapse All
Subject Author Date
Dominik Braendlin Dec 3, 2008 - 2:00 AM

Dear Tech Support

I am using CExtLabel to display a CExtBitmap. It seems to me that it does only handle the SS_CENTERIMAGE flag for ICONS (SS_ICON). I need to vertically and horizontally align the bitmap. I don’t want it to be stretched.

Could you please tell how I can do this?

Thanks

Adrian

Technical Support Dec 3, 2008 - 9:46 AM

Here is part of the WinUser.h file where the SS_*** styles of the label control are defined:

 /*
 * Static Control Constants
 */
#define SS_LEFT             0x00000000L
#define SS_CENTER           0x00000001L
#define SS_RIGHT            0x00000002L
#define SS_ICON             0x00000003L
#define SS_BLACKRECT        0x00000004L
#define SS_GRAYRECT         0x00000005L
#define SS_WHITERECT        0x00000006L
#define SS_BLACKFRAME       0x00000007L
#define SS_GRAYFRAME        0x00000008L
#define SS_WHITEFRAME       0x00000009L
#define SS_USERITEM         0x0000000AL
#define SS_SIMPLE           0x0000000BL
#define SS_LEFTNOWORDWRAP   0x0000000CL
#if(WINVER >= 0x0400)
#define SS_OWNERDRAW        0x0000000DL
#define SS_BITMAP           0x0000000EL
#define SS_ENHMETAFILE      0x0000000FL
#define SS_ETCHEDHORZ       0x00000010L
#define SS_ETCHEDVERT       0x00000011L
#define SS_ETCHEDFRAME      0x00000012L

#define SS_TYPEMASK         0x0000001FL

#endif /* WINVER >= 0x0400 */
#define SS_NOPREFIX         0x00000080L /* Don’t do "&" character translation */
#if(WINVER >= 0x0400)
#define SS_NOTIFY           0x00000100L
#define SS_CENTERIMAGE      0x00000200L
#define SS_RIGHTJUST        0x00000400L
#define SS_REALSIZEIMAGE    0x00000800L
#define SS_SUNKEN           0x00001000L
#define SS_ENDELLIPSIS      0x00004000L
#define SS_PATHELLIPSIS     0x00008000L
#define SS_WORDELLIPSIS     0x0000C000L
#define SS_ELLIPSISMASK     0x0000C000L
#endif /* WINVER >= 0x0400 */


As you can see, the first part of styles defined above the SS_TYPEMASK preprocessor symbol definition cannot be mixed with each other. So, please check whether the SS_CENTER style is not mixed with other styles like SS_ICON.

Please also ensure the CExtLabel control uses the CExtLabel::eAlign bitmap painting mode nevertheless this is the default painting mode:
   CExtLabel & wndLabel = . . .
            CExtLabel::e_ImageMode_t eImageMode = CExtLabel::eAlign;
            wndLabel.SetImageMode( eImageMode );


Finally, we have improved the CExtLabel class part which paints the CExtBitmap image and added support for the SS_CENTERIMAGE style which can be mixed with the SS_CENTER style for painting the CExtBitmap image aligned to center both vertically and horizontally. If you need to use the vertical center alignment, then please update the source code for the following method:

 void CExtLabel::DoPaint(
            CDC * pDC,
            CRect & rcClient
            )
{
            ASSERT_VALID( this );
            ASSERT_VALID( pDC );
CExtMemoryDC dc( pDC, &rcClient );
CRgn rgnClient;
            if( rgnClient.CreateRectRgnIndirect( &rcClient ) )
                        dc.SelectClipRgn( &rgnClient );
            OnEraseBackground( dc, rcClient );
DWORD dwWndStyle = GetStyle();
DWORD dwWndType = (dwWndStyle&SS_TYPEMASK);
bool bCenterImage = ( (dwWndStyle&SS_CENTERIMAGE) != 0 );
            if( ! m_bmp.IsEmpty() )
            {
                        bool bSmootherAsPossible = true;
                        e_ImageMode_t eImageMode = GetImageMode();
                        if( eImageMode == eStretch )
                                    m_bmp.AlphaBlendSkinParts( dc.GetSafeHdc(), rcClient, CRect(0,0,0,0), CExtBitmap::__EDM_STRETCH, true, bSmootherAsPossible );
                        else if( eImageMode == eTile )
                                    m_bmp.AlphaBlendSkinParts(  dc.GetSafeHdc(), rcClient, CRect(0,0,0,0), CExtBitmap::__EDM_TILE, true, bSmootherAsPossible );
                        else if( eImageMode == eAlign )
                        {
                                    CSize szSize = m_bmp.GetSize();
                                    CRect rcDst( rcClient.left, rcClient.top, rcClient.left + szSize.cx, rcClient.top + szSize.cy );
                                    bool bCenterHorizontally = false;
                                    switch( dwWndType )
                                    {
                                    case SS_RIGHT:  rcDst.OffsetRect( rcClient.right - rcDst.right, 0 ); break;
                                    case SS_CENTER: bCenterHorizontally = true;        break;
                                    default: /* all the other types assumed as left */ break;
                                    }
                                    if( bCenterHorizontally )
                                                rcDst.OffsetRect( ( (rcClient.right - rcClient.left) - (rcDst.right - rcDst.left) ) / 2, 0 );
                                    if( bCenterImage )
                                                rcDst.OffsetRect( 0, ( (rcClient.bottom - rcClient.top) - (rcDst.bottom - rcDst.top) ) / 2 );
                                    CRect rcSrc( 0, 0, szSize.cx, szSize.cy );
                                    rcDst.top = max( rcDst.top, rcClient.top );
                                    rcDst.left = max( rcDst.left, rcClient.left );
                                    rcDst.bottom = min( rcDst.bottom, rcClient.bottom );
                                    rcDst.right = min( rcDst.right, rcClient.right );
                                    if( ::RectVisible( dc.GetSafeHdc(), &rcDst ) )
                                    {
                                                INT nOldStretchBltMode = bSmootherAsPossible ? ( ::GetStretchBltMode( dc.m_hDC ) ) : ( COLORONCOLOR );
                                                if( bSmootherAsPossible )
                                                            ::SetStretchBltMode( dc.m_hDC, ( g_PaintManager.m_bIsWinNT ) ? HALFTONE : COLORONCOLOR );
                                                m_bmp.AlphaBlend( dc.m_hDC, rcDst, rcSrc );
                                                if( bSmootherAsPossible )
                                                            ::SetStretchBltMode( dc.m_hDC, nOldStretchBltMode );
                                    }
                        }
            }
            else if( dwWndType == SS_ICON )
            {
                        HICON hIcon = GetIcon();
                        if( hIcon != NULL )
                        {
                                    CExtCmdIcon _icon;
                                    _icon.AssignFromHICON( hIcon, true );
                                    CSize szIcon = _icon.GetSize();
                                    int nOffsetX = bCenterImage ? (rcClient.Width() - szIcon.cx) / 2 : 0;
                                    int nOffsetY = bCenterImage ? (rcClient.Height() - szIcon.cy) / 2 : 0;
                                    _icon.Paint( PmBridge_GetPM(), dc.GetSafeHdc(), rcClient.left + nOffsetX, rcClient.top + nOffsetY, -1, -1 );
                        }
            }
            else
            {
                        CExtSafeString strText;
                        int nTextLen = GetWindowTextLength();
                        if( nTextLen > 0 )
                        {
                                    GetWindowText( strText.GetBuffer( nTextLen + 2 ), nTextLen + 1 );
                                    strText.ReleaseBuffer();
                        }
                        if( strText.GetLength() > 0 )
                        {
                                    DWORD dwDrawTextFlags = 0;
                                    switch( dwWndType )
                                    {
                                    case SS_RIGHT:           dwDrawTextFlags = DT_RIGHT;  break; 
                                    case SS_CENTER:          dwDrawTextFlags = DT_CENTER; break;
                                    case SS_LEFTNOWORDWRAP:  dwDrawTextFlags = DT_LEFT;   break;
                                    default: /* all the other types assumed as left */ dwDrawTextFlags = DT_LEFT; break;
                                    } // switch( dwWndType )
                                    if( strText.Find( _T(’\t’) ) != -1 ) // do tabs expanding
                                                dwDrawTextFlags |= DT_EXPANDTABS;
                                    if(                     (dwWndType == SS_SIMPLE)
                                                ||           (dwWndStyle&(SS_CENTERIMAGE|SS_ENDELLIPSIS|SS_PATHELLIPSIS)) != 0
                                                )
                                    {
                                                dwDrawTextFlags |= DT_SINGLELINE;
                                                if( (dwWndStyle&SS_CENTERIMAGE) != 0 )
                                                            dwDrawTextFlags |= DT_VCENTER;
                                                if( (dwWndStyle&SS_ENDELLIPSIS) != 0 )
                                                            dwDrawTextFlags |= DT_END_ELLIPSIS;
                                                if( (dwWndStyle&SS_PATHELLIPSIS) != 0 )
                                                            dwDrawTextFlags |= DT_PATH_ELLIPSIS;
                                    }
                                    else
                                                dwDrawTextFlags |= DT_WORDBREAK;
                                    if( dwWndType == SS_LEFTNOWORDWRAP )
                                                dwDrawTextFlags &= ~(DT_WORDBREAK|DT_SINGLELINE);
                                    if( (dwWndStyle&SS_NOPREFIX) != 0 )
                                                dwDrawTextFlags |= DT_NOPREFIX;
                                    bool bEnabled = IsWindowEnabled() ? true : false;
                                    OnDrawLabelText( dc, rcClient, strText, dwDrawTextFlags, bEnabled );
                        } // if( strText.GetLength() > 0 )
            }
            PmBridge_GetPM()->OnPaintSessionComplete( this );
            if( rgnClient.GetSafeHandle() != NULL )
                        dc.SelectClipRgn( &rgnClient );  
}