Link to home
Start Free TrialLog in
Avatar of loveslave
loveslave

asked on

How to redraw custom CButton

I have a custom control that derives from CButton (it is a GUI element simulating a joystick):

class TwoAxisJoystick : public CButton

Within the main CButton, which has BS_GROUPBOX, there is another BS_GROUPBOX and a CStatic object that is a marker showing the current joystick position within the frame. The control looks a bit like the attached ASCII art. The outer and inner frames are both CButton objects with BS_GROUPBOX style, and the ¤ is a CStatic that can be moved within the inner frame by using the mouse.

However. I'm not able to clear the inner frame after I change the position of the marker. So instead of moving a marker around, it looks as if drawing with a paint brush, leaving a trail behind of its previous positions, until a redraw is forced by minimizing the window or moving another window over it, etc.

How can I redraw the control after each change of the marker's position? The "moving code" is also attached below. I thought that would work, but it doesn't. How should this be done?

+-----------+
|           |
|           |
| +-------+ |
| |       | |
| |   ¤   | |
| |       | |
| +-------+ |
+-----------+
 
m_marker.SetWindowPos(&wndTop, x, y, 20, 20, SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW);
Invalidate();
// also tried the following two lines (m_marker is the inner CStatic object, m_jsFrame is the inner frame)
// m_marker.Invalidate();
// m_jsFrame.Invalidate();

Open in new window

SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of loveslave
loveslave

ASKER

Thanks for your reply, but that doesn't work either. I still get the same effect.
Hm - maybe you have to remove the WS_CLIPCHILDREN style from the dialog.
I tried adding the line
ModifyStyle(WS_CLIPCHILDREN, 0)
to the oter CButton, the inner CButton, and to the dialog itself in its OnInitDialog() method. The only visible change is that the update is somewhat more laggy now. The marker is still leaving trails behind.
Edit: the update is not more laggy. I don't see any change at all after doig the changes above.
Hm - hard to say without being able to test.

BTW, I think it might possibly better to just implement one control which does what you like to do with several controls. I.e. a CStatic derived class could be used to display both frames and the marker. I guess this would be easier to handle and there would be a better control about the look and feel.

ZOPPO
I tried making my class inherit from CStatic instead of CButton, and changed the inner frame also to a CStatic instead of a CButton. Still no change. All is in one class. I'm attaching the current declaration.
class TwoAxisJoystick : public CStatic//CButton
{
// Construction
public:
	TwoAxisJoystick();
 
   virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CDecT2KeyboardSimDlg* pRate, int joyNumber);
 
   void TwoAxisJoystick::ResetJsMarker();
 
// Attributes
public:
 
// Operations
public:
 
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(TwoAxisJoystick)
	//}}AFX_VIRTUAL
 
// Implementation
public:
	virtual ~TwoAxisJoystick();
 
	// Generated message map functions
protected:
	//{{AFX_MSG(TwoAxisJoystick)
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg UINT OnNcHitTest(CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	//}}AFX_MSG
 
	DECLARE_MESSAGE_MAP()
 
      CButton m_buttons[5];
   CStatic m_jsFrame;
   CStatic m_marker;
   int m_jsFrameSize;
   int m_markerSize;
   int m_joyNumber;
   CDecT2KeyboardSimDlg* m_pParent;
};

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial