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 General Discussion » Using Owner Drawn CTreeCtrl Collapse All
Subject Author Date
konrad krupa Nov 3, 2004 - 1:13 PM

I’m would like to use my custom CTreeCtrl in the docable control. I was able to successfully implement my control. I can load the tree items but when I click on the docable window I’m getting nasty errors.


 


Any ideas.

Technical Support Nov 4, 2004 - 2:11 AM

Unfortunately, the information you provided is not enough to make any conclusion what happens in your application. You may send us your project so that we can fix these errors even if they are "nasty" :).

konrad krupa Nov 4, 2004 - 3:12 PM

I guess I fixed it.


 


The problem was with my OwnerDraw logic.


Please let me know if you want me to send you an example.


 


Konrad

konrad krupa Nov 4, 2004 - 7:08 AM

Thanks for your response. I just sent the project yesterday (I sent few attachments and instructions how to duplicate the problem).


 


Konrad

Technical Support Nov 8, 2004 - 8:54 AM

We reviewed your source code and would like to note the following.
To implement a thin one pixel border, you are using CExtWRB template class which recomputes and repaints the non-client area of the window. But scroll bars of the tree control are parts of its non-client area. This means CExtWRB simply kills the scroll bars in your tree. If you need scroll bars, you should not use CExtWRB. You can find an alternative solution (implementation of a thin border) in the Prof-UIS samples (trial/full version). For example, the CProfStudioThinFrame class in the ProfStudio sample implements the same border but does not kill the non-client area of the window. Here is its source code:


class CProfStudioThinFrame : public CWnd
{
 bool m_bAutoDestroyOnPostNcDestroy;
public:
 CProfStudioThinFrame()
  : m_bAutoDestroyOnPostNcDestroy( false )
 {
 }

 BOOL Create(
  CWnd * pParentWnd,
  UINT nID
  )
 {
  return
   CWnd::Create(
    AfxRegisterWndClass(0), NULL,
    WS_CHILD|WS_VISIBLE,
    CRect( 0,0,0,0 ),
    pParentWnd,
    nID,
    NULL
    );
 }

 BOOL CreateDynamicThinFrame(
  CWnd * pChildWnd
  )
 {
  ASSERT( !m_bAutoDestroyOnPostNcDestroy );
  ASSERT_VALID( pChildWnd );
  CWnd * pParentWnd = pChildWnd->GetParent();
  ASSERT_VALID( pParentWnd );
  UINT nID = pChildWnd->GetDlgCtrlID();
  if( ! Create( pParentWnd, nID ) )
  {
   ASSERT( FALSE );
   return FALSE;
  }
  pChildWnd->SetParent( this );
  m_bAutoDestroyOnPostNcDestroy = true;
  return TRUE;
 }
 
 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
 {
  switch( message )
  {
  case WM_SETFOCUS:
   {
    HWND hWndChild = ::GetWindow( GetSafeHwnd(), GW_CHILD );
    if( hWndChild != NULL )
    {
     ::SetFocus( hWndChild );
     return 0;
    }
   }
  break;
  case WM_SIZE:
   if( wParam != SIZE_MINIMIZED )
   {
    HWND hWndChild = ::GetWindow( m_hWnd, GW_CHILD );
    if( hWndChild != NULL )
    {
     ::MoveWindow(
      hWndChild,
      0,
      0,
      LOWORD(lParam),
      HIWORD(lParam),
      FALSE
      );
     RedrawWindow(
      NULL, NULL,
      RDW_INVALIDATE|RDW_UPDATENOW
      |RDW_ERASE|RDW_ERASENOW
      |RDW_ALLCHILDREN
      );
    } // if( hWndChild != NULL )
   }
   return 0;
  case WM_NCCALCSIZE:
  {
   NCCALCSIZE_PARAMS * pNCCSP =
    reinterpret_cast < NCCALCSIZE_PARAMS * > ( lParam );
   ASSERT( pNCCSP != NULL );
   CRect rcWnd( pNCCSP->rgrc[0] );
   rcWnd.DeflateRect( 2, 2 );
   ::CopyRect( &(pNCCSP->rgrc[0]), rcWnd );
   return 0;
  }
  case WM_ERASEBKGND:
   return 1;
  case WM_NCPAINT:
  {
   CRect rcChildWnd, rcClient;
   GetWindowRect( &rcChildWnd );
   GetClientRect( &rcClient );
   ClientToScreen( &rcClient );
   if( rcChildWnd == rcClient )
    return 0;
   CPoint ptDevOffset = -rcChildWnd.TopLeft();
   rcChildWnd.OffsetRect( ptDevOffset );
   rcClient.OffsetRect( ptDevOffset );

   CWindowDC dc( this );
   ASSERT( dc.GetSafeHdc() != NULL );
   dc.ExcludeClipRect( &rcClient );

   dc.FillSolidRect(
    &rcChildWnd,
    g_PaintManager->GetColor( COLOR_3DFACE )
    );

   COLORREF clrThinFrame =
      g_PaintManager->GetColor( COLOR_3DSHADOW );
   dc.Draw3dRect(
    &rcChildWnd,
    clrThinFrame,
    clrThinFrame
    );

   return 0;
  }
  case WM_PAINT:
  {
   HWND hWndChild = ::GetWindow( m_hWnd, GW_CHILD );
   if( hWndChild == NULL )
    break;
   if( !CExtPaintManager::stat_DefIsHwndNeedsDirectRepaint(hWndChild) )
    break;
   CRect rcClient;
   GetClientRect( &rcClient );
   CPaintDC dc( this );
   bool bNoFill = false;
   if( g_PaintManager->GetCb2DbTransparentMode(this) )
    bNoFill = g_PaintManager->PaintDockerBkgnd( dc, this );
   if( !bNoFill )
    dc.FillSolidRect(
     &rcClient,
     g_PaintManager->GetColor(
      CExtPaintManager::CLR_3DFACE_OUT
      )
     );
   return 1;
  }
  } // switch( message )

  return CWnd::WindowProc(message,wParam,lParam);
 }

 virtual void PostNcDestroy()
 {
  CWnd::PostNcDestroy();
  if( m_bAutoDestroyOnPostNcDestroy )
   delete this;
 }

}; // class CProfStudioThinFrame


To set a thin frame around your tree, you need to create a tree as you do this and invoke the following code:
(new CProfStudioThinFrame)->
    CreateDynamicThinFrame(
     &m_wndTree
     );