LoginSignup
1
2

More than 5 years have passed since last update.

一定時間がたったらメソッド実行。SetTimer/KillTimer内包のDelayFunkJr

Posted at

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);
});

参考

ドリー・ファンク・ジュニア

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2