![]() |
A usage question |
Post Reply
|
| Author | |
jeffcmj
Groupie
Joined: 28 October 2004 Status: Offline Points: 92 |
Post Options
Thanks(0)
Quote Reply
Topic: A usage questionPosted: 28 July 2005 at 1:37am |
|
Hi, I have a customized Combobox in my program which is derived in XTP's combobox. And I have the following code: int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) You see I use m_pAddressCB to hold the pointer to my control. It worked most of the time. But, if I go into the customization mode and customized the combobox(eg, drag it a bit longer), then next time when I start my program, I found the m_pAddressCB does not point to the real combobox used in the problem. I think it's because of the LoadCommandBar function of XTP but I don't know what's the best way to avoid it. Please advise. Thanks
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 28 July 2005 at 12:59pm |
|
It is bad design to use saved pointer. You right - user can remove this control or copuit to another toolbar.
So solution 1 (bad) to find pointer each time you need to set/get text: CXTPControlComboBox* GetAddressCombo() solution 2 (good) Update text in Update Handler (see any sample with combobox) as result if user copy it to another toolbar, they both will be updated. |
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
jeffcmj
Groupie
Joined: 28 October 2004 Status: Offline Points: 92 |
Post Options
Thanks(0)
Quote Reply
Posted: 28 July 2005 at 9:56pm |
|
But in my case it not only updating the text? I want to call some functions in my derived control.
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 28 July 2005 at 11:45pm |
|
You can call any function in Update handler:
void CMainFrame::OnUpdateEditState(CCmdUI* pCmdUI) if (pStateCombo && !pStateCombo->HasFocus()) } pCmdUI->Enable(TRUE); |
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
jeffcmj
Groupie
Joined: 28 October 2004 Status: Offline Points: 92 |
Post Options
Thanks(0)
Quote Reply
Posted: 04 August 2005 at 7:46pm |
|
Will there be any performance reduce if I put a lot of code in UpdateUI handler? Since this function is called very often.
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 05 August 2005 at 11:30pm |
|
a lot of code will be not good. Why you need executed all code each time? For example If you need to fill ComboBox from Array of strings, add "if block" to check that size of array was changed:
void CMainFrame::OnUpdateFileOpen(CCmdUI* pCmdUI){ CXTPControlComboBox* pControl = DYNAMIC_DOWNCAST(CXTPControlComboBox, CXTPControl::FromUI(pCmdUI)); if (pControl && !pControl->HasFocus()){ if (pControl->GetCount() != m_arrResources.GetSize()){ pControl->ResetContent(); for (int i = 0; i < m_arrResources.GetSize(); i++){ pControl->AddString(m_arrResources.strLanguage); } } int nCurSel = -1;CDocument* pDocument = GetActiveFrame()->GetActiveDocument(); if (pDocument){ CString strPath = pDocument->GetPathName(); for (int i = 0; i < m_arrResources.GetSize(); i++){ if (m_arrResources.strPath == strPath){ nCurSel = i; break;} } } pControl->SetCurSel(nCurSel); } } |
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |