如何得到当前打开窗口的句柄?

spirit00 2003-03-30 10:18:20
如何得到当前打开窗口的句柄?我只要当前打开窗口的句柄,后天运行的不要。
...全文
68 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Intelement 2003-04-01
  • 打赏
  • 举报
回复
'Add this code to a module
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
Form1.List1.AddItem Str$(hwnd) + " " + sSave
'continue enumeration
EnumWindowsProc = True
End Function

'Add this code to a form
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Set the form's graphics mode to persistent
'call the Enumwindows-function
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
spirit00 2003-04-01
  • 打赏
  • 举报
回复
不好意思,我的要求是要得到所有打开的窗口的句柄或TITLE
Sean918 2003-04-01
  • 打赏
  • 举报
回复
'in a form
Private Sub Form_Load()
Me.AutoRedraw = True
EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0&
End Sub
'in a module
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength(hwnd) + 1)
'get the window text
GetWindowText hwnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave <> "" Then Form1.Print sSave
'continue enumeration
EnumChildProc = 1
End Function
Intelement 2003-03-30
  • 打赏
  • 举报
回复
--GetActiveWindow
The GetActiveWindow function retrieves the window handle to the active window associated with the calling thread's message queue.
--HWND GetActiveWindow(VOID)

--GetForegroundWindow
The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.
--HWND GetForegroundWindow(VOID)

Maconel 2003-03-30
  • 打赏
  • 举报
回复
用api
findwindow
spirit00 2003-03-30
  • 打赏
  • 举报
回复
错了,是后台运行的不要。谢谢
用户 昵称 2003-03-30
  • 打赏
  • 举报
回复
GetActiveWindow
GetForeGroundWindow
Sean918 2003-03-30
  • 打赏
  • 举报
回复
hoho~~~楼上的可以用用
dsclub 2003-03-30
  • 打赏
  • 举报
回复
'This Project needs
'- two timers, interval=100
'- a button

'in general section
Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Timer2.Interval = 100
Timer2.Enabled = True
Command1.Caption = "Draw Text"
End Sub
'This will draw an Ellipse on the active window
Sub Timer1_Timer()
Dim Position As POINTAPI
'Get the cursor position
GetCursorPos Position
'Draw the Ellipse on the Screen's DC
Ellipse GetWindowDC(0), Position.x - 5, Position.y - 5, Position.x + 5, Position.y + 5
End Sub
Sub Command1_Click()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net

Dim intCount As Integer, strString As String
strString = "Cool, text on screen !"
For intCount = 0 To 30
'Draw the text on the screen
TextOut GetWindowDC(0), intCount * 20, intCount * 20, strString, Len(strString)
Next intCount
End Sub
Private Sub Timer2_Timer()
'Draw the text to the active window
TextOut GetWindowDC(GetActiveWindow), 50, 50, "This is a form", 14
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧