Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Create custom control.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Create custom control.

 Post Reply Post Reply
Author
Message
Gorkystreet View Drop Down
Newbie
Newbie


Joined: 04 July 2007
Location: Ukraine
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gorkystreet Quote  Post ReplyReply Direct Link To This Post Topic: Create custom control.
    Posted: 04 July 2007 at 9:36am
Good morning!
 
I need a custom control to use it with CXTPPropertyGrid. It should be like combobox (with dropdown list), but it should have possibility to be enabled\disabled from the construction. So it has contain the check-box at left side of it's value field. Maybe someone has emplemented such class already? My version is the following:
 
Declaration:
 
class CInplaceCheckBox : public CButton
{
public:
 afx_msg LRESULT OnCheck(WPARAM wParam, LPARAM lParam); 
 afx_msg HBRUSH CtlColor(CDC* pDC, UINT /*nCtlColor*/);
 DECLARE_MESSAGE_MAP()
protected:
 CCustomItemCheckBox* m_pItem;
 COLORREF m_clrBack;
 CBrush m_brBack;
 virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
 friend class CCustomItemCheckBox;
};
//----------------------------------------------------------------------------
class CCustomItemCheckBox : public CXTPPropertyGridItemEnum
{
protected:
public:
 CCustomItemCheckBox(CString strCaption);
 CCustomItemCheckBox(CString strCaption, ULONG index);
 CCustomItemCheckBox(CString strCaption, BOOL checked);
 CCustomItemCheckBox(CString strCaption, ULONG index, BOOL checked);
 virtual ~CCustomItemCheckBox();
 BOOL GetBool();
 void SetBool(BOOL bValue);
 ControlType GetType();
 void SetType(ControlType type);
protected:
 //virtual void OnDeselect();
 //virtual void OnSelect();
 virtual BOOL OnLButtonDown(UINT nFlags, CPoint point);
 virtual CRect GetValueRect();
 virtual BOOL OnDrawItemValue(CDC& dc, CRect rcValue);

 virtual BOOL IsValueChanged();
private:
 CInplaceCheckBox m_wndCheckBox;
 BOOL m_bValue;
 CRect m_CheckBoxRect;
 ControlType m_Type;
 friend class CInplaceCheckBox;
};
Implementation:
 
BEGIN_MESSAGE_MAP(CInplaceCheckBox, CButton)
 ON_MESSAGE(BM_SETCHECK, OnCheck)
 ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
//----------------------------------------------------------------------------
HBRUSH CInplaceCheckBox::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
 class CGridView : public CXTPPropertyGridView
 {
  friend class CInplaceCheckBox;
 };
 CGridView* pGrid = (CGridView*)m_pItem->m_pGrid;
 COLORREF clr = pGrid->GetPaintManager()->GetItemMetrics()->m_clrBack;
 if (clr != m_clrBack || !m_brBack.GetSafeHandle())
 {
  m_brBack.DeleteObject();
  m_brBack.CreateSolidBrush(clr);
  m_clrBack = clr;
 }
 pDC->SetBkColor(m_clrBack);
 return m_brBack;
}
//----------------------------------------------------------------------------
BOOL CInplaceCheckBox::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)

 return CButton::OnChildNotify(message, wParam, lParam, pResult);
}
//----------------------------------------------------------------------------
LRESULT CInplaceCheckBox::OnCheck(WPARAM wParam, LPARAM lParam)

 m_pItem->m_bValue = (wParam == BST_CHECKED);
 m_pItem->OnValueChanged(m_pItem->GetValue()); 
 return CButton::DefWindowProc(BM_SETCHECK, wParam, lParam);
}
//----------------------------------------------------------------------------
CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption)
: CXTPPropertyGridItemEnum(strCaption)
{
 m_wndCheckBox.m_pItem = this;
 m_bValue = TRUE;
}
//----------------------------------------------------------------------------
CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption, ULONG index)
: CXTPPropertyGridItemEnum(strCaption,index)
{
 m_wndCheckBox.m_pItem = this;
 m_bValue = TRUE;
}
//----------------------------------------------------------------------------
CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption, BOOL checked)
: CXTPPropertyGridItemEnum(strCaption)
{
 m_wndCheckBox.m_pItem = this;
 m_bValue = checked;
}
//----------------------------------------------------------------------------
CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption, ULONG index, BOOL checked)
: CXTPPropertyGridItemEnum(strCaption,index)
{
 m_wndCheckBox.m_pItem = this;
 m_bValue = checked;
}
//----------------------------------------------------------------------------
CCustomItemCheckBox::~CCustomItemCheckBox(){}
//----------------------------------------------------------------------------
CRect CCustomItemCheckBox::GetValueRect()
{
 CRect rcValue(CXTPPropertyGridItem::GetValueRect());
 rcValue.left += 17; 
 return rcValue;
}
//----------------------------------------------------------------------------
BOOL CCustomItemCheckBox::OnDrawItemValue(CDC& dc, CRect rcValue)
{
 CRect rcText(rcValue);
 if (m_wndCheckBox.GetSafeHwnd() == 0 && m_bValue)
 {
  CRect rcCheck(rcText.left , rcText.top, rcText.left + 13, rcText.bottom -1);
  dc.DrawFrameControl(rcCheck, DFC_MENU, DFCS_MENUCHECK );
  m_CheckBoxRect = rcText;  
 }
 rcText.left += 17;
 dc.DrawText( GetValue(), rcText,  DT_SINGLELINE | DT_VCENTER ); 
 return TRUE;
}
//----------------------------------------------------------------------------
BOOL CCustomItemCheckBox::GetBool()
{
 return m_bValue;
}
//----------------------------------------------------------------------------
void CCustomItemCheckBox::SetBool(BOOL bValue)
{
 m_bValue = bValue;
 if (m_wndCheckBox.GetSafeHwnd())
  m_wndCheckBox.SetCheck(bValue);  
}
//----------------------------------------------------------------------------
ControlType CCustomItemCheckBox::GetType()
{
 return m_Type;
}
//----------------------------------------------------------------------------
void CCustomItemCheckBox::SetType(ControlType type)
{
 m_Type = type;
}
//----------------------------------------------------------------------------
BOOL CCustomItemCheckBox::IsValueChanged()
{
 return !m_bValue;
}
//----------------------------------------------------------------------------
BOOL CCustomItemCheckBox::OnLButtonDown(UINT nFlags, CPoint point)
{
 //ASSERT(FALSE);
 POINT pt;
 pt.x = point.x;
 pt.y = point.y;
 m_CheckBoxRect.NormalizeRect();
 CRect tempRect = m_CheckBoxRect;
 tempRect.right = tempRect.left + 17;
 if (PtInRect(&tempRect/*m_CheckBoxRect*/,pt))
 {
  //if (m_bValue)
  // SetBool(FALSE);
  //else SetBool(TRUE);
  SetBool(!m_bValue);  
  return CXTPPropertyGridItem::OnLButtonDown(nFlags,point);  
 }
}
The main fault here is that I cannot create it disabled from construction time. If I will pass 'false' value to the CCustomItemCheckBox(CString strCaption, ULONG index, BOOL checked); constructor, the method
OnDrawItemValue(...) will not draw the check box. Now I just don't know how to overcome it :(
 
I will be very appreciated for any help.
 
Thanx in advance!
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.031 seconds.