Sign in to follow this  

button problem

This topic is 3457 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
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

This topic is 3457 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this