本文整理汇总了C++中CComboBox::SetHorizontalExtent方法的典型用法代码示例。如果您正苦于以下问题:C++ CComboBox::SetHorizontalExtent方法的具体用法?C++ CComboBox::SetHorizontalExtent怎么用?C++ CComboBox::SetHorizontalExtent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComboBox
的用法示例。
在下文中一共展示了CComboBox::SetHorizontalExtent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ShowInPlaceComboBox
CComboBox* CSHListCtrl::ShowInPlaceComboBox(int nItem, int nSubitem,DWORD dwStyle)
{
// The returned pointer should not be saved
// Make sure that the item is visible
// My code start here
if (!EnsureVisible(nItem, TRUE) )
return NULL;
// Make sure that nCol is valid
CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount();
if( nSubitem >= nColumnCount || GetColumnWidth(nSubitem) < 10 )
return NULL;
// Get the column offset
int offset = 0;
for(int i = 0; i < nSubitem; i++)
offset += GetColumnWidth(i);
CRect rect;
GetItemRect(nItem, &rect, LVIR_BOUNDS);
// Now scroll if we need to expose the column
CRect rcClient;
GetClientRect(&rcClient);
if(offset + rect.left < 0 || offset + rect.left > rcClient.right)
{
CSize size;
size.cx = offset + rect.left;
size.cy = 0;
Scroll(size);
rect.left -= size.cx;
}
rect.left += offset;
rect.right = rect.left + GetColumnWidth( nSubitem ) ;
int height = rect.bottom - rect.top;
rect.bottom += 22 * height;
if (rect.right > rcClient.right)
rect.right = rcClient.right;
dwStyle |= WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DISABLENOSCROLL;
CComboBox* pList = new CSHInPlaceComboBox(nItem, nSubitem);
pList->Create(dwStyle, rect, this, IDC_INPLACE_COMBOBOX);
pList->SetItemHeight(-1, height);
pList->SetHorizontalExtent(GetColumnWidth(nSubitem));
CString strWindowText = GetItemText(nItem, nSubitem);
if(dwStyle & CBS_DROPDOWN && !(dwStyle & CBS_DROPDOWNLIST))
{
CEdit* m_pEdit = new CEdit();
m_pEdit->SubclassWindow(pList->GetDlgItem(1001)->GetSafeHwnd());
m_pEdit->SetWindowText(strWindowText);
m_pEdit->SetSel(0,-1);
}
return pList;
// My code end here
}
示例2: UpdateHorzExtent
void UpdateHorzExtent(CComboBox &rctlComboBox, int iIconWidth)
{
int iItemCount = rctlComboBox.GetCount();
if (iItemCount > 0)
{
CDC *pDC = rctlComboBox.GetDC();
if (pDC != NULL)
{
// *** To get *ACCURATE* results from 'GetOutputTextExtent' one *MUST*
// *** explicitly set the font!
CFont *pOldFont = pDC->SelectObject(rctlComboBox.GetFont());
CString strItem;
int iMaxWidth = 0;
for (int i = 0; i < iItemCount; i++)
{
rctlComboBox.GetLBText(i, strItem);
int iItemWidth = pDC->GetOutputTextExtent(strItem, strItem.GetLength()).cx;
if (iItemWidth > iMaxWidth)
iMaxWidth = iItemWidth;
}
pDC->SelectObject(pOldFont);
rctlComboBox.ReleaseDC(pDC);
// Depending on the string (lot of "M" or lot of "i") sometime the
// width is just a few pixels too small!
iMaxWidth += 4;
if (iIconWidth)
iMaxWidth += 2 + iIconWidth + 2;
rctlComboBox.SetHorizontalExtent(iMaxWidth);
if (rctlComboBox.GetDroppedWidth() < iMaxWidth)
rctlComboBox.SetDroppedWidth(iMaxWidth);
}
}
else
rctlComboBox.SetHorizontalExtent(0);
}
示例3: ShowList
CComboBox* CMySuperGrid::ShowList(int nItem, int nCol, CStringList *lstItems)
{
CString strFind = GetItemText(nItem, nCol);
//basic code start
CRect rect;
int offset = 0;
// Make sure that the item is visible
if( !EnsureVisible(nItem, TRUE)) return NULL;
GetSubItemRect(nItem, nCol, LVIR_BOUNDS, rect);
// Now scroll if we need to expose the column
CRect rcClient;
GetClientRect(rcClient);
if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
{
CSize size;
size.cx = offset + rect.left;
size.cy = 0;
Scroll(size);
rect.left -= size.cx;
}
rect.left += offset;
rect.right = rect.left + GetColumnWidth(nCol);
if(rect.right > rcClient.right)
rect.right = rcClient.right;
//basic code end
rect.bottom += 10 * rect.Height();//dropdown area
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL|CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL;
CComboBox *pList = new CComboInListView(nItem, nCol, lstItems);
pList->Create(dwStyle, rect, this, IDC_COMBOBOXINLISTVIEW);
pList->ModifyStyleEx(0,WS_EX_CLIENTEDGE);//can we tell at all
pList->SetHorizontalExtent(CalcHorzExtent(pList, lstItems));
pList->ShowDropDown();
pList->SelectString(-1, strFind.GetBuffer(1));
// The returned pointer should not be saved
return pList;
}