'創(chuàng)建一個列表框和一個按鈕'API函數(shù)定義Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As LongPrivate Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongConst GW_HWNDFIRST = 0Const GW_HWNDNEXT = 2Private Sub Command1_Click()Dim s As LongDim a As Stringa = Space(255)s = GetWindow(Me.hwnd, GW_HWNDFIRST) '獲得句柄GetWindowText s, a, 255 '獲得標題Dim ab As String * 255GetClassName s, ab, 255 '獲得類名Dim ClassName As StringClassName = StripTerFlag(ab) 'StripTerFlag是一個自定義函數(shù),后面有代碼,用于去處結束符If UCase(ClassName) = "NOTEPAD" ThenList1.AddItem aList1.ItemData(List1.ListCount - 1) = sEnd IfDo While sDoEventss = GetWindow(s, GW_HWNDNEXT) '獲得句柄GetWindowText s, a, 255 '獲得標題GetClassName s, ab, 255 '獲得類名ClassName = StripTerFlag(ab)If UCase(ClassName) = "NOTEPAD" ThenList1.AddItem aList1.ItemData(List1.ListCount - 1) = sEnd IfLoopEnd SubPrivate Sub List1_Click()MsgBox List1.ItemData(List1.ListIndex) '單擊列表框獲得句柄End Sub
1 回答

阿波羅的戰(zhàn)車
TA貢獻1862條經(jīng)驗 獲得超6個贊
ClassName = StripTerFlag(ab) 'StripTerFlag是一個自定義函數(shù),后面有代碼,用于去處結束符
你是不是把這個StripTerFlag過程代碼放到模塊中 而這個過程是Private私有過程 修改成public公用即可
- 1 回答
- 0 關注
- 361 瀏覽
添加回答
舉報
0/150
提交
取消