home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / WILDASS / SOURCE / FAKECPTN.CPP < prev    next >
C/C++ Source or Header  |  1993-07-27  |  4KB  |  136 lines

  1. // fakecptn.cpp
  2. //
  3. // implementation file for CFakeWnd
  4. // 
  5. // update: 1.00 28-Jul-93 tw
  6.  
  7. #include <afxwin.h>
  8. #include <afxext.h>
  9. #include "fakecptn.h"
  10.                 
  11. BEGIN_MESSAGE_MAP( CFakeWnd, CFrameWnd )
  12.    ON_WM_NCHITTEST()
  13.    ON_WM_PAINT()
  14.    ON_WM_ACTIVATEAPP() 
  15. END_MESSAGE_MAP()                
  16.                 
  17. CFakeWnd::CFakeWnd()
  18. {  
  19.    // create it, using the base classes create fxn
  20.    VERIFY( Create( NULL, "FakeCaption", 
  21.       WS_POPUP | WS_BORDER, CRect(0,0,100,100) ));
  22.       
  23.    // calculate the fake captions size
  24.    int cyCaption = GetSystemMetrics( SM_CYCAPTION ) / 3; 
  25.    m_pRectCaption = new CRect( cyCaption, 0, 100, cyCaption );      
  26.    ASSERT( m_pRectCaption );
  27.    
  28.    // ... and the close boxes size too
  29.    m_pRectSysMenu = new CRect( 0, 0, cyCaption, cyCaption );
  30.    ASSERT( m_pRectSysMenu );
  31. }            
  32.    
  33. CFakeWnd::~CFakeWnd()
  34. {  
  35.    // take care of the alloted objects
  36.    delete m_pRectSysMenu;
  37.    delete m_pRectCaption;
  38. }
  39.    
  40.        
  41. UINT
  42. CFakeWnd::OnNcHitTest( CPoint pnt )
  43. {  
  44.    // get the client coordinates of the point we`re testing     
  45.    ScreenToClient( &pnt );
  46.    
  47.    // if we`re in the fake caption bar, tell windows we`re in
  48.    // the actual caption bar
  49.    if ( m_pRectCaption->PtInRect( pnt ))
  50.    {
  51.       return HTCAPTION;    
  52.    }
  53.    
  54.    // if we`re in the closebox, tell windows we are..  
  55.    if ( m_pRectSysMenu->PtInRect( pnt ))
  56.    {
  57.       return HTSYSMENU;
  58.    }
  59.    
  60.    // base class will do the rest
  61.    return CFrameWnd::OnNcHitTest( pnt );      
  62. }
  63.      
  64.       
  65. void 
  66. CFakeWnd::OnPaint()
  67. {         
  68.  
  69.    // select a color according to focus
  70.    COLORREF col = ( GetFocus() == this ) ? GetSysColor( COLOR_ACTIVECAPTION )
  71.                                          : GetSysColor( COLOR_INACTIVECAPTION );
  72.    
  73.    // paint the caption
  74.    CBrush brushCaption;
  75.    VERIFY( brushCaption.CreateSolidBrush( col ));
  76.    
  77.    CPaintDC dc( this );
  78.    dc.FillRect( *m_pRectCaption, &brushCaption );   
  79.                        
  80.    // paint the menu box                       
  81.    CBrush brushMenu;              
  82.    VERIFY( brushMenu.CreateSolidBrush( GetSysColor( COLOR_MENU )));          
  83.    dc.FillRect( *m_pRectSysMenu, &brushMenu );
  84.    
  85.    // paint the boxes logo          
  86.    CBrush brushCloseSign;             
  87.    VERIFY( brushCloseSign.CreateSolidBrush( RGB( 255, 255, 255 )));
  88.    CRect rectCloseSign( 2, 
  89.                         (m_pRectSysMenu->Height()/2)-1, 
  90.                         m_pRectSysMenu->Width()-2, 
  91.                         (m_pRectSysMenu->Height()/2)+1 );
  92.    dc.FillRect( rectCloseSign, &brushCloseSign );
  93.                     
  94.    CPen penBlack;
  95.    VERIFY( penBlack.CreatePen( PS_SOLID, 0, RGB( 0, 0, 0) ));
  96.    
  97.    // paint the black separator lines
  98.    CPen * pPenOrig;
  99.    VERIFY( pPenOrig = dc.SelectObject( &penBlack ));
  100.    dc.MoveTo( rectCloseSign.TopLeft() );                   
  101.    CPoint pntTopRight = rectCloseSign.TopLeft() + CSize( rectCloseSign.Width(), 0 );
  102.    VERIFY( dc.LineTo( pntTopRight ));
  103.    VERIFY( dc.LineTo( rectCloseSign.BottomRight() ));
  104.    CPoint pntBottomLeft = rectCloseSign.BottomRight() - CSize( rectCloseSign.Width(), 0 );
  105.    VERIFY( dc.LineTo( pntBottomLeft ));
  106.    VERIFY( dc.LineTo( rectCloseSign.TopLeft() ));
  107.    
  108.    dc.MoveTo( 0, m_pRectSysMenu->bottom );
  109.    VERIFY( dc.LineTo( m_pRectCaption->right, m_pRectSysMenu->bottom ));
  110.    
  111.    dc.MoveTo( m_pRectSysMenu->right, m_pRectSysMenu->bottom );
  112.    VERIFY( dc.LineTo( m_pRectSysMenu->right, m_pRectSysMenu->top-1 ));
  113.    
  114.    dc.SelectObject( pPenOrig ); 
  115.         
  116. }
  117.  
  118.       
  119. void
  120. CFakeWnd::OnActivateApp( BOOL bActive, HTASK /*hTask*/ )
  121. {  
  122.    // if activation state changes, take care
  123.    // the caption bar is redrawn - or it will stay in
  124.    // the state it was before; remember this is _not_
  125.    // an ordinary caption bar so nobody else will take care of it...
  126.    
  127.    TRACE("OnACtivateApp called\n");
  128.    
  129.    CRect rectClient;
  130.    GetClientRect( &rectClient );
  131.    InvalidateRect( rectClient );
  132. }
  133.    
  134.       
  135.       
  136.