Print Page | Close Window

CXTPControlComboBox width

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=11364
Printed Date: 15 November 2025 at 9:09am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPControlComboBox width
Posted By: Bala
Subject: CXTPControlComboBox width
Date 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



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



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


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



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


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



Posted By: jimmy
Date Posted: 10 July 2008 at 6:45am
Will be nice to support Markup into ListBox

  Jimmy




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