Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - How to reach the DrawItem() in CXTPControlComboBox
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to reach the DrawItem() in CXTPControlComboBox

 Post Reply Post Reply
Author
Message
hikaroute View Drop Down
Groupie
Groupie


Joined: 05 September 2007
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote hikaroute Quote  Post ReplyReply Direct Link To This Post Topic: How to reach the DrawItem() in CXTPControlComboBox
    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.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
hikaroute View Drop Down
Groupie
Groupie


Joined: 05 September 2007
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote hikaroute Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
hikaroute View Drop Down
Groupie
Groupie


Joined: 05 September 2007
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote hikaroute Quote  Post ReplyReply Direct Link To This Post 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
}
 
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1201
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
hikaroute View Drop Down
Groupie
Groupie


Joined: 05 September 2007
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote hikaroute Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2008 at 4:26am
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;
}
 
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1201
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
hikaroute View Drop Down
Groupie
Groupie


Joined: 05 September 2007
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote hikaroute Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
hikaroute View Drop Down
Groupie
Groupie


Joined: 05 September 2007
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote hikaroute Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
hikaroute View Drop Down
Groupie
Groupie


Joined: 05 September 2007
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote hikaroute Quote  Post ReplyReply Direct Link To This Post Posted: 20 March 2008 at 9:13pm
Thank you so much oleg,
     it help me so much.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.