Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Control identifier
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Control identifier

 Post Reply Post Reply
Author
Message
Bart6 View Drop Down
Groupie
Groupie
Avatar

Joined: 22 March 2009
Location: Belgium
Status: Offline
Points: 20
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bart6 Quote  Post ReplyReply Direct Link To This Post Topic: Control identifier
    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
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 515
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 515
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Posted: 13 May 2009 at 2:32pm
Or
pCameraItem->SetTag(  (DWORD_PTR) camera );

ICamera* camera = (ICamera*) pControl->GetTag();

  Jimmy

Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 515
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Bart6 View Drop Down
Groupie
Groupie
Avatar

Joined: 22 March 2009
Location: Belgium
Status: Offline
Points: 20
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bart6 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Bart6 View Drop Down
Groupie
Groupie
Avatar

Joined: 22 March 2009
Location: Belgium
Status: Offline
Points: 20
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bart6 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 515
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 2009 at 3:35am
Hi,

Sorry forgot to remove this lines.
Because i copy some part from our application.

  Jimmy

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.157 seconds.