mvp_tips/CPUID/CPUID/ScrollableCaptions.cpp
void CScrollableCaptions::DoAlign(UINT ctlid, UINT textid)
    {
     CRect r;
     BOOL b = (BOOL)GetParent()->SendMessage(UWM_QUERY_COORDINATES, ctlid, (LPARAM)&r);
     ASSERT(b);
     if(!b)
        return;
     
     TRACE("DoAlign: Parent [%d] (L=%d T=%d R=%d B=%d)\n", ctlid, r.left, r.top, r.right, r.bottom);
     
     /******************************************************************************
                   +----+
                   |    |
                   |    |
                   |    |  Parent object: coordinates in r
                   |    |
                   +----+
                    +----+
                    |    |  
                    |    |  
                    |    |  Local object: coordinates in L
                    |    |  
                    +----+
     ******************************************************************************/

     CWnd * wnd = GetDlgItem(ctlid); // Well, my second GetDlgItem for 2007 (but they tend to come in pairs)
     ASSERT(wnd != NULL);   
     if(wnd == NULL)
        return;
     CRect L;
     wnd->GetWindowRect(&L);

     L.left = r.left;
     L.right = r.right;

     CWnd * caption = GetDlgItem(textid);
     ASSERT(caption != NULL);
     if(caption != NULL)
        { /* force vertical alignment */
         CRect C;
         caption->GetWindowRect(&C);
         L.bottom = C.bottom;
        } /* force vertical alignment */

     ScreenToClient(&L);
     wnd->SetWindowPos(NULL,
                       L.left, L.top,
                       L.Width(), L.Height(),
                       SWP_NOZORDER | SWP_NOACTIVATE);
     wnd->Invalidate();
    }
/****************************************************************************
*                       CScrollableCaptions::DoAlign
* Inputs:
*       UINT ctlid: Control ID of reference caption and vertical bar
*       UINT textid: Control ID of text
* Result: void
*       
* Effect: 
*       Aligns the edges of the vertical control with the parent control and with
*       the bottom of the horizontal control
* Notes:
*       The purpose of this code is to force the screen coordinates of the
*       scrollable entity to align to the screen coordinates of the
*       referenced entity, which is in a different dialog.  Because of the
*       roundoff errors in DBU-to-pixel mappings, there can be an off-by-one
*       error which looks really ugly.
*
*       Who says I'm obsessive-compusive?  
****************************************************************************/


Aligns the edges of the vertical control with the parent control and with
the bottom of the horizontal control
Notes:
The purpose of this code is to force the screen coordinates of the
scrollable entity to align to the screen coordinates of the
referenced entity, which is in a different dialog.  Because of the
roundoff errors in DBU-to-pixel mappings, there can be an off-by-one
error which looks really ugly.


Aligns the edges of the vertical control with the parent control and with the bottom of the horizontal control Notes : The purpose of this code is to force the screen coordinates of the scrollable entity to align to the screen coordinates of the referenced entity which is in a different dialog . Because of the roundoff errors in DBU - to - pixel mappings there can be an off - by - one error which looks really ugly .
void CScrollableCaptions::DoAlign(UINT ctlid, UINT textid)
    {
     CRect r;
     BOOL b = (BOOL)GetParent()->SendMessage(UWM_QUERY_COORDINATES, ctlid, (LPARAM)&r);
     ASSERT(b);
     if(!b)
        return;
     TRACE("DoAlign: Parent [%d] (L=%d T=%d R=%d B=%d)\n", ctlid, r.left, r.top, r.right, r.bottom);
     CWnd * wnd = GetDlgItem(ctlid); 
     ASSERT(wnd != NULL);   
     if(wnd == NULL)
        return;
     CRect L;
     wnd->GetWindowRect(&L);
     L.left = r.left;
     L.right = r.right;
     CWnd * caption = GetDlgItem(textid);
     ASSERT(caption != NULL);
     if(caption != NULL)
        { 
         CRect C;
         caption->GetWindowRect(&C);
         L.bottom = C.bottom;
        } 
     ScreenToClient(&L);
     wnd->SetWindowPos(NULL,
                       L.left, L.top,
                       L.Width(), L.Height(),
                       SWP_NOZORDER | SWP_NOACTIVATE);
     wnd->Invalidate();
    }
void CScrollableCaptions :: DoAlign ( UINT ctlid , UINT textid ) { CRect r ; BOOL b = ( BOOL ) GetParent ( ) -> SendMessage ( UWM_QUERY_COORDINATES , ctlid , ( LPARAM ) & r ) ; ASSERT ( b ) ; if ( ! b ) return ; TRACE ( " \n " , ctlid , r . left , r . top , r . right , r . bottom ) ; CWnd * wnd = GetDlgItem ( ctlid ) ; ASSERT ( wnd != NULL ) ; if ( wnd == NULL ) return ; CRect L ; wnd -> GetWindowRect ( & L ) ; L . left = r . left ; L . right = r . right ; CWnd * caption = GetDlgItem ( textid ) ; ASSERT ( caption != NULL ) ; if ( caption != NULL ) { CRect C ; caption -> GetWindowRect ( & C ) ; L . bottom = C . bottom ; } ScreenToClient ( & L ) ; wnd -> SetWindowPos ( NULL , L . left , L . top , L . Width ( ) , L . Height ( ) , SWP_NOZORDER | SWP_NOACTIVATE ) ; wnd -> Invalidate ( ) ; }
CScrollableCaptions::DoAlign
Inputs:
UINT ctlid: Control ID of reference caption and vertical bar
UINT textid: Control ID of text
Result: void
CScrollableCaptions :: DoAlign Inputs : UINT ctlid : Control ID of reference caption and vertical bar UINT textid : Control ID of text Result : void
/******************************************************************************
                   +----+
                   |    |
                   |    |
                   |    |  Parent object: coordinates in r
                   |    |
                   +----+
                    +----+
                    |    |  
                    |    |  
                    |    |  Local object: coordinates in L
                    |    |  
                    +----+
     ******************************************************************************/ // Well, my second GetDlgItem for 2007 (but they tend to come in pairs) /* force vertical alignment */ /* force vertical alignment */