Jump to content
  • Advertisement
Sign in to follow this  
5quirrel

button problem

This topic is 3766 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

void cIntroState::HandleEvents()
{
	RECT clientRect;
	GetWindowRect(m_GameEngine->GethWnd(), &clientRect);

	GetCursorPos(&mousePos);
	POINT relMousePos;
	relMousePos.x = mousePos.x - clientRect.left;
	relMousePos.y = mousePos.y - clientRect.top;

	static bool StartButtonDown = false;
	if(KEY_DOWN(VK_LBUTTON))
	{
		if(relMousePos.x< 180 && relMousePos.x > 140 && relMousePos.y < 250 && relMousePos.y > 225 && StartButtonDown == false)
		{
				StartButtonDown = true;
		}
	}
	if(KEY_UP(VK_LBUTTON))
	{
		if(relMousePos.x< 180 && relMousePos.x > 140 && relMousePos.y < 250 && relMousePos.y > 225 && StartButtonDown)
		{
			cPlayState *playState = new cPlayState;
			m_GameEngine->getStateManagerPtr()->PushState(playState);
		}
		StartButtonDown = false;
	}
}

Hi everyone the above is my code for my button. There is a problem i run into that is when i click the mouse outside the button area, then hover over the button and release it, the button works. How can i code my button such that this wont happen?

Share this post


Link to post
Share on other sites
Advertisement
Normally one responds to these sorts of things via Windows messages, which basically takes care of the issue for you -- assuming you are using actual Win32 button controls and the like.

Otherwise, you will basically need to track which control the mouse is currently over (by checking when the mouse moves) and if the button is down and mouse hasn't been captured and the mouse leaves the control, cancel the is-down state.

If you're using Win32 buttons and Windows messages, this is much easier.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!