Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - A usage question
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

A usage question

 Post Reply Post Reply
Author
Message
jeffcmj View Drop Down
Groupie
Groupie


Joined: 28 October 2004
Status: Offline
Points: 92
Post Options Post Options   Thanks (0) Thanks(0)   Quote jeffcmj Quote  Post ReplyReply Direct Link To This Post Topic: A usage question
    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

 

Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jeffcmj View Drop Down
Groupie
Groupie


Joined: 28 October 2004
Status: Offline
Points: 92
Post Options Post Options   Thanks (0) Thanks(0)   Quote jeffcmj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jeffcmj View Drop Down
Groupie
Groupie


Joined: 28 October 2004
Status: Offline
Points: 92
Post Options Post Options   Thanks (0) Thanks(0)   Quote jeffcmj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
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.031 seconds.