Print Page | Close Window

CButton Custom item

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=2367
Printed Date: 23 November 2024 at 10:29pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CButton Custom item
Posted By: Patrick
Subject: CButton Custom item
Date Posted: 12 June 2005 at 10:46pm

I would like to create a custom item that is a simple command button (CButton).  I would like the button always to be visible (e.g., even if it has not been selected) unless its category is collapsed, and receive an event when the button is clicked.  I have a partially working version but it does not property hide or show itself when its category is expanded or collapsed.  Thanks in advance for any help.




Replies:
Posted By: Oleg
Date Posted: 13 June 2005 at 4:31am

We added this sample to PropertyGrid sample for next release.

After item expnaded/collapsed SetVisible is called. You can override it and test

m_bVisible state.



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Patrick
Date Posted: 13 June 2005 at 6:04am

oleg,

Thank you for the quick reply!  When will the sample code be available and how may I obtain it?  Is it possible to get it now?  By the way, your product is outstanding!  The best object model and implementation I have seen in any off the shelf visual component.

Thanks again,

Patrick

 



Posted By: Patrick
Date Posted: 15 June 2005 at 1:46am

The following code represents my solution. It will be interesting to see how different it is from the future sample code.

// Patrick
// CCustomItemCommandBtn
// 6/14/05

class CCustomItemCommandBtn;

class CInplaceCommandBtn : public CButton
{
public:
 afx_msg LRESULT OnClick(WPARAM wParam, WPARAM lParam);
 afx_msg HBRUSH CtlColor(CDC* pDC, UINT /*nCtlColor*/);
   afx_msg void OnMove(int x, int y);

 DECLARE_MESSAGE_MAP()

protected:
 CCustomItemCommandBtn* m_pItem;
 COLORREF m_clrBack;
 CBrush m_brBack;

 friend class CCustomItemCommandBtn;
};

class CCustomItemCommandBtn : public CXTPPropertyGridItem
{
public:
 CCustomItemCommandBtn(CString strCaption, LPCTSTR buttonTxt = NULL, HICON hIcon = NULL);

protected:
   CString m_buttonTxt;
   HICON m_hIcon;
   void Create();

protected:
 virtual BOOL OnDrawItemValue(CDC& dc, CRect rcValue);
   virtual void SetVisible(BOOL bVisible);
     
private:
 CInplaceCommandBtn m_wndButton;

 friend class CInplaceCommandBtn;
};

//Patrick

// CCustomItemCommandBtn
// 6/14/05


BEGIN_MESSAGE_MAP(CInplaceCommandBtn, CButton)
 ON_MESSAGE(BM_SETSTATE, OnClick)
 ON_WM_CTLCOLOR_REFLECT()
 ON_WM_MOVE()
END_MESSAGE_MAP()

HBRUSH CInplaceCommandBtn::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
 class CGridView : public CXTPPropertyGridView
 {
  friend class CInplaceCommandBtn;
 };

 CGridView* pGrid = (CGridView*)m_pItem->m_pGrid;

 COLORREF clr = pGrid->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;
}

LRESULT CInplaceCommandBtn::OnClick(WPARAM wParam, WPARAM lParam)
{
   if (!wParam)
      m_pItem->OnValueChanged(_T(""));
   return CButton::DefWindowProc(BM_SETSTATE, wParam, lParam);
}

void CInplaceCommandBtn::OnMove(int, int)
{
   Invalidate();
}


CCustomItemCommandBtn::CCustomItemCommandBtn(CString strCaption,
                              LPCTSTR buttonTxt /*=NULL*/, HICON hIcon/*=NULL*/)
 : CXTPPropertyGridItem(strCaption)
{
 m_wndButton.m_pItem = this;
 m_nFlags = 0;
   m_buttonTxt = buttonTxt;
   m_hIcon = hIcon;
}

void CCustomItemCommandBtn::Create()
{
   DWORD style = WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE | (m_hIcon ? BS_ICON : 0);
   m_wndButton.Create(m_buttonTxt, style, GetValueRect(), (CWnd*)m_pGrid, 0);
   if (m_hIcon)
   {
      m_wndButton.SetIcon(m_hIcon);
   }
}

BOOL CCustomItemCommandBtn::OnDrawItemValue(CDC&, CRect)
{
   if (!m_wndButton.m_hWnd)
   {
      Create();
   }
   m_wndButton.MoveWindow(GetValueRect());
  
   return TRUE;
}

void CCustomItemCommandBtn::SetVisible(BOOL bVisible)
{
   CXTPPropertyGridItem::SetVisible(bVisible);
   if (m_wndButton.m_hWnd)
   {
      m_wndButton.ShowWindow(bVisible ? SW_SHOW : SW_HIDE);
   }
   else
   {
      Create();
   }
}

 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net