デスクトップクリックを検出する

 


'フォームにタイマーコントロールを貼り付けて以下をペーストする

Option Explicit

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


Private Sub Timer1_Timer()
Dim hWind As Long
Dim lpClassName As String * 250
Dim MaxCount As Long
Dim ret As Long
Static hWindOld As Long

hWind = GetForegroundWindow()
Debug.Print hWind
MaxCount = Len(lpClassName)
ret = GetClassName(hWind, lpClassName, MaxCount)
If Left(lpClassName, InStr(lpClassName, vbNullChar) - 1) = "Progman" Then
Call MsgBox("Click", vbInformation, "")
SetForegroundWindow hWindOld
Else
hWindOld = hWind
End If
End Sub


トップページに戻る

Tips一覧に戻る