Window-03 ウィンドウのタイトルバー・タスクバーのボタンを点滅させる(2)

Q 前回の点滅させる方法を見ましたが、1回しか点滅させられないのは納得がいきません。3回とか5回などと、回数を指定して点滅させる方法をお願いします。
A 贅沢ですね(笑) FlashWindowEx関数を使います。
但し、Win95・WinNT4.0の方にはこの関数が対応していないため諦めていただきましょう(^^;;
[いや、後でちゃんとWin95・WinNT4.0でも対応している方法をご紹介しますので…。]
どう使う?
'構造体の宣言(コードの一番上の部分に書くことを推奨)
Type FLASHWINFO
    cbSize As DWord
    hWnd As HWND
    dwFlags As DWord
    uCount As DWord
    dwTimeout As DWord
End Type
'関数の宣言(構造体の宣言のすぐ後に書くことを推奨)

Declare Function FlashWindowEx Lib "user32" (ByRef pfwi As FLASHWINFO) As Long
'※RADツールで作成したウィンドウ MainWnd を点滅の対象とする。

Dim udtFlashWInfo As FLASHWINFO
With udtFlashWInfo
    .cbSize=Len(udtFlashWInfo)
    .hWnd=hMainWnd 'ウィンドウハンドル
    .dwFlags=3
    .uCount=5 '点滅の回数
    .dwTimeout=0
End With
FlashWindowEx(udtFlashWInfo)
'↑を実行後 5回点滅する
これで回数を指定した点滅が可能になります。
しかし、残念ながらFlashWindowEx関数はWin95・WinNT4.0に対応していないのです。
これでは、それ以外のOSをお使いの方であっても、すべてのOSに対応するプログラムを作るのには具合が悪くなります。
そこで、タイマーを使った、ある意味強制的な回数指定で点滅させる方法をご紹介しておきます。
(あまり動作が安定しませんが)

'関数の宣言(コードの一番上の部分に書くことを推奨)
Declare Function
timeSetEvent Lib "winmm" (uDelay As DWord, uResolution As DWord, lpTimeProc As DWord, dwUser As DWordPtr, fuEvent As DWord) As DWord
Declare Function timeKillEvent Lib "winmm" (uTimerID As DWord) As DWord
Declare Function GetCaretBlinkTime Lib "user32" () As DWord
'グローバル変数の宣言
Dim dwFlashCount As DWord
Dim uTimerID As DWord

'コールバック関数の宣言
Function FlashTimeProc(uID As DWord, uMsg As DWord, dwUser As DWord, dw1 As DWord, dw2 As DWord) As DWord
    FlashWindow(dwUser,TRUE)
    dwFlashCount=dwFlashCount-1
    If dwFlashCount=0 Then timeKillEvent(uTimerID)
End Function


'ウィンドウのタイトルバー・タスクバーを点滅させる関数の宣言
Sub FlashWindowEx2(hWnd As HWND, FlashCount As DWord)
    If dwFlashCount Then timeKillEvent(uTimerID)
    If FlashCount>=2 Then
        FlashWindow(hWnd,TRUE)
        dwFlashCount=FlashCount-1
        uTimerID=timeSetEvent(GetCaretBlinkTime()*2,0,AddressOf(FlashTimeProc),hWnd,1)
    ElseIf FlashCount=1 Then
        FlashWindow(hWnd,TRUE)
    End If
End Sub
'※RADツールで作成したウィンドウ MainWnd を点滅の対象とする。

FlashWindowEx2(hMainWnd,5)
'↑を実行後 5回点滅する
'プログラム終了時に実行するコード
If dwFlashCount Then timeKillEvent(uTimerID)

メニューに戻る