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

CXTPControlComboBox width

 Post Reply Post Reply
Author
Message
Bala View Drop Down
Newbie
Newbie


Joined: 31 January 2008
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bala Quote  Post ReplyReply Direct Link To This Post Topic: CXTPControlComboBox width
    Posted: 09 July 2008 at 11:09am
Hi,
 
We are using CXTPControlComboBox object and setting up a standard width based on the string size that we are adding.
But on multi byte langauges ( japanese/chinese) our math of setting width doesnot hold up....a few chars are trucated in the display.
 
Here is how our display looks like...
 
 
 
Is there an auto width property on the CXTPControlComboBox? or should we be getting the font width and number of chars do the math and come up with the width??
 
Regards,
Bala
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Posted: 09 July 2008 at 11:11am
Hi,

int CExResizeDialog::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
{
    if (lpCreateControl->bToolBar)
    {
        CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
        if (!pToolBar)
            return FALSE;

        if (lpCreateControl->nID == ID_GUI_ONLINECURRENT && pToolBar->GetBarID() == IDR_GUI_ONLINESETTINGS)
        {
            CXTPControlComboBox* pComboState = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
            pComboState->SetCaption(_T("Online"));
            pComboState->SetWidth(180);
            pComboState->SetDropDownWidth(220);
            pComboState->SetDropDownItemCount(30);
            lpCreateControl->pControl = pComboState;
            return TRUE;
        }
    }
    return FALSE;
}

  Jimmy

Back to Top
Bala View Drop Down
Newbie
Newbie


Joined: 31 January 2008
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bala Quote  Post ReplyReply Direct Link To This Post Posted: 09 July 2008 at 12:35pm
Thanks for your response.looks like you have hard coded value of 180.
 
we are also calling SetWidth
 
But I would like to know what value to set..
 
for ex:- we have a string called "Samrt priority" in english ...and it may be different in chinese.....so how do we come up with the width.
 
One way is to get the string length and multiply by average font width.
 
I am trying to see - if codejock has a special flag called "autowidth" on the combo box.    ---ie'; combo box width adjusts based on the string added and font. - instead of users having to specify it...
 
Regards,
Bala
 
 
Back to Top
Smucker View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 February 2008
Status: Offline
Points: 156
Post Options Post Options   Thanks (0) Thanks(0)   Quote Smucker Quote  Post ReplyReply Direct Link To This Post Posted: 09 July 2008 at 2:16pm
Here's the basic code I use:

  int cwidth = 0;
  pcombo->ResetContent();
  CDC *pdc = pcombo->GetEditCtrl()->GetDC();
  for (each CString strval you add)
  {
    pcombo->AddString(strval);
    int w = pdc->GetTextExtent(strval).cx;
    if (w > cwidth)
      cwidth = w;
  }
  pcombo->GetEditCtrl()->ReleaseDC(pdc);
  pcombo->SetDropDownWidth(max(pcombo->GetWidth(), cwidth)); // **


** - you may want to constrain cwidth to a reasonable range.

Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)

Back to Top
Bala View Drop Down
Newbie
Newbie


Joined: 31 January 2008
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bala Quote  Post ReplyReply Direct Link To This Post Posted: 09 July 2008 at 3:01pm
Thanks Smucker! I plugged in the logic and works great in german,french,chinese,english...etc
I had to substitute GetEditCtrl with GetListBoxCtrl - since our ctrl is of type list box
 
May be for next release - codejock could support this property - 'autowidth' and do this math - instead of every customer setting the width.
 
Regards,
Bala
Back to Top
Smucker View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 February 2008
Status: Offline
Points: 156
Post Options Post Options   Thanks (0) Thanks(0)   Quote Smucker Quote  Post ReplyReply Direct Link To This Post Posted: 09 July 2008 at 3:41pm
Here's a more accurate version that handles the font size and borders/scroll width correctly. New code/changed code in green:

  int cwidth = 0;
  CFont cfont;
  CDC *pdc = pcombo->GetListBoxCtrl()->GetDC();
  CFont *pfont = pcombo->GetListBoxCtrl()->GetFont();
  if (!pfont) {
    cfont.CreateStockObject(DEFAULT_GUI_FONT);
    pfont = &cfont;
  }
  pdc->SaveDC();
  pdc->SelectObject(pfont);

  pcombo->ResetContent();
  for (each CString strval you add)
  {
    pcombo->AddString(strval);
    int w = pdc->GetTextExtent(strval).cx;
    if (w > cwidth)
      cwidth = w;
  }
  CXTNonClientMetrics ncm;
  cwidth += ncm.iBorderWidth * 2 + ncm.iScrollWidth;
  pdc->RestoreDC(-1);
  pcombo->GetListBoxCtrl()->ReleaseDC(pdc);
  pcombo->SetDropDownWidth(max(pcombo->GetRect().Width(), cwidth));

Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)

Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Posted: 10 July 2008 at 6:45am
Will be nice to support Markup into ListBox

  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.063 seconds.