如何获得活动的窗口地址...? [英] How to get active window address....?

查看:93
本文介绍了如何获得活动的窗口地址...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在vb6中获取活动的窗口地址...?

我的意思是,当我们打开任何驱动器或文件夹时,我们在地址栏上得到一个地址.如果我们打开程序文件",那么我们在地址栏上得到一个地址,即"C:\ Program File",我想使用代码将该地址指向该地址. />
我有以下获取活动窗口标题的示例,但我想要活动窗口路径.

How to get active window address in vb6...?

I mean when we open any drive or folder we get one address on address bar.If we open Program Files then we get one address that is "C:\Program File" on address bar and i want to that address using code.

I have following example for get active window title but i want active window path.

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long

Public Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
    Dim i As Long
    Dim j As Long
    i = GetForegroundWindow
    If ReturnParent Then
    Do While i <> 0
    j = i
    i = GetParent(i)
    Loop
    i = j
    End If
    GetActiveWindowTitle = GetWindowTitle(i)
End Function
Public Function GetWindowTitle(ByVal hwnd As Long) As String
Dim l As Long
Dim s As String
l = GetWindowTextLength(hwnd)
s = Space(l + 1)

GetWindowText hwnd, s, l + 1

GetWindowTitle = Left$(s, l)
End Function

Private Sub Timer1_Timer()
Print GetActiveWindowTitle(GetActiveWindow)
If Trim(GetActiveWindowTitle(GetActiveWindow)) = "Yahoo" Then
    X = SetActiveWindow(i)
    SendKeys ("%{S}")
End If
If Trim(GetActiveWindowTitle(GetActiveWindow)) = "Save As" Then
    X = SetActiveWindow(i)
    Clipboard.SetText "D:\kc.txt"
    SendKeys ("%{N}")
    SendKeys ("^{V}")
    SendKeys ("{TAB}")
    SendKeys ("{TAB}")
    Timer1.Interval = 0
End If
End Sub


如果我打开程序文件,则此代码仅显示"Program Files",表示活动窗口的标题,但我想定位活动窗口的位置.

请帮助我.


If i open program files then this code just show "Program Files" means title of active window but i want to location of active window.

Please help me.

推荐答案

(s,l) 结束功能 专用子Timer1_Timer() 打印GetActiveWindowTitle(GetActiveWindow) 如果Trim(GetActiveWindowTitle(GetActiveWindow))="Yahoo",则 X = SetActiveWindow(i) SendKeys(%{S}") 万一 如果Trim(GetActiveWindowTitle(GetActiveWindow))=另存为",则 X = SetActiveWindow(i) Clipboard.SetText"D:\ kc.txt" SendKeys(%{N}") SendKeys("^ {V}") SendKeys("{TAB}") SendKeys("{TAB}") Timer1.Interval = 0 万一 结束Sub
(s, l) End Function Private Sub Timer1_Timer() Print GetActiveWindowTitle(GetActiveWindow) If Trim(GetActiveWindowTitle(GetActiveWindow)) = "Yahoo" Then X = SetActiveWindow(i) SendKeys ("%{S}") End If If Trim(GetActiveWindowTitle(GetActiveWindow)) = "Save As" Then X = SetActiveWindow(i) Clipboard.SetText "D:\kc.txt" SendKeys ("%{N}") SendKeys ("^{V}") SendKeys ("{TAB}") SendKeys ("{TAB}") Timer1.Interval = 0 End If End Sub


如果我打开程序文件,则此代码仅显示"Program Files",表示活动窗口的标题,但我想定位活动窗口的位置.

请帮助我.


If i open program files then this code just show "Program Files" means title of active window but i want to location of active window.

Please help me.


如果我理解正确,请尝试从App.Path
If I understood correctly, try getting the startup location information from App.Path


获取启动位置信息Windows没有路径.期间.

—SA
Windows do not have paths. Period.

—SA


这篇关于如何获得活动的窗口地址...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆