以下是引用WHYFUN在2004-3-13 9:22:00的发言: 各位,请问在EXCEL的VBA中,如何用API 函数FINDWINDOW取得控件(如TEXTBOX,LISTBOX等)的句柄HANDLE?
FINDWINDOW的语法如下:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
请教其中的lpClassName和lpWindowName该如何取值,自带的说明文件实在不懂啊:
Dim hw& , cnt& Dim rttitle As String * 256 hw& = FindWindow("ThunderRT5Main", vbNullString) ' ThunderRTMain under VB4 cnt = GetWindowText(hw& , rttitle, 255) MsgBox Left$(rttitle, cnt), 0, "RTMain title"
WHYFUN 你好:
配合GetFocus API函数,就能取得Control的 Hwnd
请在窗体建立一个 CommandButton,及 Listbox
请参考
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Property Get GetTextbox_hWnd() As Long ListBox1.SetFocus GetTextbox_hWnd = GetFocus() End Property
Private Sub CommandButton1_Click() MsgBox GetTextbox_hWnd End Sub
|