How to reach the DrawItem() in CXTPControlComboBox
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=9905
Printed Date: 08 June 2025 at 1:15am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: How to reach the DrawItem() in CXTPControlComboBox
Posted By: hikaroute
Subject: How to reach the DrawItem() in CXTPControlComboBox
Date Posted: 17 March 2008 at 12:26am
I created the class that derived from CXTPControlComboBox and make the new virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); function to add some special.
But this virtual function don't active automatically, I don't know why and try the debug mode but still freez.
I want to know the CXTPControlComboBox don't use this function to draw? I can't use CXTPControlComboBoxList because I need only the combobox stlye.(not boxlist)
Thank you.
|
Replies:
Posted By: Oleg
Date Posted: 17 March 2008 at 2:12am
Hi,
You also have to set LBS_OWNERDRAWFIXED style for List:
CXTPControlComboBox* pComboFind = new CXTPControlComboBox(GetCommandBars()); pComboFind->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: hikaroute
Date Posted: 17 March 2008 at 3:23am
Hi again oleg,
Yes, for the standard function that use LBS_OWNERDRAWFIXED, I think all should cleared(function works). But when I use it in the OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) function. And the code inside should be
...
if ((lpCreateControl->nID == ID_COMBO_ENP_LAYER))
{
lpCreateControl->pControl = new CXTPControlComboBox(GetCommandBars));
lpCreateControl->pControl->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
return TRUE;
}
...
But I cannot use the modifyListBoxStyle like this, how to fixed this problem.
Thank you again.
|
Posted By: hikaroute
Date Posted: 17 March 2008 at 4:00am
And the code of new CXTPControlComboBox is
-- header --
#ifndef __NEW_COMBOBOX_H__
#define __NEW_COMBOBOX_H__
class CNewComboBox : public CXTPControlComboBox
{
protected:
public:
CNewComboBox(CXTPCommandBars* pCommandBars = NULL);
virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
DECLARE_XTP_CONTROL(CNewComboBox)
};
#endif //__NEW_COMBOBOX_H__
-- body --
#include "stdafx.h"
#include "newcombobox.h"
IMPLEMENT_XTP_CONTROL(CNewComboBox, CXTPControlComboBox)
CNewComboBox::CNewComboBox(CXTPCommandBars* pCommandBars)
{
m_pCommandBar->SetCommandBars(pCommandBars);
}
void CNewComboBox::DrawItem( LPDRAWITEMSTRUCT pDrawItemStruct )
{
AfxMessageBox("Draw"); // Sample for testing
}
|
Posted By: mgampi
Date Posted: 17 March 2008 at 4:09am
Hi,
I did it this way:
Derive not only from CXTPControlComboBox but also from CXTPControlComboBoxList:
class CXRCurveComboBox; class CXRCurveComboBoxList : public CXTPControlComboBoxList {
DECLARE_XTP_COMMANDBAR(CXRCurveComboBoxList);
DECLARE_MESSAGE_MAP()
public: void DrawItem ( LPDRAWITEMSTRUCT lpDrawItemStruct ); void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct); void CreateListBox();
friend class CXRCurveComboBox; };
class CXRCurveComboBox : public CXTPControlComboBox
{ DECLARE_XTP_CONTROL(CXRCurveComboBox)
public:
CXRCurveComboBox();
virtual ~CXRCurveComboBox();
...
void DrawEditText(CDC* pDC, CRect rcText);
protected:
DECLARE_MESSAGE_MAP()
};
/// Implementation (only important parts...)
CXRCurveComboBox::CXRCurveComboBox()
{
if (m_pCommandBar)
{
m_pCommandBar->InternalRelease();
}
m_pCommandBar = new CXRCurveComboBoxList();
((CXRCurveComboBoxList*)m_pCommandBar)->CreateListBox();
}
CXRCurveComboBox::~CXRCurveComboBox()
{
}
void CXRCurveComboBoxList::CreateListBox()
{
ASSERT_VALID(_gMainInstance); VERIFY(CreateEx(WS_EX_STATICEDGE|WS_EX_TOOLWINDOW, _T("LISTBOX"), _T(""),WS_VSCROLL|WS_BORDER|WS_CLIPCHILDREN|LBS_SORT|
LBS_OWNERDRAWFIXED|LBS_HASSTRINGS|WS_POPUP|LBS_NOTIFY, CRect(0,0,0,0), _gMainInstance, 0)==TRUE);
SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, 0 ); ModifyStyle(WS_CHILD, WS_POPUP);
#ifdef _WIN64 SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, (LONG_PTR)_gMainInstance->GetSafeHwnd()); #else SetWindowLong(m_hWnd, GWLP_HWNDPARENT, (LONG)(LONG_PTR)_gMainInstance->GetSafeHwnd()); #endif
}
_gMainInstance is in my case the global window handle (AfxGetMainWnd()). I do this this way because the classes are exported from a DLL.
Hope this helps
------------- Martin
Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022
|
Posted By: hikaroute
Date Posted: 17 March 2008 at 4:26am
Thank you http://forum.codejock.com/member_profile.asp?PF=109&FID=18 - mgampi ,
But the thing I need to know is how to create & manage the ModifyListBoxStyle in the OnCreateControl() function...
int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
{
if ((lpCreateControl->nID == ID_COMBO_TEST))
{
lpCreateControl->pControl = new CXTPControlComboBox(GetCommandBars());
lpCreateControl->pControl->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
return TRUE;
}
return FALSE;
}
|
Posted By: mgampi
Date Posted: 17 March 2008 at 4:44am
Ah, I see!
I think, you have to reinterpret_cast<> lpCreatControl->pControl or DYNAMIC_DOWNCAST() to a CXTPControlComboBox like this:
reinterpret_cast<CXTPControlComboBox*>(lpCreateControl->pControl)->ModifyListBoxStyle(...)
------------- Martin
Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022
|
Posted By: hikaroute
Date Posted: 17 March 2008 at 10:47pm
To oleg, mgampi or others
I use this function
----------------------------------------------------------------
int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
{
if ((lpCreateControl->nID == ID_COMBO_TEST))
{
lpCreateControl->pControl = new CNewComboBox(GetCommandBars());
reinterpret_cast<CNewComboBox*>(lpCreateControl->pControl)->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
return TRUE;
}
}
----------------------------------------------------------------
But the function name void CNewComboBox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ); still can not use.
Please tell me how to fix for run DrawItem() function.
Thank you.
|
Posted By: Oleg
Date Posted: 18 March 2008 at 3:55am
Hi,
Check ToolkitPro\Samples\CommandBars\CustomThemes - exactly same code works for CControlComboBoxCustomDraw.
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: hikaroute
Date Posted: 18 March 2008 at 10:53am
Thank you oleg,
now I can redraw my item in combobox.
But I have the new problem of my new combobox, it's the item detail lost.
That you can see in my image, each column have images and it's font still have the different font color too. (in the future for the font type)
But when I click the other column to change the selected. They can show the default font format with no have the image in the current selected.
How can I fix this problem? Because I tested with CComboBox is OK. Or you can check my source code if you want.
Thank you again.
|
Posted By: Oleg
Date Posted: 19 March 2008 at 7:55am
Hi,
Its something in your sources. Check you set right text color.
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: hikaroute
Date Posted: 20 March 2008 at 9:13pm
Thank you so much oleg,
it help me so much.
|
|