Dave's Brain

Browse - programming tips - windows how does my application receive a button click

Date: 2010jan19
OS: Windows
Level: beginner

Q.  How does my application receive a user's mouse click?

A.  If its a button you get WM_COMMAND otherwise WM_LBUTTONDOWN
windows messages.  In MFC you can use the GUI to set this up or do:

For a button...

In your .h file:

	afx_msg LRESULT OnMyButton(WPARAM, LPARAM);

In your .cpp file:

	BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
		ON_COMMAND(ID_MY_BUTTON, OnMyButton)
	END_MESSAGE_MAP()

	// ...

	LRESULT CMyDialog::OnMyButton(WPARAM, LPARAM);
	{
	}

For a click on a window...

In your .h file:

	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);

In your .cpp file:

	BEGIN_MESSAGE_MAP(CMyWindow, CWnd)
		ON_WM_LBUTTONDOWN()
	END_MESSAGE_MAP()

	// ...

	void CMyWindow::OnLButtonDown(UINT nFlags, CPoint point)
	{
		// ...
	}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.