<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : Create custom control.</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Toolkit Pro : Create custom control.]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Sun, 14 Jun 2026 12:01:40 +0000</pubDate>
  <lastBuildDate>Wed, 04 Jul 2007 09:36:26 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=7526</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[Create custom control. : Good morning!  I need a custom...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=7526&amp;PID=24185&amp;title=create-custom-control#24185</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=3124">Gorkystreet</a><br /><strong>Subject:</strong> 7526<br /><strong>Posted:</strong> 04 July 2007 at 9:36am<br /><br />Good morning!<DIV>&nbsp;</DIV><DIV>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:</DIV><DIV>&nbsp;</DIV><DIV><strong><U>Declaration:</U></strong></DIV><DIV>&nbsp;</DIV><DIV>class CInplaceCheckBox : public CButton<BR>{<BR>public:<BR>&nbsp;afx_msg LRESULT OnCheck(WPARAM wParam, LPARAM lParam);&nbsp;<BR>&nbsp;afx_msg HBRUSH CtlColor(CDC* pDC, UINT /*nCtlColor*/);</DIV><DIV>&nbsp;DECLARE_MESSAGE_MAP()<BR>protected:<BR>&nbsp;CCustomItemCheckBox* m_pItem;<BR>&nbsp;COLORREF m_clrBack;<BR>&nbsp;CBrush m_brBack;</DIV><DIV>&nbsp;virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);</DIV><DIV>&nbsp;friend class CCustomItemCheckBox;<BR>};<BR>//----------------------------------------------------------------------------<BR>class CCustomItemCheckBox : public CXTPPropertyGridItemEnum<BR>{<BR>protected:</DIV><DIV>public:<BR>&nbsp;CCustomItemCheckBox(CString strCaption);<BR>&nbsp;CCustomItemCheckBox(CString strCaption, ULONG index);<BR>&nbsp;CCustomItemCheckBox(CString strCaption, BOOL checked);<BR>&nbsp;CCustomItemCheckBox(CString strCaption, ULONG index, BOOL checked);<BR>&nbsp;virtual ~CCustomItemCheckBox();</DIV><DIV>&nbsp;BOOL GetBool();<BR>&nbsp;void SetBool(BOOL bValue);</DIV><DIV>&nbsp;ControlType GetType();<BR>&nbsp;void SetType(ControlType type);</DIV><DIV>protected:<BR>&nbsp;//virtual void OnDeselect();<BR>&nbsp;//virtual void OnSelect();<BR>&nbsp;virtual BOOL OnLButtonDown(UINT nFlags, CPoint point);<BR>&nbsp;virtual CRect GetValueRect();<BR>&nbsp;virtual BOOL OnDrawItemValue(CDC&amp; dc, CRect rcValue);</DIV><DIV><BR>&nbsp;virtual BOOL IsValueChanged();</DIV><DIV>private:<BR>&nbsp;CInplaceCheckBox m_wndCheckBox;<BR>&nbsp;BOOL m_bValue;<BR>&nbsp;CRect m_CheckBoxRect;<BR>&nbsp;ControlType m_Type;</DIV><DIV>&nbsp;friend class CInplaceCheckBox;<BR>};<BR></DIV><DIV><U><strong>Implementation:</strong></U></DIV><DIV><strong><U></U></strong>&nbsp;</DIV><DIV>BEGIN_MESSAGE_MAP(CInplaceCheckBox, CButton)<BR>&nbsp;ON_MESSAGE(BM_SETCHECK, OnCheck)<BR>&nbsp;ON_WM_CTLCOLOR_REFLECT()<BR>END_MESSAGE_MAP()<BR>//----------------------------------------------------------------------------<BR>HBRUSH CInplaceCheckBox::CtlColor(CDC* pDC, UINT /*nCtlColor*/)<BR>{<BR>&nbsp;class CGridView : public CXTPPropertyGridView<BR>&nbsp;{<BR>&nbsp;&nbsp;friend class CInplaceCheckBox;<BR>&nbsp;};</DIV><DIV>&nbsp;CGridView* pGrid = (CGridView*)m_pItem-&gt;m_pGrid;</DIV><DIV>&nbsp;COLORREF clr = pGrid-&gt;GetPaintManager()-&gt;GetItemMetrics()-&gt;m_clrBack;</DIV><DIV>&nbsp;if (clr != m_clrBack || !m_brBack.GetSafeHandle())<BR>&nbsp;{<BR>&nbsp;&nbsp;m_brBack.DeleteObject();<BR>&nbsp;&nbsp;m_brBack.CreateSolidBrush(clr);<BR>&nbsp;&nbsp;m_clrBack = clr;<BR>&nbsp;}</DIV><DIV>&nbsp;pDC-&gt;SetBkColor(m_clrBack);<BR>&nbsp;return m_brBack;<BR>}<BR>//----------------------------------------------------------------------------<BR>BOOL CInplaceCheckBox::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)<BR>{&nbsp;<BR>&nbsp;return CButton::OnChildNotify(message, wParam, lParam, pResult);<BR>}<BR>//----------------------------------------------------------------------------<BR>LRESULT CInplaceCheckBox::OnCheck(WPARAM wParam, LPARAM lParam)<BR>{&nbsp;<BR>&nbsp;m_pItem-&gt;m_bValue = (wParam == BST_CHECKED);<BR>&nbsp;m_pItem-&gt;OnValueChanged(m_pItem-&gt;GetValue());&nbsp;<BR>&nbsp;return CButton::DefWindowProc(BM_SETCHECK, wParam, lParam);<BR>}<BR>//----------------------------------------------------------------------------<BR>CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption)<BR>: CXTPPropertyGridItemEnum(strCaption)<BR>{<BR>&nbsp;m_wndCheckBox.m_pItem = this;<BR>&nbsp;m_bValue = TRUE;<BR>}<BR>//----------------------------------------------------------------------------<BR>CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption, ULONG index)<BR>: CXTPPropertyGridItemEnum(strCaption,index)<BR>{<BR>&nbsp;m_wndCheckBox.m_pItem = this;<BR>&nbsp;m_bValue = TRUE;<BR>}<BR>//----------------------------------------------------------------------------<BR>CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption, BOOL checked)<BR>: CXTPPropertyGridItemEnum(strCaption)<BR>{<BR>&nbsp;m_wndCheckBox.m_pItem = this;<BR>&nbsp;m_bValue = checked;<BR>}<BR>//----------------------------------------------------------------------------<BR>CCustomItemCheckBox::CCustomItemCheckBox(CString strCaption, ULONG index, BOOL checked)<BR>: CXTPPropertyGridItemEnum(strCaption,index)<BR>{<BR>&nbsp;m_wndCheckBox.m_pItem = this;<BR>&nbsp;m_bValue = checked;<BR>}<BR>//----------------------------------------------------------------------------<BR>CCustomItemCheckBox::~CCustomItemCheckBox(){}<BR>//----------------------------------------------------------------------------<BR>CRect CCustomItemCheckBox::GetValueRect()<BR>{<BR>&nbsp;CRect rcValue(CXTPPropertyGridItem::GetValueRect());<BR>&nbsp;rcValue.left += 17;&nbsp;<BR>&nbsp;return rcValue;<BR>}<BR>//----------------------------------------------------------------------------<BR>BOOL CCustomItemCheckBox::OnDrawItemValue(CDC&amp; dc, CRect rcValue)<BR>{<BR>&nbsp;CRect rcText(rcValue);</DIV><DIV>&nbsp;if (m_wndCheckBox.GetSafeHwnd() == 0 &amp;&amp; m_bValue)<BR>&nbsp;{<BR>&nbsp;&nbsp;CRect rcCheck(rcText.left , rcText.top, rcText.left + 13, rcText.bottom -1);<BR>&nbsp;&nbsp;dc.DrawFrameControl(rcCheck, DFC_MENU, DFCS_MENUCHECK );<BR>&nbsp;&nbsp;m_CheckBoxRect = rcText;&nbsp;&nbsp;<BR>&nbsp;}</DIV><DIV>&nbsp;rcText.left += 17;<BR>&nbsp;dc.DrawText( GetValue(), rcText,&nbsp; DT_SINGLELINE | DT_VCENTER );&nbsp;<BR>&nbsp;return TRUE;<BR>}<BR>//----------------------------------------------------------------------------<BR>BOOL CCustomItemCheckBox::GetBool()<BR>{<BR>&nbsp;return m_bValue;<BR>}<BR>//----------------------------------------------------------------------------<BR>void CCustomItemCheckBox::SetBool(BOOL bValue)<BR>{<BR>&nbsp;m_bValue = bValue;</DIV><DIV>&nbsp;if (m_wndCheckBox.GetSafeHwnd())<BR>&nbsp;&nbsp;m_wndCheckBox.SetCheck(bValue);&nbsp;&nbsp;<BR>}<BR>//----------------------------------------------------------------------------<BR>ControlType CCustomItemCheckBox::GetType()<BR>{<BR>&nbsp;return m_Type;<BR>}<BR>//----------------------------------------------------------------------------<BR>void CCustomItemCheckBox::SetType(ControlType type)<BR>{<BR>&nbsp;m_Type = type;<BR>}<BR>//----------------------------------------------------------------------------<BR>BOOL CCustomItemCheckBox::IsValueChanged()<BR>{<BR>&nbsp;return !m_bValue;<BR>}<BR>//----------------------------------------------------------------------------<BR>BOOL CCustomItemCheckBox::OnLButtonDown(UINT nFlags, CPoint point)<BR>{<BR>&nbsp;//ASSERT(FALSE);<BR>&nbsp;POINT pt;<BR>&nbsp;pt.x = point.x;<BR>&nbsp;pt.y = point.y;</DIV><DIV>&nbsp;m_CheckBoxRect.NormalizeRect();<BR>&nbsp;CRect tempRect = m_CheckBoxRect;<BR>&nbsp;tempRect.right = tempRect.left + 17;</DIV><DIV>&nbsp;if (PtInRect(&amp;tempRect/*m_CheckBoxRect*/,pt))<BR>&nbsp;{<BR>&nbsp;&nbsp;//if (m_bValue)<BR>&nbsp;&nbsp;//&nbsp;SetBool(FALSE);<BR>&nbsp;&nbsp;//else SetBool(TRUE);<BR>&nbsp;&nbsp;SetBool(!m_bValue);&nbsp;&nbsp;<BR>&nbsp;&nbsp;return CXTPPropertyGridItem::OnLButtonDown(nFlags,point);&nbsp;&nbsp;<BR>&nbsp;}<BR>}<BR></DIV><DIV>The main fault here is that I cannot create it disabled from construction time. If I will pass '<FONT color=#0066ff>false</FONT>' value to the <FONT color=#0066ff>CCustomItemCheckBox(CString strCaption, ULONG index, BOOL checked);</FONT><FONT> constructor, the method </FONT></DIV><DIV><FONT color=#0099ff>OnDrawItemValue(...)</FONT><FONT> will not draw the check box. Now I just don't know how to overcome it :(</FONT></DIV><DIV>&nbsp;</DIV><DIV>I will be very appreciated for any help.</DIV><DIV>&nbsp;</DIV><DIV>Thanx in advance!</DIV>]]>
   </description>
   <pubDate>Wed, 04 Jul 2007 09:36:26 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=7526&amp;PID=24185&amp;title=create-custom-control#24185</guid>
  </item> 
 </channel>
</rss>