文書番号: 112649
最終更新日: 2003/08/01
Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "User32" (lpPoint As _ POINTAPI) As Long Private Declare Function WindowFromPointXY Lib "User32" Alias _ "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) _ As Long Private Declare Function GetModuleFileName Lib "kernel32" Alias _ "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As _ String, ByVal nSize As Long) As Long Private Declare Function GetWindowWord Lib "User32" (ByVal hwnd As _ Long, ByVal nIndex As Long) As Integer Private Declare Function GetWindowLong Lib "User32" Alias _ "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As _ Long Private Declare Function GetParent Lib "User32" (ByVal hwnd As _ Long) 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 GetWindowText Lib "User32" Alias _ "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, _ ByVal cch As Long) As Long Const GWW_HINSTANCE = (-6) Const GWW_ID = (-12) Const GWL_STYLE = (-16)
Sub Timer1_Timer() Dim pt32 As POINTAPI Dim ptx As Long Dim pty As Long Dim sWindowText As String * 100 Dim sClassName As String * 100 Dim hWndOver As Long Dim hWndParent As Long Dim sParentClassName As String * 100 Dim wID As Long Dim lWindowStyle As Long Dim hInstance As Long Dim sParentWindowText As String * 100 Dim sModuleFileName As String * 100 Static hWndLast As Long Call GetCursorPos(pt32) ' カーソル位置を取得 ptx = pt32.x pty = pt32.y ' カーソルの位置しているウィンドウを取得 hWndOver = WindowFromPointXY(ptx, pty) If hWndOver <> hWndLast Then ' 変更があったら表示する hWndLast = hWndOver ' 変更の保存 Cls ' 描画のクリア Print "Window Handle: &H"; Hex(hWndOver) ' ウィンドウハンドルの表示 r = GetWindowText(hWndOver, sWindowText, 100) ' ウィンドウテキス ト Print "Window Text: " & Left(sWindowText, r) r = GetClassName(hWndOver, sClassName, 100) ' ウィンドウクラス Print "Window Class Name: "; Left(sClassName, r) lWindowStyle = GetWindowLong(hWndOver, GWL_STYLE) ' ウィンドウスタイ ル Print "Window Style: &H"; Hex(lWindowStyle) ' 親ウィンドウハンドルの取得 hWndParent = GetParent(hWndOver) ' 親ウィンドウがあれば、さらに情報を取得 If hWndParent <> 0 Then ' ウィンドウ ID の取得 wID = GetWindowWord(hWndOver, GWW_ID) Print "Window ID Number: &H"; Hex(wID) Print "Parent Window Handle: &H"; Hex(hWndParent) ' 親ウィンドウテキストの取得 r = GetWindowText(hWndParent, sParentWindowText, 100) Print "Parent Window Text: " & Left(sParentWindowText, r) ' 親ウィンドウクラス名の取得 r = GetClassName(hWndParent, sParentClassName, 100) Print "Parent Window Class Name: "; Left(sParentClassName, r) Else ' 親ウィンドウがないとき Print "Window ID Number: N/A" Print "Parent Window Handle: N/A" Print "Parent Window Text : N/A" Print "Parent Window Class Name: N/A" End If ' ウィンドウインスタンスの取得 hInstance = GetWindowWord(hWndOver, GWW_HINSTANCE) ' モジュール名の取得 r = GetModuleFileName(hInstance, sModuleFileName, 100) Print "Module: "; Left(sModuleFileName, r) End If End Sub
Additional query words: ClassName FindWindow
Keywords: KBHOWTO VB5 VB6 KB112649
Technology: kbAudDeveloper kbVB16bitSearch kbVB300 kbVB300Search kbVB400 kbVB400Search kbVB500 kbVB500Search kbVBSearch kbZNotKeyword2 kbZNotKeyword6