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 use in "SubclassAllControlsDynamically" Collapse All
Subject Author Date
Monte Variakojis Nov 7, 2007 - 9:47 AM

Hello Group,


I’m having a bit of a problem with using the CExtLabel (CStatic) when subclassing. I would like the AfxMessageBox to share the same interface as rest of the application.


In my CWinApp (CMyApp) I’ve declared the DoMessageBox method:



    

int CGPSClockMonitorApp::DoMessageBox(LPCTSTR
    lpszPrompt, UINT nType, UINT nIDPrompt)

    {

    CExtNCW<CMyMessageBoxWnd> dlg;

    AfxHookWindowCreate( &dlg );

    int nReturn = CWinApp::DoMessageBox(lpszPrompt, nType,
    nIDPrompt);;

    AfxUnhookWindowCreate();

    return nReturn;

    }



In the CMyMessageBoxWnd class I’m using the "SubclassAllControlsDynamically" that was supplied in the FAQ. This allowed me a convient place to subclass all of the clildren like this:



    

void CMyMessageBoxWnd::OnPaint()

    {

    CPaintDC dcPaint(this); // device context for painting

    

    // This may not be a good technique, but it works -
    Suggestions where

    // to subclass this?

    if(m_bFirstTime == TRUE)

    {

        m_bFirstTime = FALSE;

        SubclassAllControlsDynamically(m_hWnd);

    }

    .

    .

    .

    }



All seems to function very well. However the CExtLabel does not expand the control characters in the string nor does it wrap the text within the desired rectangle.


Example using "SubclassAllControlsDynamically" and CExtLable:

 


text format: _T("WARNING!\n\nThis operation will erase the current temperature compensation table and create a new one. To ccomplish this, a temperature chamber will be necessary to complete this task. Do you want to proceed with the temperature characterization?")




In the "SubclassAllControlsDynamically" function I replace the CExtLabel with
CStatic I get the following (desired format):




You can see that the text is wrapped and follows the formation. I have tried
to "ModifyStyle" in the "SubclassAllControlsDynamically" function to encompass
the SS_LEFT  style with no success.


Do you have any suggestions how to get the "CExtLabel" to behave like the
CStatic? Any comments welcome.


Thanks for a great class library.


Regards,


Monte--


Monte Variakojis Nov 8, 2007 - 9:27 AM

support -

Thanks for the help. That did the trick. Pizza-n-Beer next time I’m in town.

Monte---

Technical Support Nov 8, 2007 - 7:16 AM

Here is the latest version of the DoPaint method that fixes all the label problems

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;
        if( m_eImageMode == eStretch )
        {
            m_bmp.AlphaBlendSkinParts( 
                dc.GetSafeHdc(),
                rcClient,
                CRect(0,0,0,0), 
                CExtBitmap::__EDM_STRETCH,
                true,
                bSmootherAsPossible
                );
        }
        else if( m_eImageMode == eTile )
        {
            m_bmp.AlphaBlendSkinParts( 
                dc.GetSafeHdc(),
                rcClient,
                CRect(0,0,0,0), 
                CExtBitmap::__EDM_TILE,
                true,
                bSmootherAsPossible
                );
        }
        else if( m_eImageMode == eAlign )
        {
            CSize szSize = m_bmp.GetSize();
            CRect rcDst( 
                rcClient.left, 
                rcClient.top, 
                rcClient.left + szSize.cx, 
                rcClient.top + szSize.cy
                );

            switch( dwWndType )
            {
            case SS_RIGHT:
                rcDst.OffsetRect( rcClient.right - rcDst.right, 0 );
                break; 
            case SS_CENTER:
                rcDst.OffsetRect( ( (rcClient.right - rcClient.left) - (rcDst.right - rcDst.left) ) / 2, 0 );
                break;
            default: 
                // all the other types assumed as left
                break;
            }

            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 )

            // do tabs expanding
            if( strText.Find( _T(’\t’) ) != -1 ) 
                dwDrawTextFlags |= DT_EXPANDTABS;

            if(        (dwWndType == SS_SIMPLE)
                ||    (dwWndStyle&SS_CENTERIMAGE) != 0
                ||    (dwWndStyle&SS_ENDELLIPSIS) != 0
                ||    (dwWndStyle&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 );    
}

Suhai Gyorgy Nov 8, 2007 - 4:33 AM

There have been posts reporting the CExtLabel class in the latest ProfUIS v2.81 ignoring "\n" and not handling wordwrapping right . The first problem can be solved like this:
Change CExtLabel.cpp @ line 238:

It is now:
bool bForceSingleLine =
( strText.Find( _T("\n") ) >= 0 ) ? true : false;

It should be:
bool bForceSingleLine =
( strText.Find( _T("\n") ) >= 0 ) ? false : true;

But the second problem is not solved yet (or at least the solution hasn’t appeared on the forums yet) and it might involve the above-mentioned lines to be changed again.