Jump to content
  • Advertisement
Sign in to follow this  
Fire Lancer

Sending a delayed windows message

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

I came up with a method to post a "delayed" message in win32, however id rather one that didnt require a temporary thread, are there any other ways?
//DELAYED MESSAGE
struct PostMessageDelayedInfo
{
	HWND   hwnd;
	UINT   msg;
	WPARAM wParam;
	LPARAM lParam;
	DWORD  delay;
};
static unsigned __stdcall PostMessageDelayedReal(void *a)
{
	PostMessageDelayedInfo *info = (PostMessageDelayedInfo*)a;
	Sleep(info->delay);
	PostMessage(info->hwnd, info->msg, info->wParam, info->lParam);
	delete info;
	return 0;
}
void PostMessageDelayed(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, DWORD delay)
{
	PostMessageDelayedInfo *info = new PostMessageDelayedInfo;
	info->hwnd   = hwnd;
	info->msg    = msg;
	info->wParam = wParam;
	info->lParam = lParam;
	info->delay  = delay;
	_beginthreadex(0,0, &PostMessageDelayedReal, (void*)info, 0,0);
}

Share this post


Link to post
Share on other sites
Advertisement
Why on earth would you want to do this? If you absolutely need to send delayed messages, what's wrong with having a std::vector of pending messages somewhere, and checking if it's time to send one every tick?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!