在单击任何按钮之前,如何使XSleep()函数执行? [英] How to make XSleep() function execute untill i click on any button?

查看:128
本文介绍了在单击任何按钮之前,如何使XSleep()函数执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使XSleep()功能继续执行,直到我单击按钮.

还有什么其他功能可以使您睡到事件发生为止?


使用XSleep时XSleep(1000);
我停止执行1000毫秒.


而不是给出值,执行应该停止一段时间,直到我在按钮上执行OnClick操作为止.

How to make XSleep()function continue execution untill i click on the button.

Is there any other funtion that sleep untill an event occurs?


when XSleep is used XSleep(1000);
i stops execution for 1000 milliseconds.


Instead of giving a value the Execution should stop for time untill I do OnClick operstion on a button.

void CDemoDlg::OnBnClickedSongPlay2()
{
	
if(PauseFlag==true)
{
	int i=0;bool b=true;
	while(b)
	{
		i++;
		XSleep(i++);
// some code to be written for any event occurs so i can make b=false;
		
	}

		
	}
	else
	{
		PauseFlag=true;
	return;
	}
}




在上面的代码中,它暂停并且永远不会恢复,请更正此代码以恢复它.




In the above code it pauses and never resume please correct this code to resume it.

推荐答案

应避免使用sleep().我没有看过XSleep()源码,但是它似乎避免了sleep函数的某些缺点.

通常的方法是将WaitForSingleObject()与事件一起使用.如果您向我们介绍要使用sleep()的上下文,我们可能会找到避免这种情况的解决方案.

[根据更新问题进行更新]
一种解决方案可能是终止由XSleep()创建的线程.这需要通过添加代码以在特定消息后终止(例如,按钮的BN_CLICKED通知)来修改XSleep()源.

更好的解决方案是适当的设计.我了解您正在播放音频,并希望提供暂停和恢复选项.然后暂停播放,并保存实际的播放位置.恢复后,在已存储的位置开始播放.这样的设计避免了使用睡眠命令.
[UPDATE]
Using sleep() should be avoided. I did not had a look at the XSleep() source, but it seems to avoid some of the disadvantages of the sleep function.

The usual way is to use WaitForSingleObject() with an event. If you tell us about the context where you want to use sleep(), we may find a solution to avoid it.

[UPDATE according to update question]
One solution may be terminating the thread created by XSleep(). This requires modification of the XSleep() source by adding code to terminate upon a specific message (e.g. the BN_CLICKED notfication of your button).

A better solution would be a proper design. I understand that you are playing audio and want to provide a pause and resume option. Then stop playing upon pause, and save the actual play position. Upon resume, start playing at the stored position. Such a design avoids the usage of sleep commands.
[UPDATE]


这篇关于在单击任何按钮之前,如何使XSleep()函数执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆