Option ExplicitPrivate Declare Function GetDesktopWindow Lib "user32" () As LongPrivate Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As LongPrivate Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, _ ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _ ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _ ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1 Private Const HWND_TOPMOST = -1 Private Const GW_CHILD = 5 Private Const GW_HWNDNEXT = 2Private Sub Form_Load() SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Dim lngDeskTopHandle As Long Dim lngHand As Long Dim strName As String * 255 Dim lngWindowCount As Long lngDeskTopHandle = GetDesktopWindow() lngHand = GetWindow(lngDeskTopHandle, GW_CHILD) lngWindowCount = 1 Do While lngHand <> 0 GetWindowText lngHand, strName, Len(strName) lngHand = GetWindow(lngHand, GW_HWNDNEXT) If Left$(strName, 1) <> vbNullChar Then Me.list1.AddItem Left$(strName, InStr(1, strName, vbNullChar)) lngWindowCount = lngWindowCount + 1 End If Loop End Sub
ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const HWND_TOPMOST = -1
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Dim lngDeskTopHandle As Long
Dim lngHand As Long
Dim strName As String * 255
Dim lngWindowCount As Long lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
lngWindowCount = 1
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If Left$(strName, 1) <> vbNullChar Then
Me.list1.AddItem Left$(strName, InStr(1, strName, vbNullChar))
lngWindowCount = lngWindowCount + 1
End If
Loop
End Sub
用VB6没什么希望
或者我的程序运行后要监视按键操作,我又不想用timer(),因为会影响效率,还有其他的更底层的东西吗?比方说:在WINDOWS里哪个地方注册一下,WINDOWS在传送按键码时,也自动给我的程序通知。或有人在读硬盘时,WINDOWS自动告诉我的程序啊?