Print Page | Close Window

A usage question

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=2650
Printed Date: 08 November 2025 at 4:11pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: A usage question
Posted By: jeffcmj
Subject: A usage question
Date Posted: 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)
{...
if(nID==ID_ADDRESSBOX)
  {
   CMaxAddressCB* pButton = (CMaxAddressCB*)CMaxAddressCB::CreateObject();
   pButton->SetFlags(xtpFlagManualUpdate);
   pButton->SetIconId(ID_ADDRESSBOX);
   pButton->SetDropDownListStyle();
   pButton->SetDefaultText(_T("Input URL here"));
   pButton->SetCaption(_T("Address"));
   pButton->SetWidth(400);
   pButton->SetAutoComplete(0x0e);
   lpCreateControl->pControl = pButton;
   m_pAddressCB = pButton;
   return TRUE;
  }
...
}

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

 




Replies:
Posted By: Oleg
Date 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()
{
  return (CXTPControlComboBox*) GetMainFrame()->GetCommandBars()->FindControl(xtpContr olComboBox, ID_GOTO_URL, FALSE, FALSE);
}

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


Posted By: jeffcmj
Date 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.


Posted By: Oleg
Date Posted: 28 July 2005 at 11:45pm

You can call any function in Update handler:

 

void CMainFrame::OnUpdateEditState(CCmdUI* pCmdUI)
{
 CMaxAddressCB* pStateCombo = DYNAMIC_DOWNCAST(CMaxAddressCB, CXTPControl::FromUI(pCmdUI));

 if (pStateCombo && !pStateCombo->HasFocus())
 {
  pStateCombo->SetDefaultText("New text")

 }

 pCmdUI->Enable(TRUE);
}



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: jeffcmj
Date 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.


Posted By: Oleg
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net