Control identifier  
       
      Printed From: Codejock Forums
        Category:  Codejock Products
       Forum Name:  Command Bars
       Forum Description:  Topics Related to Codejock Command Bars
       URL: http://forum.codejock.com/forum_posts.asp?TID=14287
       Printed Date: 04 November 2025 at 12:44am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
      
 
  
      Topic: Control identifier
       
      Posted By: Bart6
       Subject: Control identifier
       Date Posted: 13 May 2009 at 10:50am
       
      
        
          
	
Hi all,
 
 My application used a user-defined number of cameras (minimum 1). The user can pick from a commandbar the active camera.
 
 To populate the commandbar, i use:
 
 BOOST_FOREACH(ICamera* camera, cameras->Collection()) {
    CXTPControl* pCameraItem = pControls->Add(xtpControlButton, ID_CAMERA);
    pCameraItem->SetCaption( camera->Name().c_str() );
    pCameraItem->SetChecked( camera == cameras->Active() ); 
 }
 
 The listen to the commands, i use:
 
 ON_COMMAND(ID_CAMERA, OnCamera)
 
 and 
 
 void CPyroView::OnCamera()
 {
    // what camera is being picked?
 }
 
 
 Question: all the controls in the commandbar have the same id (ID_CAMERA) - in OnCamera i can't make the distinction between what camera is picked.
 What is the correct method to use, when the amount of camera's is unknown (iow ON_COMMAND_RANGE cant be used)
 
 Thanks
 Bart
          | 
         
        
      
 
  Replies: 
       
      Posted By: jimmy
       
      Date Posted: 13 May 2009 at 1:43pm
       
      
        
          
	
Hi,
  Add   pCameraItem->SetTag( iIndex)
  Remove ON_COMMAND and insert this line ON_XTP_EXECUTE(ID_FILE_RECENTPROJECTS, OnCamera)
  void CPyroView::OnCamera(NMHDR *pNMHDR,LRESULT *pResult) {     CXTPControl *pControl = ((NMXTPCONTROL *)pNMHDR)->pControl;     if (pControl)     {         DWORD_PTR myIndex = pControl->GetTag();         // do yours     } }
 
    Jimmy
  
          | 
         
        
        
       
      
      Posted By: jimmy
       
      Date Posted: 13 May 2009 at 2:32pm
       
      
        
          
	
Or pCameraItem->SetTag(  (DWORD_PTR) camera );
  ICamera* camera = (ICamera*) pControl->GetTag();
    Jimmy
  
          | 
         
        
        
       
      
      Posted By: jimmy
       
      Date Posted: 13 May 2009 at 2:36pm
       
      
        
          
	
Also can use
  CXTPControl *CPyroView::GetControl(CCmdUI *pCmdUI)     {     if (!pCmdUI->m_pOther)         return NULL;     return ((CXTPCommandBar*)pCmdUI->m_pOther)->GetControl(pCmdUI->m_nIndex);     }
  void CPyroView::OnUpdateCamera(CCmdUI *pCmdUI) {     if (m_dwMenuLock & ML_ANY)         pCmdUI->Enable(FALSE);     else     {         CXTPControl* pControl = GetControl(pCmdUI);         if (pControl)         {             ICamera* camera = (ICamera*) pControl->GetTag();             pCmdUI->SetCheck( (camera->Active()) );         }         else             pCmdUI->Enable(FALSE);     } }
 
    Jimmy
  
          | 
         
        
        
       
      
      Posted By: Bart6
       
      Date Posted: 13 May 2009 at 3:15pm
       
      
        
          
	
Thank you Kimmy - i'm trying the latter, but bump into undefined "m_dwMenuLock" & "ML_ANY". I searched the library, but could find any reference to it.
 
 Will the last proposal also be capable of checking the active camera? (only active camera is checked, the other arent)
 
 Thanks again for looking inito this
 Bart
          | 
         
        
        
       
      
      Posted By: Bart6
       
      Date Posted: 13 May 2009 at 3:22pm
       
      
        
          
	
(Jimmy - sorry for misspelling your name)
 (I commented m_dwMenuLock & ML_ANY)
 
 I got this to work:
 
 //---------------------------------------------------------------------------
 //
 //---------------------------------------------------------------------------
 //
 void
 CPyroView::OnCamera(NMHDR *pNMHDR,LRESULT *pResult)
 {
      CXTPControl *pControl = ((NMXTPCONTROL *)pNMHDR)->pControl;
     if (pControl)
     {
         ICamera* camera = (ICamera*)pControl->GetTag();
           assert(camera);
           camera->Activate();
     }
 }
 
 //---------------------------------------------------------------------------
 //
 //---------------------------------------------------------------------------
 //
 CXTPControl* CPyroView::GetControl(CCmdUI *pCmdUI)
 {
     if (!pCmdUI->m_pOther)
         return NULL;
     return ((CXTPCommandBar*)pCmdUI->m_pOther)->GetControl(pCmdUI->m_nIndex);
 }
 
 //---------------------------------------------------------------------------
 //
 //---------------------------------------------------------------------------
 //
 void CPyroView::OnUpdateCamera(CCmdUI *pCmdUI)
 {
     //if (m_dwMenuLock & ML_ANY)
     //    pCmdUI->Enable(FALSE);
     //else
     {
         CXTPControl* pControl = GetControl(pCmdUI);
         if (pControl)
         {
             ICamera* camera = (ICamera*) pControl->GetTag();
                ASSERT(camera);
                pCmdUI->SetCheck(camera->IsActive());
                pCmdUI->Enable(camera != NULL);
         }
         else
             pCmdUI->Enable(FALSE);
     }
 }
 
 
 Thanks!
 Bart
          | 
         
        
        
       
      
      Posted By: jimmy
       
      Date Posted: 14 May 2009 at 3:35am
       
      
        
          
	
Hi,
  Sorry forgot to remove this lines. Because i copy some part from our application.
    Jimmy
  
          | 
         
        
        
       
      
     |