|
e.g "&T" is replaced by "T"
Here is a patch see DT_NOPREFIX in the line const UINT format = DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX:
Index: ComboBoxSuper.cpp
===================================================================
--- ComboBoxSuper.cpp (revision 36953)
+++ ComboBoxSuper.cpp (working copy)
@@ -136,6 +136,8 @@
dc.SetTextColor(pItemData->m_vecTextColor[0]);
}
+ const UINT format = DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX;
+
if (m_vecColumnWidth.size()>1)
{
@@ -149,7 +151,7 @@
if (i==0)
{
- dc.DrawText(str, -1, &rcText, m_vecColumnFormat[i]|DT_SINGLELINE|DT_VCENTER);
+ dc.DrawText(str, -1, &rcText, m_vecColumnFormat[i] | format);
rect.left -= nImageWidth;
if ( pItemData->m_vecBold[i] )
@@ -174,7 +176,7 @@
boldFont2.CreateFontIndirect(&lf);
pOldFont2 = dc.SelectObject(&boldFont2);
}
- dc.DrawText(pItemData->mapStrings[x64workaround::staticcast<int>(i)], -1, &rcText, m_vecColumnFormat[i] | DT_SINGLELINE | DT_VCENTER);
+ dc.DrawText(pItemData->mapStrings[x64workaround::staticcast<int>(i)], -1, &rcText, m_vecColumnFormat[i] | format);
if ( pItemData->m_vecBold[i] )
{
dc.SelectObject(pOldFont2);
@@ -196,7 +198,7 @@
else
{
- dc.DrawText(str, -1, &rect, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
+ dc.DrawText(str, -1, &rect, DT_LEFT | format);
}
if (pItemData && pItemData->m_vecBold[0])
Andreas.
|
|
|
|
|
I tried numerous combo box column implementations, this is the only one that works properly. I added an additional method to calculate the column sizes and thought I'd share it here in case someone is interested. You only need to call it once after all strings have been added.
void CComboBoxSuper::AutoAdjustDropdownWidth()
{
if (!GetSafeHwnd() || !::IsWindow(GetSafeHwnd()))
{
ASSERT(FALSE);
return;
}
CDC& ComboDC = *GetDC();
const int RestorePoint = ComboDC.SaveDC();
CFont& ComboFont = *GetFont();
ComboDC.SelectObject(&ComboFont);
const int iColumns = m_vecColumnWidth.size();
for (int i=0; i < iColumns; i++)
m_vecColumnWidth[i] = 0;
CString str;
CString strMax;
int n;
SIZE sz;
for (int i = 0; i < GetCount(); i++)
{
n = GetLBTextLen(i);
GetLBText(i, str.GetBuffer(n));
str.ReleaseBuffer();
sz = ComboDC.GetTextExtent(str);
if (sz.cx > m_vecColumnWidth[0])
{
m_vecColumnWidth[0] = sz.cx;
strMax = str;
}
for (int j = 1; j < iColumns; j++)
{
ItemData* pItemData = GetOrCreateItemData(i);
if (pItemData)
{
str = pItemData->mapStrings[j];
sz = ComboDC.GetTextExtent(str);
if (sz.cx > m_vecColumnWidth[j])
m_vecColumnWidth[j] = sz.cx;
}
}
}
int j = 0;
for (int i=0; i < iColumns; i++)
{
j += m_vecColumnWidth[i];
}
if (j > 0)
{
const int ScrollWidth = ::GetSystemMetrics(SM_CXVSCROLL);
SetDroppedWidth(j + ScrollWidth * 2);
}
ComboDC.RestoreDC(RestorePoint);
}
|
|
|
|
|
|
Auto Size Implementation
MaskedComboBox.cpp
#include "stdafx.h"
#include "MaskedComboBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CMaskedComboBox::CMaskedComboBox()
{
m_bAutoAlign = true;
m_rgbBorderColor = RGB(192,192,192);
m_rgbMaskColor = RGB(192,192,192);
m_rgbIDColor = RGB(0,0,0);
m_rgbDescColor = RGB(0,0,0);
}
CMaskedComboBox::CMaskedComboBox(char MaskChar)
{
m_MaskChar.Format(" %c ",MaskChar);
}
CMaskedComboBox::CMaskedComboBox(CString csMaskChar)
{
m_MaskChar= csMaskChar;
}
CMaskedComboBox::~CMaskedComboBox()
{
_DumpMemory();
m_MaskChar.ReleaseBuffer();
}
BEGIN_MESSAGE_MAP(CMaskedComboBox, CComboBox)
END_MESSAGE_MAP()
void CMaskedComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
try
{
if((lpDrawItemStruct->itemState & ODS_SELECTED)) {
CDC dc;
if(dc.Attach(lpDrawItemStruct->hDC) )
{
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
if ((lpDrawItemStruct->itemAction | ODA_SELECT) || (lpDrawItemStruct->itemAction | ODA_FOCUS) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetBkMode(OPAQUE);
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
}
if(m_nMaxDropListWidth ==0 )
m_nMaxDropListWidth = GetDroppedWidth();
SIZE sz;
GetTextExtentPoint32(dc.GetSafeHdc(),m_csMaxWidthCombined,m_csMaxWidthCombined.GetLength(),&sz);
if(m_nMaxDropListWidth < sz.cx )
{
m_nMaxDropListWidth = sz.cx;
SetDroppedWidth(m_nMaxDropListWidth+50);
}
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
}
if (GetCount() == 0 || lpDrawItemStruct->itemID > (unsigned int)GetCount())
return;
if((lpDrawItemStruct->itemID ==0) && lpDrawItemStruct->itemData == NULL)
{
CDC dc;
if(dc.Attach(lpDrawItemStruct->hDC))
{
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetBkMode(OPAQUE);
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
}
if(m_nMaxDropListWidth ==0 )
m_nMaxDropListWidth = GetDroppedWidth();
SIZE sz;
GetTextExtentPoint32(dc.GetSafeHdc(),m_csMaxWidthCombined,m_csMaxWidthCombined.GetLength(),&sz);
if(m_nMaxDropListWidth < sz.cx )
{
m_nMaxDropListWidth = sz.cx;
SetDroppedWidth(m_nMaxDropListWidth+50);
}
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
return;
}
}
if (lpDrawItemStruct->itemData == NULL)
return;
else
{
ComboBoxItemData* pItemData = NULL;
pItemData = (ComboBoxItemData *)lpDrawItemStruct->itemData;
CDC dc;
if(dc.Attach(lpDrawItemStruct->hDC))
{
SIZE Size;
int nMaxWidth;
CPen* pOldPen;
if(m_nMaxDropListWidth ==0 )
m_nMaxDropListWidth = GetDroppedWidth();
SIZE sz;
GetTextExtentPoint32(dc.GetSafeHdc(),m_csMaxWidthCombined,m_csMaxWidthCombined.GetLength(),&sz);
if(m_nMaxDropListWidth < sz.cx )
{
m_nMaxDropListWidth = sz.cx;
SetDroppedWidth(m_nMaxDropListWidth+50);
}
if(m_bAutoAlign)
{
GetTextExtentPoint32(dc.GetSafeHdc(),m_MaxLengthData,m_MaxLengthData.GetLength(),&Size);
nMaxWidth = Size.cx;
}
else
{
nMaxWidth = 0;
}
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetBkMode(OPAQUE);
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
m_rgbIDColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
m_rgbDescColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
m_rgbIDColor = ::GetSysColor(COLOR_MENUTEXT);
m_rgbDescColor = ::GetSysColor(COLOR_MENUTEXT);
}
if(lpDrawItemStruct->itemAction >= 0x1)
{
CRect rect(lpDrawItemStruct->rcItem);
rect.DeflateRect(1,0);
CRect rc(rect);
COLORREF cr;
rc.left +=1;
rc.bottom -=1;
cr = dc.SetTextColor(m_rgbIDColor);
dc.DrawText(pItemData->cs_ID, -1, &rc, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
dc.SetTextColor(cr);
if( m_bAutoAlign && GetDroppedState())
{
rc.left = nMaxWidth + 10;
}
else
{
GetTextExtentPoint32(dc.GetSafeHdc(),pItemData->cs_ID,pItemData->cs_ID.GetLength(),&Size);
rc.left = Size.cx + 10;
}
if(!pItemData->cs_ID.IsEmpty())
{
if((m_MaskChar == "" || m_MaskChar.IsEmpty()))
{
CPen maskStyle(PS_SOLID, 0, m_rgbMaskColor);
pOldPen = dc.SelectObject(&maskStyle);
dc.MoveTo(rc.left,rc.top);
dc.LineTo(rc.left,rc.bottom+1);
dc.SelectObject(pOldPen);
rc.left +=2;
}
else
{
COLORREF cr = dc.SetTextColor(m_rgbMaskColor);
dc.DrawText(m_MaskChar, &rc, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
dc.SetTextColor(cr);
rc.left +=2;
}
}
rc.left += 3;
cr = dc.SetTextColor(m_rgbDescColor);
dc.DrawText(pItemData->cs_Desc , -1, &rc, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
dc.SetTextColor(cr);
if(lpDrawItemStruct->itemState != 0x11 && lpDrawItemStruct->itemState !=0x1000 &&
lpDrawItemStruct->itemState !=0x1300 ) {
CPen linePen(PS_SOLID, 0, m_rgbBorderColor);
CRect ct = CRect(lpDrawItemStruct->rcItem);
pOldPen = dc.SelectObject(&linePen);
dc.MoveTo(ct.left,ct.bottom);
dc.LineTo(ct.right,ct.bottom);
dc.MoveTo(ct.left,ct.top);
dc.LineTo(ct.right,ct.top);
dc.SelectObject(pOldPen);
}
}
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
}
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
catch( ... )
{
}
}
int CMaskedComboBox::AddString(CString csString)
{
int nRet = -1;
try
{
if(m_MaxLengthData.GetLength() >= csString.GetLength())
m_MaxLengthData = csString;
if(m_csMaxWidthCombined.GetLength() <= csString.GetLength())
m_csMaxWidthCombined = csString;
nRet = CComboBox::AddString(csString.GetBuffer(csString.GetLength()));
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
catch( ... )
{
}
return nRet;
}
int CMaskedComboBox::AddCode(CString csID, CString csDesc, int nIntData)
{
int nIndex = -1;
try
{
{
if(m_MaxLengthData.GetLength() <= csID.GetLength())
m_MaxLengthData = csID;
if(m_csMaxWidthCombined.GetLength() <= csID.GetLength() + csDesc.GetLength())
m_csMaxWidthCombined = csID + csDesc;
nIndex=CComboBox::AddString(csID.GetBuffer(csID.GetLength()));
switch(nIndex)
{
case CB_ERRSPACE:
case CB_ERR:
nIndex = -1;
break;
default:
ComboBoxItemData *pItemData = new ComboBoxItemData();
m_pDataList.AddTail(pItemData);
pItemData->cs_ID = csID;
pItemData->cs_Desc = csDesc;
pItemData->nIntData = nIntData;
CComboBox::SetItemDataPtr(nIndex,pItemData);
}
}
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
catch( ... )
{
}
return nIndex;
}
CString CMaskedComboBox::GetCode(int nIndex, int nWhichCode) const
{
CString csRet="";
try
{
switch(nIndex)
{
case CB_ERR:
break; default:
switch(nWhichCode)
{
case 1: csRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->cs_ID;break;
case 2: csRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->cs_Desc;break;
default: csRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->cs_ID;
}
}
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
catch( ... )
{
}
return csRet;
}
int CMaskedComboBox::GetIntCode(int nIndex) const
{
int nRet = -1;
try
{
switch(nIndex)
{
case CB_ERR:
nRet = -1;
break; default:
nRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->nIntData;
}
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
catch( ... )
{
}
return nRet;
}
CString CMaskedComboBox::GetID(int nIndex) const
{
return GetCode(nIndex);
}
CString CMaskedComboBox::GetCurSelectedID() const
{
int nIndex = GetCurSel();
return GetCode(nIndex);
}
CString CMaskedComboBox::GetDesc(int nIndex) const
{
return GetCode(nIndex,2);
}
CString CMaskedComboBox::GetCurSelectedDesc() const
{
int nIndex = GetCurSel();
return GetCode(nIndex,2);
}
int CMaskedComboBox::GetIntData(int nIndex) const
{
return GetIntCode(nIndex);
}
int CMaskedComboBox::GetCurSelectedIntData() const
{
int nIndex = GetCurSel();
return GetIntCode(nIndex);
}
void CMaskedComboBox::_DumpMemory()
{
try
{
while( !m_pDataList.IsEmpty() )
{
ComboBoxItemData * pDumpData = m_pDataList.RemoveHead();
try {
if(pDumpData != NULL)
{
delete pDumpData;
}
}
catch( ... )
{
} }
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
}
void CMaskedComboBox::Cleanup()
{
_DumpMemory();
CComboBox::ResetContent();
CComboBox::Clear();
m_MaxLengthData = "";
}
int CMaskedComboBox::DeleteCode(int nIndex)
{
int nRet = -1;
try
{
int nCount = CComboBox::GetCount();
if(nCount <= 0) return -1;
if(nIndex >=0 && nIndex < GetCount())
{
delete (ComboBoxItemData *)(CComboBox::GetItemDataPtr(nIndex));
}
nRet = CComboBox::DeleteString(nIndex);
CWnd::Invalidate();
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
catch( ... )
{
}
return nRet;
}
void CMaskedComboBox::ResetContent()
{
Cleanup();
}
void CMaskedComboBox::DeleteAll()
{
Cleanup();
}
void CMaskedComboBox::Clear()
{
Cleanup();
}
void CMaskedComboBox::CleanUp()
{
Cleanup();
}
BOOL CMaskedComboBox::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_CHAR)
{
try
{
if(pMsg->wParam == 0x3) {
CString csClipData = this->GetCurSelectedID()+" | "+this->GetCurSelectedDesc();
if (OpenClipboard())
{
EmptyClipboard();
HGLOBAL hClipboardData;
hClipboardData = GlobalAlloc(GMEM_DDESHARE,csClipData.GetLength()+1);
char * pchData;
pchData = (char*)GlobalLock(hClipboardData);
strcpy(pchData, LPCSTR(csClipData));
GlobalUnlock(hClipboardData);
SetClipboardData(CF_TEXT,hClipboardData);
CloseClipboard();
}
}
else if (!GetDroppedState() && pMsg->wParam != VK_RETURN && pMsg->wParam != VK_ESCAPE )
ShowDropDown();
}
catch( CMemoryException* e )
{
e->Delete();
}
catch( CFileException* e )
{
e->Delete();
}
catch( CException* e )
{
e->Delete();
}
catch( ... )
{
}
}
return CComboBox::PreTranslateMessage(pMsg);
}
MaskedComboBox.h
#if !defined(AFX_MASKEDCOMBOBOX_H__32482D69_64C2_4FFF_8820_E4AEB41E83EE__INCLUDED_)
#define AFX_MASKEDCOMBOBOX_H__32482D69_64C2_4FFF_8820_E4AEB41E83EE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxtempl.h>
struct ComboBoxItemData
{
CString cs_ID;
CString cs_Desc;
int nIntData;
ComboBoxItemData()
{
cs_ID="";
cs_Desc="";
nIntData=-1;
}
~ComboBoxItemData()
{
#ifdef _DEBUG
OutputDebugString("\nDumping Memory - "+cs_ID+"\n");
#endif
cs_ID.ReleaseBuffer();
cs_Desc.ReleaseBuffer();
}
};
class CMaskedComboBox : public CComboBox
{
public:
CMaskedComboBox();
CMaskedComboBox(char MaskChar);
CMaskedComboBox(CString csMaskChar);
public:
CList <ComboBoxItemData * , ComboBoxItemData*> m_pDataList;
public:
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
public:
void CleanUp();
COLORREF m_rgbDescColor;
COLORREF m_rgbIDColor;
COLORREF m_rgbBorderColor;
COLORREF m_rgbMaskColor;
bool m_bAutoAlign;
int AddString(CString csString);
void Clear();
void Cleanup();
void ResetContent();
void DeleteAll();
int DeleteCode(int Index);
CString GetID(int nIndex) const;
CString GetDesc(int nIndex) const;
CString GetCurSelectedID() const;
CString GetCurSelectedDesc() const;
int GetIntData(int nIndex) const;
int GetIntCode(int nIndex) const;
int GetCurSelectedIntData() const;
int AddCode(CString csID,CString csDesc,int nIntData = -1);
CString GetCode(int nIndex,int nWhichCode = 1) const;
CString m_csMaxWidthCombined;
virtual ~CMaskedComboBox();
protected:
int m_nMaxDropListWidth;
void _DumpMemory();
CString m_MaxLengthData;
CString m_MaskChar;
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
DECLARE_MESSAGE_MAP()
};
#endif // !defined(AFX_MASKEDCOMBOBOX_H__32482D69_64C2_4FFF_8820_E4AEB41E83EE__INCLUDED_)
Feel free to enter your comments for the above implemetation
S.V.Rajkumar
|
|
|
|
|
GetTextExtentPoint32 API can help you to implement Auto size functionality.
S.V.Rajkumar
|
|
|
|
|
I spent some time on this and read through this article, responses and MSDN. My requirement was to have a combo with text where each will have its own background color (the text was the color name). At the end, i was able to make the code work and add a background color to the DataItem structure. What i found out, was that the following is missing to make this work:
- The window style for creating the supercombo should include the CBS_OWNERDRAWFIXED and CBS_HASSTRINGS styles. If you set the style to CBS_DROPDOWN once an item is selected from the list and the drop down goes away, the selected item's background does not get show on the selected item. So, here is what i used for the SuperCombo's create:
<pre lang="c++"> Create(WS_CHILD|WS_VISIBLE|WS_BORDER|CBS_DROPDOWNLIST|
WS_VSCROLL|CBS_OWNERDRAWFIXED|CBS_HASSTRINGS,
rCtrl,this,IDC_SELECT_HIGHLIGHT_COLORS);
obj->SetCurSel(0) would throw the app into an infinite loop when CBS_DROPDOWN was the style rather than the CBS_DROPDOWNLIST. But this may have been a result of my coding errors.
- The order of calls is important, i.e. you have to use AddString before the SetItemxx method would work. You can also work around this but i did not do that.
Thanks for good work Ron Hash and others!
Cheers!
bramoin
|
|
|
|
|
What license is this source released under?
|
|
|
|
|
Is there a way to change the color of the dropdown button on the combo-box?
|
|
|
|
|
I've tried & tried but I just can't get it to work. The only thing I see different between my dialog and the one in the sample is that mine is in a DLL. Running in Debug, the CComboBoxSuper constructor gets hit but I cannot get it to hit CComboBoxSuper::DrawItem(). I have set the combobox to Owner Draw Fixed & Has Strings.
I get the same problem with Alex Hazanov's ComboBoxBold class. Any ideas?
|
|
|
|
|
I knew it had to be a simple problem:
WM_DRAWITEM was being handled in the dialog class so my combobox drawitem() was not getting called.
|
|
|
|
|
I tryed importin the files h and cpp
but there were a lot of problems.
Is there any possibility to have an updated code?
thnks.
F
|
|
|
|
|
I have some question for using "super combo box".
While I was programing, I found that "GetOrCreateItemData" had a bug.
In "GetOrCreateItemData" function, error happened when I used below program coding.
m_cmbDatePicker.AddString("A0088");<br />
m_cmbDatePicker.SetItemText(i++,1,"itkim");<br />
m_cmbDatePicker.AddString("A0032");<br />
m_cmbDatePicker.SetItemText(i++,1,"nisung");<br />
m_cmbDatePicker.AddString("A0053");<br />
m_cmbDatePicker.SetItemText(i++,1,"kskim");
However following codings works.
m_cmbDatePicker.AddString("A01");<br />
m_cmbDatePicker.SetItemText(i++,1,"bwhan");
|
|
|
|
|
Hello,
I get the following errors if compiling with VS2005 (default settings) after automatically conversion of the old project to the new format:
comboboxsuper.h(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
comboboxsuper.h(45) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
SuperComboDemoDlg.cpp
comboboxsuper.h(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
comboboxsuper.h(45) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
because there is no type specified for DEFAULT_COLUMN_COUNT and DEFAULT_COLUMN_WIDTH.
After setting this to int (in the header and the cpp file) I get the following errors:
SuperComboDemo.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CComboBoxSuper::~CComboBoxSuper(void)" (??1CComboBoxSuper@@UAE@XZ) referenced in function "public: virtual __thiscall CSuperComboDemoDlg::~CSuperComboDemoDlg(void)" (??1CSuperComboDemoDlg@@UAE@XZ)
SuperComboDemoDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CComboBoxSuper::~CComboBoxSuper(void)" (??1CComboBoxSuper@@UAE@XZ)
SuperComboDemoDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall CComboBoxSuper::CComboBoxSuper(void)" (??0CComboBoxSuper@@QAE@XZ) referenced in function "public: __thiscall CSuperComboDemoDlg::CSuperComboDemoDlg(class CWnd *)" (??0CSuperComboDemoDlg@@QAE@PAVCWnd@@@Z)
SuperComboDemoDlg.obj : error LNK2019: unresolved external symbol "public: void __thiscall CComboBoxSuper::SetItemImage(int,int)" (?SetItemImage@CComboBoxSuper@@QAEXHH@Z) referenced in function "protected: virtual int __thiscall CSuperComboDemoDlg::OnInitDialog(void)" (?OnInitDialog@CSuperComboDemoDlg@@MAEHXZ)
SuperComboDemoDlg.obj : error LNK2019: unresolved external symbol "public: void __thiscall CComboBoxSuper::SetItemText(int,int,class ATL::CStringT<char,class strtraitmfc_dll<char,class="" atl::chtraitscrt<char=""> > >)" (?SetItemText@CComboBoxSuper@@QAEXHHV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "protected: virtual int __thiscall CSuperComboDemoDlg::OnInitDialog(void)" (?OnInitDialog@CSuperComboDemoDlg@@MAEHXZ)
SuperComboDemoDlg.obj : error LNK2019: unresolved external symbol "public: void __thiscall CComboBoxSuper::SetItemColor(int,unsigned long)" (?SetItemColor@CComboBoxSuper@@QAEXHK@Z) referenced in function "protected: virtual int __thiscall CSuperComboDemoDlg::OnInitDialog(void)" (?OnInitDialog@CSuperComboDemoDlg@@MAEHXZ)
SuperComboDemoDlg.obj : error LNK2019: unresolved external symbol "public: void __thiscall CComboBoxSuper::SetItemBold(int,int)" (?SetItemBold@CComboBoxSuper@@QAEXHH@Z) referenced in function "protected: virtual int __thiscall CSuperComboDemoDlg::OnInitDialog(void)" (?OnInitDialog@CSuperComboDemoDlg@@MAEHXZ)
SuperComboDemoDlg.obj : error LNK2019: unresolved external symbol "public: void __thiscall CComboBoxSuper::SetColumnWidth(int,int)" (?SetColumnWidth@CComboBoxSuper@@QAEXHH@Z) referenced in function "protected: virtual int __thiscall CSuperComboDemoDlg::OnInitDialog(void)" (?OnInitDialog@CSuperComboDemoDlg@@MAEHXZ)
SuperComboDemoDlg.obj : error LNK2019: unresolved external symbol "public: void __thiscall CComboBoxSuper::SetColumnCount(int)" (?SetColumnCount@CComboBoxSuper@@QAEXH@Z) referenced in function "protected: virtual int __thiscall CSuperComboDemoDlg::OnInitDialog(void)" (?OnInitDialog@CSuperComboDemoDlg@@MAEHXZ)
.\Debug/SuperComboDemo.exe : fatal error LNK1120: 8 unresolved externals
This is because of the missing ComboBoxSuper.cpp and .h file in the project.
After fixing this I get the following warnings:
comboboxsuper.cpp(46) : warning C4018: '>' : signed/unsigned mismatch
comboboxsuper.cpp(124) : warning C4018: '<' : signed/unsigned mismatch
comboboxsuper.cpp(262) : warning C4018: '>=' : signed/unsigned mismatch
comboboxsuper.cpp(341) : warning C4018: '<' : signed/unsigned mismatch
Regards,
Andreas.
|
|
|
|
|
Add files(.h, .cpp) in your project
|
|
|
|
|
Hello,
I already wrote how to fix this problem in my first posting, you don't have to repeat this.
Kind regards,
Andreas.
|
|
|
|
|
Can this be used with VB.Net/ASP.Net?
|
|
|
|
|
Hello all,
I added the functionality of disabled items by combining this code with the code from the article "CComboBox with disabled items" by Petr Novotny.
To clearly visualise the difference between enabled and disabled rows, I set the background to grey (180,180,180) for disabled rows.
The only problem I ran into, was that for items that are added by AddString, without setting special looks like bold, icon,... , the pItemData pointer is NULL.
To solve this, I call the GetOrCreateItemData function at the beginning of DrawItem for items that have a null pItemData pointer.
I have added below the section of code I changed in DrawItem (changes are in bold)
To the author: is it an idea to publish my changed version as an update of your project?
Kind regards,
Patrick Pasteels
....
Code fragment:
if (GetCount() == 0 || lpDrawItemStruct->itemID > GetCount()) return;
CString str;
GetLBText(lpDrawItemStruct->itemID, str);
CDC dc;
BOOL bSelected = FALSE;
ItemData* pItemData = NULL;
if (lpDrawItemStruct->itemData!=NULL)
{
pItemData = (ItemData*)lpDrawItemStruct->itemData;
}
else
{
pItemData = this->GetOrCreateItemData(lpDrawItemStruct->itemID);
}
dc.Attach(lpDrawItemStruct->hDC);
// Save these value to restore them when done drawing.
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
COLORREF selectedcolor;
// If this item is selected, set the background color and the text color to appropriate
// values. Erase the rect by filling it with the background color.
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED) && pItemData)
{
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
if (!IsItemEnabled(lpDrawItemStruct->itemID)) // function from the CComboBox with disabled items project
selectedcolor = RGB(180,180,180); // disabled items have a grey background when selected
else
selectedcolor = GetSysColor(COLOR_HIGHLIGHT);
dc.SetBkColor(selectedcolor);
dc.FillSolidRect(&lpDrawItemStruct->rcItem, selectedcolor); bSelected = TRUE;
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
}
|
|
|
|
|
Hi Patrick,
Thanks for the nice feature.
I will updated the article as soon as my work will allow me...
Ron.
|
|
|
|
|
Is there a way to control the background color ?
|
|
|
|
|
OK, I have made some small extensions in ComboBoxSuper.h and ComboBoxSuper.cpp to set the backgroundcolor.
Change in ComboBoxSuper.h:
<br />
struct ItemData<br />
{<br />
ItemData() : crTextColor(RGB(0,0,0)),nImageIndex(-1),bBold(FALSE){}<br />
COLORREF crTextColor;<br />
int nImageIndex;<br />
std::map<int,CString> mapStrings;<br />
BOOL bBold;<br />
DWORD dwItemData;<br />
};<br />
<br />
<br />
<br />
void SetItemColor(int nItemIndex, COLORREF rcTextColor);<br />
<br />
to
<br />
struct ItemData<br />
{<br />
ItemData() : crTextColor(RGB(0,0,0)), crBkColor(RGB(255,255,255)),nImageIndex(-1),bBold(FALSE){}<br />
COLORREF crTextColor, crBkColor;<br />
int nImageIndex;<br />
std::map<int,CString> mapStrings;<br />
BOOL bBold;<br />
DWORD dwItemData;<br />
};<br />
<br />
<br />
<br />
void SetItemColor(int nItemIndex, COLORREF crTextColor, COLORREF crBkColor);<br />
<br />
Change in ComboBoxSuper.cpp:
<br />
<br />
if (pItemData && (!bSelected || (bSelected && pItemData->crTextColor != RGB(0,0,0))))<br />
{<br />
dc.SetTextColor(pItemData->crTextColor);<br />
}<br />
<br />
<br />
void CExtendedComboBox::SetItemColor(int nItemIndex, COLORREF rcTextColor)<br />
{<br />
ItemData* pItemData = GetOrCreateItemData(nItemIndex);<br />
if (pItemData)<br />
{<br />
pItemData->crTextColor = rcTextColor;<br />
Invalidate();<br />
}<br />
}<br />
<br />
to
<br />
if (pItemData && (!bSelected || (bSelected && pItemData->crTextColor != RGB(0,0,0))))<br />
{<br />
dc.SetTextColor(pItemData->crTextColor); <br />
}<br />
<br />
if (pItemData && !bSelected)<br />
{<br />
dc.FillSolidRect(&lpDrawItemStruct->rcItem, pItemData->crBkColor);<br />
}<br />
<br />
<br />
void CExtendedComboBox::SetItemColor(int nItemIndex, COLORREF crTextColor, COLORREF crBkColor)<br />
{<br />
ItemData* pItemData = GetOrCreateItemData(nItemIndex);<br />
if (pItemData)<br />
{<br />
pItemData->crTextColor = crTextColor;<br />
pItemData->crBkColor = crBkColor;<br />
Invalidate();<br />
}<br />
}<br />
TheIronFist
|
|
|
|
|
Nice...
I will add this feature to the next article update.
Ron.
|
|
|
|
|
Is there a way to change the color of the dropdown button on the conbo-box?
|
|
|
|
|
Any idea why and how I can change it back to be normal?
Jeremy Pemberton-Pigott
A programmer with a dream can accomplish anything. So, start by implementing your castle in the clouds and then working on its interface to a foundation
Quote by: Jeremy Pemberton-Pigott
New Dawn Engineering
|
|
|
|
|
The reason is that it is a owner-draw combo box.
This is strange, but when you set 'Owner Draw' attribute to fixed, Microsoft is making the combo higher.
I did try to override the MeasureItem function and change the height, without success.
If anybody know how to solve it, i will be very happy
|
|
|
|
|
There is a bug in the Microsoft code for drawing owner drawn combo boxes. These are the only 2 solutions that I found. I had to use the "2 combo box solution". If you can figure out a better solution that'd be great
Codeproject link 1[^] link 2[^]
Jeremy Pemberton-Pigott
A programmer with a dream can accomplish anything. So, start by implementing your castle in the clouds and then working on its interface to a foundation
Quote by: Jeremy Pemberton-Pigott
New Dawn Engineering
|
|
|
|
|