延迟一段时间调用SendMessage发送Windows消息
2014-10-16 17:14
351 查看
#pragma once
#include <boost/thread.hpp>
#include <boost/asio.hpp>
#include <functional>
/*
功能:延迟一段时间调用SendMessage发送Windows消息
测试环境:
[1]VS2013 Sp3
[2]boost 1.56
使用方式:
Step1:把CDelayEvent属性化为当前类成员。
Step2:在任意地方调用,例子如下
m_delayEvent.SendMessage(::SendMessage, GetSafeHwnd(), WM_MYUPDATEVIEW, 0, 0, 0);
可重复调用。
N次调用,会有N个事件等待执行。
Step3:
然后延迟一段时间后,SendMessage函数就会被调用。
*/
namespace kagula
{
typedef std::function<long (const HWND hwnd, const UINT msg,
const WPARAM wParam, const LPARAM lParam)> Callback;
class CDelayEvent
{
public:
CDelayEvent();
~CDelayEvent();
void SendMessage(Callback callback, const HWND hwnd, const UINT msg,
const WPARAM wParam=0, const LPARAM lParam=0, int millisecond=1000/30);
private:
boost::asio::io_service _service;
/*
if no _work object, after all thing done, the _service.run will continue
then thread will end.
*/
boost::asio::io_service::work _work;
boost::asio::deadline_timer _deadlineTimer;
boost::thread _thread;
};
}
#include <boost/thread.hpp>
#include <boost/asio.hpp>
#include <functional>
/*
功能:延迟一段时间调用SendMessage发送Windows消息
测试环境:
[1]VS2013 Sp3
[2]boost 1.56
使用方式:
Step1:把CDelayEvent属性化为当前类成员。
Step2:在任意地方调用,例子如下
m_delayEvent.SendMessage(::SendMessage, GetSafeHwnd(), WM_MYUPDATEVIEW, 0, 0, 0);
可重复调用。
N次调用,会有N个事件等待执行。
Step3:
然后延迟一段时间后,SendMessage函数就会被调用。
*/
namespace kagula
{
typedef std::function<long (const HWND hwnd, const UINT msg,
const WPARAM wParam, const LPARAM lParam)> Callback;
class CDelayEvent
{
public:
CDelayEvent();
~CDelayEvent();
void SendMessage(Callback callback, const HWND hwnd, const UINT msg,
const WPARAM wParam=0, const LPARAM lParam=0, int millisecond=1000/30);
private:
boost::asio::io_service _service;
/*
if no _work object, after all thing done, the _service.run will continue
then thread will end.
*/
boost::asio::io_service::work _work;
boost::asio::deadline_timer _deadlineTimer;
boost::thread _thread;
};
}
#include "stdafx.h" #include "DelayEvent.h" #include <boost/bind.hpp> namespace kagula { CDelayEvent::CDelayEvent() :_work(_service), _deadlineTimer(_service) { boost::thread t(boost::bind(&boost::asio::io_service::run, &_service)); _thread = boost::move(t); } CDelayEvent::~CDelayEvent() { _service.stop(); _thread.join(); } void CDelayEvent::SendMessage(Callback callback, const HWND hwnd, const UINT msg, const WPARAM wParam, const LPARAM lParam, int millisecond) { _deadlineTimer.expires_from_now(boost::posix_time::milliseconds(millisecond)); _deadlineTimer.async_wait(boost::bind(callback, hwnd, msg, wParam, lParam)); } }
相关文章推荐
- SendMessage和PostMessage发送windows消息的区别
- 工作线程调用sendmessage()向主对话框发送自定义消息遇到的问题以及解决
- C#调用WinAPI发送消息SendMessage
- sendmessage 发送消息
- C#控制Windows Messenger和Windows Live Messenger窗口发送消息
- 关于C# windows发送消息
- CLR 无法从 COM 上下文 0x1a2740 转换为 COM 上下文 0x1a28b0,这种状态已持续 60 秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个运行时间非常长的操作
- 使用C#编程将websphere MQ 5.3 windows客户端消息发送到linux服务器端
- vb利用FindWindow,GetWindowText,SendMessage查找程序并发送最小化消息
- 利用dbus-send在命令行下给程序发送消息,调用其相应的函数
- 如何用sendmessage(postmessage)往webbrowse里发送鼠标消息
- c#通过SendMessage发送消息,改变其他程序的下拉框控件(ComboBox)的值
- 利用Windows消息循环实现消息延迟和消息合并
- C#调用net.exe发送消息
- C#调用net.exe发送消息
- 应用程序间发送消息 c# SendMessage WM_COPYDATA
- 使用SendMessage方法对窗体上的控件进行截图,该方法的思想就是把控件的句柄拿到,对控件发送WM_PAINT消息,并且把希望得到图形对象的句柄当作wParam参数传过去,这样就可以在图形对象得到想要得图形。
- 只能用SendMessage发送消息WM_CopyData的分析
- 下层对象调用上层的对象--办法是向上层对象发送消息--- 类似PostMessage()
- c#通过SendMessage发送消息,改变其他程序的下拉框控件(ComboBox)的值