Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Property Grid
  New Posts New Posts RSS Feed - CButton Custom item
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CButton Custom item

 Post Reply Post Reply
Author
Message
Patrick View Drop Down
Newbie
Newbie
Avatar

Joined: 12 June 2005
Location: United States
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Patrick Quote  Post ReplyReply Direct Link To This Post Topic: CButton Custom item
    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.

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: 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
Back to Top
Patrick View Drop Down
Newbie
Newbie
Avatar

Joined: 12 June 2005
Location: United States
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Patrick Quote  Post ReplyReply Direct Link To This Post 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

 

Back to Top
Patrick View Drop Down
Newbie
Newbie
Avatar

Joined: 12 June 2005
Location: United States
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Patrick Quote  Post ReplyReply Direct Link To This Post 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();
   }
}

 

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.156 seconds.