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 » Why my button could not display in the view? Collapse All
Subject Author Date
Fietiger Kisinger Oct 25, 2008 - 9:02 AM

I want my ctreectrl work with a toolbar, so I combine them into a view derived from CExtWRB < CView >,then I created the view in


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)


But the button of the tool bar could not display.


I got the hint in the GLView sample.


My view is like this


#if !defined(AFX_XTREEVIEW_H__D6B7D588_61DC_43AA_98F7_7CE0716E7657__INCLUDED_)

#define AFX_XTREEVIEW_H__D6B7D588_61DC_43AA_98F7_7CE0716E7657__INCLUDED_


#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

// XTreeView.h : header file

//


/////////////////////////////////////////////////////////////////////////////

// CXTreeView view

#define GL_VIEWS_ID_VIEW_DLG_CTRL_ID 0x1234

class CXTreeCtrlDoc;

class CXExtTreeView : public CExtWRB < CView >

{

 class CNavigationBar : public CExtToolControlBar

 {

 public:

  CExtComboBox m_wndCameraSelCombo;

  

  CNavigationBar()

  {

  }

  ~CNavigationBar()

  {

  }  

  virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)

  {

   if( message == WM_CONTEXTMENU )

    return 0L;

   if(  message == WM_LBUTTONDOWN

    || message == WM_LBUTTONUP

    || message == WM_MBUTTONDOWN

    || message == WM_MBUTTONUP

    || message == WM_RBUTTONDOWN

    || message == WM_RBUTTONUP

    )

   {

    HWND hWndThis = GetSafeHwnd();

    ASSERT( hWndThis != NULL );

    ASSERT( ::IsWindow( hWndThis ) );

    HWND hWndParent = ::GetParent( hWndThis );

    ASSERT( hWndParent != NULL );

    ASSERT( ::IsWindow( hWndParent ) );

    HWND hWndFocus = ::GetFocus();

    if(  hWndFocus == NULL

     || hWndFocus == hWndThis

     || ::IsChild( hWndThis, hWndFocus )

     )

     ::SetFocus( hWndParent );

    else if( ! ::IsChild( hWndParent, hWndFocus ) )

     ::SetFocus( hWndParent );

   }

   return CExtToolControlBar::WindowProc(message,wParam,lParam);

  }

  

  bool InitNavigationBar()

  {

   m_bPresubclassDialogMode = true;

   

   if( !m_wndCameraSelCombo.Create(

    WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,

    CRect( 0, 0, 100, 400 ),

    this,

    ID_CAMERA_SELECTION_COMBO

    )

    )

   {

    ASSERT( FALSE );

    return  false;

   }

   VERIFY(

    SetButtonCtrl(

    CommandToIndex(ID_CAMERA_SELECTION_COMBO),

    &m_wndCameraSelCombo

    )

    );

   m_wndCameraSelCombo.SetCurSel( 0 );

   m_wndCameraSelCombo.SetFont( CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT)) );

    return true;

  }

  

 }; // class CNavigationBar


protected:

 DECLARE_DYNCREATE(CXExtTreeView)


// Attributes

public:

 CNavigationBar m_wndToolbar;

 

 CExtWFF<CTreeCtrl> m_wndDockedCtrlTree;


// Operations

public:

 CXExtTreeView();           // protected constructor used by dynamic creation

 virtual ~CXExtTreeView();

 CXTreeCtrlDoc* GetDocument();


// Overrides

 // ClassWizard generated virtual function overrides

 //{{AFX_VIRTUAL(CXExtTreeView)

 public:

 virtual void OnInitialUpdate();

 protected:

 virtual void OnDraw(CDC* pDC);      // overridden to draw this view

 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

 virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);

 //}}AFX_VIRTUAL


// Implementation

protected:

#ifdef _DEBUG

 virtual void AssertValid() const;

 virtual void Dump(CDumpContext& dc) const;

#endif


 // Generated message map functions

protected:

 //{{AFX_MSG(CXExtTreeView)

 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

 afx_msg void OnSize(UINT nType, int cx, int cy);

 afx_msg void OnPaint();

 //}}AFX_MSG

 DECLARE_MESSAGE_MAP()

};


/////////////////////////////////////////////////////////////////////////////


//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_XTREEVIEW_H__D6B7D588_61DC_43AA_98F7_7CE0716E7657__INCLUDED_)


// XTreeView.cpp : implementation file

//


#include "stdafx.h"

#include "XTreeCtrl.h"

#include "XTreeView.h"


#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

#include "XTreeCtrlDoc.h"

/////////////////////////////////////////////////////////////////////////////

// CXTreeView


IMPLEMENT_DYNCREATE(CXExtTreeView, CView)


CXExtTreeView::CXExtTreeView()

{

}


CXExtTreeView::~CXExtTreeView()

{

}




BEGIN_MESSAGE_MAP(CXExtTreeView, CView)

 //{{AFX_MSG_MAP(CXExtTreeView)

 ON_WM_CREATE()

 ON_WM_SIZE()

 ON_WM_PAINT()

 //}}AFX_MSG_MAP

END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////

// CXTreeView drawing


void CXExtTreeView::OnDraw(CDC* pDC)

{

 CDocument* pDoc = GetDocument();

 // TODO: add draw code here

}


/////////////////////////////////////////////////////////////////////////////

// CXTreeView diagnostics


#ifdef _DEBUG

void CXExtTreeView::AssertValid() const

{

 CView::AssertValid();

}


void CXExtTreeView::Dump(CDumpContext& dc) const

{

 CView::Dump(dc);

}

#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////

// CXTreeView message handlers

CXTreeCtrlDoc* CXExtTreeView::GetDocument() // non-debug version is inline

{

 if(m_pDocument==NULL){

  CFrameWnd* frm = (CFrameWnd*) ::AfxGetMainWnd();

  ASSERT(frm);

  CDocument* pDoc = frm->GetActiveDocument();

  ASSERT(pDoc);

  ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CXTreeCtrlDoc)));

  pDoc->AddView(this);

  m_pDocument= pDoc;

 }

 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CXTreeCtrlDoc)));

 return (CXTreeCtrlDoc*)m_pDocument;

}

int CXExtTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

 if (CExtWRB < CView >::OnCreate(lpCreateStruct) == -1)

 { AfxMessageBox("Creat err");

 return -1;

 }

 

 // TODO: Add your specialized creation code here

 m_wndToolbar.m_bPresubclassDialogMode = true;

 if( !m_wndToolbar.Create(

  _T(""),

  this,

  AFX_IDW_DIALOGBAR,

  WS_CHILD|WS_VISIBLE

  |CBRS_ALIGN_TOP|CBRS_TOOLTIPS

  |CBRS_FLYBY|CBRS_SIZE_DYNAMIC

  )

  )

 {

  ASSERT( FALSE );

  return -1;

 }

 if( !m_wndToolbar.LoadToolBar(IDR_TOOLBAR_INVIEW) )

 {

  ASSERT( FALSE );

  return -1;

 }

 if( !m_wndToolbar.InitNavigationBar() )

  return -1;

 

 //  if( !m_wndGlPanel.Create(

 //   this,

 //   GL_VIEWS_ID_VIEW_DLG_CTRL_ID

 //   )

 //   )

 //  {

 //   ASSERT( FALSE );

 //   AfxMessageBox("Creat err");

 //   return -1;

 //  }

 if( !m_wndDockedCtrlTree.Create(

  WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL

  |TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT

  |TVS_INFOTIP|TVS_DISABLEDRAGDROP

  |TVS_SINGLEEXPAND|TVS_SHOWSELALWAYS

  ,

  CRect(0,0,0,0),

  this,

  /*this->GetDlgCtrlID()*/

  GL_VIEWS_ID_VIEW_DLG_CTRL_ID

  )

  )

 {

  TRACE0("Failed to create m_wndDockedCtrlEdit\n");

  return -1;  // fail to create

 }

 

 CWnd::RepositionBars( 0, 0xFFFF, GL_VIEWS_ID_VIEW_DLG_CTRL_ID );


 return 0;

}


void CXExtTreeView::OnSize(UINT nType, int cx, int cy)

{

 CView::OnSize(nType, cx, cy);

 

 // TODO: Add your message handler code here

 if( nType != SIZE_MINIMIZED )

  CWnd::RepositionBars( 0, 0xFFFF, GL_VIEWS_ID_VIEW_DLG_CTRL_ID );


}


void CXExtTreeView::OnPaint()

{

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

 

 // TODO: Add your message handler code here

 CPaintDC dcPaint( this );

 CExtPaintManager::stat_ExcludeChildAreas(

  dcPaint.GetSafeHdc(),

  GetSafeHwnd()

  );

// OnDraw(&dcPaint);

 // Do not call CView::OnPaint() for painting messages

}


BOOL CXExtTreeView::PreCreateWindow(CREATESTRUCT& cs)

{

 // TODO: Add your specialized code here and/or call the base class

 if( ! (CExtWRB < CView > ::PreCreateWindow(cs) ) )

  return FALSE;

 

 cs.dwExStyle &= ~(WS_EX_STATICEDGE|WS_EX_CLIENTEDGE);

 cs.style &= ~WS_BORDER;

 cs.style |= WS_CLIPSIBLINGS;

 cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,

  ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);


 return CView::PreCreateWindow(cs);

}


void CXExtTreeView::OnInitialUpdate()

{

 CView::OnInitialUpdate();

 

 // TODO: Add your specialized code here and/or call the base class

 m_wndToolbar.m_wndCameraSelCombo.AddString("Root");

 m_wndToolbar.m_wndCameraSelCombo.SetCurSel(0);


}


void CXExtTreeView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)

{

 // TODO: Add your specialized code here and/or call the base class

 m_wndToolbar.m_wndCameraSelCombo.AddString("Sub");

 m_wndToolbar.m_wndCameraSelCombo.SetCurSel(0);


 

}


 


I created the view in the following funtion.


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)

{

 // TODO: Add your specialized code here and/or call the base class

 CRect rc;

 GetClientRect( &rc);

 if (!m_wndSplitter.CreateStatic(this,1, 2))

 {

  TRACE0("Failed to CreateStaticSplitter\n");

  

  return CExtNCW < CFrameWnd >::OnCreateClient(lpcs, pContext);

 }

 if (!m_wndSplitter.CreateView(0,1,pContext->m_pNewViewClass,

  CSize(rc.Width(), rc.Height()),pContext))

 {

  ;

 }

 if (!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CXExtTreeView),

  CSize(rc.Width()/6, rc.Height()),pContext))

 {

  ;

 }


 SetActiveView((CView*)m_wndSplitter.GetPane (0,1));

 return true;


 return CFrameWnd::OnCreateClient(lpcs, pContext);

}


 


the toolbar resorce is:


/////////////////////////////////////////////////////////////////////////////

//

// Toolbar

//


IDR_TOOLBAR_INVIEW TOOLBAR DISCARDABLE  16, 15

BEGIN

    BUTTON      ID_CAMERA_SELECTION_COMBO

    BUTTON      ID_BTN_MENU_ROTATION //this button is not diaplayed

END


 

Technical Support Oct 27, 2008 - 3:55 AM

Your view creation code is OK. The in-view toolbar in the GLViews sample application has 4 buttons and 2 separators both at run-time and in the toolbar resource. The last button in the toolbar resource in your project can be invisible if you have manually edited bitmap of toolbar resource outside Visual C++ resource editor and the result bitmap width is less than required.