![]() |
How to reach the DrawItem() in CXTPControlComboBox |
Post Reply ![]() |
Author | |
hikaroute ![]() Groupie ![]() Joined: 05 September 2007 Status: Offline Points: 51 |
![]() ![]() ![]() ![]() ![]() 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.
|
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
hikaroute ![]() Groupie ![]() Joined: 05 September 2007 Status: Offline Points: 51 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
|
hikaroute ![]() Groupie ![]() Joined: 05 September 2007 Status: Offline Points: 51 |
![]() ![]() ![]() ![]() ![]() |
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
}
|
|
![]() |
|
mgampi ![]() Senior Member ![]() ![]() Joined: 14 July 2003 Status: Offline Points: 1201 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
hikaroute ![]() Groupie ![]() Joined: 05 September 2007 Status: Offline Points: 51 |
![]() ![]() ![]() ![]() ![]() |
Thank you 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;
}
|
|
![]() |
|
mgampi ![]() Senior Member ![]() ![]() Joined: 14 July 2003 Status: Offline Points: 1201 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
hikaroute ![]() Groupie ![]() Joined: 05 September 2007 Status: Offline Points: 51 |
![]() ![]() ![]() ![]() ![]() |
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. |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
Hi,
Check ToolkitPro\Samples\CommandBars\CustomThemes - exactly same code works for CControlComboBoxCustomDraw.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
hikaroute ![]() Groupie ![]() Joined: 05 September 2007 Status: Offline Points: 51 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
Hi,
Its something in your sources. Check you set right text color.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
hikaroute ![]() Groupie ![]() Joined: 05 September 2007 Status: Offline Points: 51 |
![]() ![]() ![]() ![]() ![]() |
Thank you so much oleg,
it help me so much.
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |