Code
# include <functional>
typedef std::function<void()> Func;
class DelayFunkJr
{
public:
static void spinning_toe_hold(UINT Elapse, Func func)
{
Funk_ = func;
timer_id_= ::SetTimer( NULL, NULL, Elapse, DelayFunkJr::hey_Terry );
}
private:
static void CALLBACK hey_Terry(HWND hwnd,UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
::KillTimer( NULL, timer_id_ );
if ( Funk_ ){
Funk_();
}
reset();
}
static void reset()
{
Funk_ = nullptr;
timer_id_ = 0;
}
static Func Funk_;
static UINT_PTR timer_id_;
};
Func DelayFunkJr::Funk_ = nullptr;
UINT_PTR DelayFunkJr::timer_id_ = 0;
Usage
1秒後にドリー兄さんの深いお言葉
DelayFunkJr::spinning_toe_hold(1000, [](){
::MessageBox( 0, _T("いきてるってなーんだろ"), MB_OK);
});