- 分享
- 0
- 人气
- 0
- 主题
- 62
- 帖子
- 6367
- UID
- 51295
- 积分
- 3715
- 阅读权限
- 21
- 注册时间
- 2006-11-21
- 最后登录
- 2022-1-19
- 在线时间
- 3699 小时
|
我找了很多东西还是看不懂!
MSDN写得很简略
我上网找了这个
- Public Class Form1
- Private Declare Function GetForegroundWindow Lib "user32" () As Integer
- Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
- hWnd As Integer, ByRef lpdwProcessId As Integer) As Integer
- Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
- (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer,
- ByVal lParam As Integer) As Integer
- Private Declare Function GetGUIThreadInfo Lib "user32.dll" (ByVal
- idThread As Integer, ByRef pgui As GUITHREADINFO) As Integer
- Private Const WM_COPY As Integer = &H301
- Private Structure RECT
- Dim Left_Renamed As Integer
- Dim Top As Integer
- Dim Right_Renamed As Integer
- Dim Bottom As Integer
- End Structure
- Private Structure GUITHREADINFO
- Dim cbSize As Integer
- Dim flags As Integer
- Dim hwndActive As Integer
- Dim hwndFocus As Integer
- Dim hwndCapture As Integer
- Dim hwndMenuOwner As Integer
- Dim hwndMoveSize As Integer
- Dim hwndCaret As Integer
- Dim rcCaret As RECT
- End Structure
- Private Function GetFocusWindow() As Integer
- Dim h As Integer
- Dim ThreadID As Integer
- Dim gui As GUITHREADINFO
- Dim ret As Integer
- h = GetForegroundWindow()
- Console.WriteLine("GetFocusWindow: ForegroundWindow = " & Hex(h))
- ThreadID = GetWindowThreadProcessId(h, 0)
- gui.cbSize = Len(gui)
- ret = GetGUIThreadInfo(ThreadID, gui)
- If ret = 0 Then
- Console.WriteLine("GetFocusWindow: GetGUIThreadInfo failed.
- LastDllError = " & Err.LastDllError)
- Exit Function
- End If
- Console.WriteLine("GetFocusWindow: hwndFocus = " &
- Hex(gui.hwndFocus))
- GetFocusWindow = gui.hwndFocus
- End Function
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
- System.EventArgs) Handles Timer1.Tick
- Me.Text = Hex(GetFocusWindow())
- SendCopyToWindow(GetFocusWindow())
- TextBox1.Text = Clipboard.GetText
- End Sub
- Private Sub SendCopyToWindow(ByVal hWnd As Integer)
- SendMessage(hWnd, WM_COPY, 0, 0)
- End Sub
- End Class
复制代码 GUITHREADINFO 是 GUI 的类型吗?
这个API他return boolean,true的话就是那个类型,false的话就不是? |
|