13 个解决方案
#1
WebBrowser
#2
IE浏览器窗口类名可是IEFrame哦
#3
注意区别:
IE类名:
IEFrame
用于api函数,如findwindow
IE注册的类名为:InternetExplorer.Application(不同系统可能不同,可通过regedit.exe程序查阅Hkey_Classes_Root项目,找出类名)
用于用createobject(getobject)创建(得到)对象
你要的是哪一个?
IE类名:
IEFrame
用于api函数,如findwindow
IE注册的类名为:InternetExplorer.Application(不同系统可能不同,可通过regedit.exe程序查阅Hkey_Classes_Root项目,找出类名)
用于用createobject(getobject)创建(得到)对象
你要的是哪一个?
#4
我是想在VB下,编一段程序,找到IE,使IE窗口置到前台(置前),用findwindow()却找不到IE窗口的类名,怎样实现?请指点。
#5
单击按钮,找到所有ie窗口的句柄,显示在listbox内,单击listbox显示所选窗口:
一个按钮,一个listbox:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SetForegroundWindow mwnd(i)
End Sub
一个按钮,一个listbox:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SetForegroundWindow mwnd(i)
End Sub
#6
厉害
向 rainstormmaster(rainstormmaster)学习
向 rainstormmaster(rainstormmaster)学习
#7
\\单击listbox显示所选窗口:
TO rainstormmaster(rainstormmaster)
我单击listbox里的内容,可是它所对应的窗口为什么不 显示呢?我用的WIN98和IE6
TO rainstormmaster(rainstormmaster)
我单击listbox里的内容,可是它所对应的窗口为什么不 显示呢?我用的WIN98和IE6
#8
哦~~~原来是在listbox的内容所对应的窗口最小化了,当不是最小化的时候,单击listbox显示所选窗口
请问rainstormmaster(rainstormmaster)如何在listbox里内容所对应窗口最小化的情况下,单击listbox显示所选窗口(给窗口已经最小化)
请问rainstormmaster(rainstormmaster)如何在listbox里内容所对应窗口最小化的情况下,单击listbox显示所选窗口(给窗口已经最小化)
#9
那就用SetWindowPos重设窗口位置:
声明:
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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 Long
说明:
这个函数能为窗口指定一个新位置和状态。它也可改变窗口在内部窗口列表中的位置。该函数与DeferWindowPos函数相似,只是它的作用是立即表现出来的(在vb里使用:针对vb窗体,如它们在win32下屏蔽或最小化,则需重设最顶部状态。如有必要,请用一个子类处理模块来重设最顶部状态
返回值:
Long,非零表示成功,零表示失败。会设置GetLastError
参数:
hwnd ----------- Long,欲定位的窗口
hWndInsertAfter - Long,窗口句柄。在窗口列表中,窗口hwnd会置于这个窗口句柄的后面。也可能选用下述值之一:
HWND_BOTTOM
将窗口置于窗口列表底部
HWND_TOP
将窗口置于Z序列的顶部;Z序列代表在分级结构中,窗口针对一个给定级别的窗口显示的顺序
HWND_TOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的前面
HWND_NOTOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的后面
x -------------- Long,窗口新的x坐标。如hwnd是一个子窗口,则x用父窗口的客户区坐标表示
y -------------- Long,窗口新的y坐标。如hwnd是一个子窗口,则y用父窗口的客户区坐标表示
cx ------------- Long,指定新的窗口宽度
cy ------------- Long,指定新的窗口高度
wFlags --------- Long,包含了旗标的一个整数
SWP_DRAWFRAME
围绕窗口画一个框
SWP_HIDEWINDOW
隐藏窗口
SWP_NOACTIVATE
不激活窗口
SWP_NOMOVE
保持当前位置(x和y设定将被忽略)
SWP_NOREDRAW
窗口不自动重画
SWP_NOSIZE
保持当前大小(cx和cy会被忽略)
SWP_NOZORDER
保持窗口在列表的当前位置(hWndInsertAfter将被忽略)
SWP_SHOWWINDOW
显示窗口
SWP_FRAMECHANGED
强迫一条WM_NCCALCSIZE消息进入窗口,即使窗口的大小没有改变窗口成为最*窗口后,它下属的所有窗口也会进入最*。一旦将其设为非最*,则它的所有下属和物主窗口也会转为非最*。Z序列用垂直于屏幕的一根假想Z轴量化这种从顶部到底部排列的窗口顺序
声明:
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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 Long
说明:
这个函数能为窗口指定一个新位置和状态。它也可改变窗口在内部窗口列表中的位置。该函数与DeferWindowPos函数相似,只是它的作用是立即表现出来的(在vb里使用:针对vb窗体,如它们在win32下屏蔽或最小化,则需重设最顶部状态。如有必要,请用一个子类处理模块来重设最顶部状态
返回值:
Long,非零表示成功,零表示失败。会设置GetLastError
参数:
hwnd ----------- Long,欲定位的窗口
hWndInsertAfter - Long,窗口句柄。在窗口列表中,窗口hwnd会置于这个窗口句柄的后面。也可能选用下述值之一:
HWND_BOTTOM
将窗口置于窗口列表底部
HWND_TOP
将窗口置于Z序列的顶部;Z序列代表在分级结构中,窗口针对一个给定级别的窗口显示的顺序
HWND_TOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的前面
HWND_NOTOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的后面
x -------------- Long,窗口新的x坐标。如hwnd是一个子窗口,则x用父窗口的客户区坐标表示
y -------------- Long,窗口新的y坐标。如hwnd是一个子窗口,则y用父窗口的客户区坐标表示
cx ------------- Long,指定新的窗口宽度
cy ------------- Long,指定新的窗口高度
wFlags --------- Long,包含了旗标的一个整数
SWP_DRAWFRAME
围绕窗口画一个框
SWP_HIDEWINDOW
隐藏窗口
SWP_NOACTIVATE
不激活窗口
SWP_NOMOVE
保持当前位置(x和y设定将被忽略)
SWP_NOREDRAW
窗口不自动重画
SWP_NOSIZE
保持当前大小(cx和cy会被忽略)
SWP_NOZORDER
保持窗口在列表的当前位置(hWndInsertAfter将被忽略)
SWP_SHOWWINDOW
显示窗口
SWP_FRAMECHANGED
强迫一条WM_NCCALCSIZE消息进入窗口,即使窗口的大小没有改变窗口成为最*窗口后,它下属的所有窗口也会进入最*。一旦将其设为非最*,则它的所有下属和物主窗口也会转为非最*。Z序列用垂直于屏幕的一根假想Z轴量化这种从顶部到底部排列的窗口顺序
#10
用spy或程序间谍什么的找类名,当然也可以用api啦
#11
谢谢,不过,我试了一下,我也碰到当IE窗口最小化时,想变大前置,却不能实现,怎么办呢?
#12
如果你是想在vb控制ie而不是自己做浏览器:
用这几个对象试试
Dim doc1 As New MSHTML.HTMLDocument
Dim shWin As New ShellWindows
Dim IEObj As New InternetExplorer
Dim item As Object
Private Sub Form_Load()
For Each IEObj In shWin
If InStr(1, IEObj.LocationURL, "Google", vbTextCompare) > 0 Then
If InStr(1, IEObj.Document.Title, "Google", vbTextCompare) > 0 Then
Set doc1 = IEObj.Document
Do Until doc1.readyState = "complete"
DoEvents
Loop
For Each item In doc1.All.tags("input")
If item.Name = "q" Then item.Value = "Searchstring"
Next
End If
Next
End Sub
用这几个对象试试
Dim doc1 As New MSHTML.HTMLDocument
Dim shWin As New ShellWindows
Dim IEObj As New InternetExplorer
Dim item As Object
Private Sub Form_Load()
For Each IEObj In shWin
If InStr(1, IEObj.LocationURL, "Google", vbTextCompare) > 0 Then
If InStr(1, IEObj.Document.Title, "Google", vbTextCompare) > 0 Then
Set doc1 = IEObj.Document
Do Until doc1.readyState = "complete"
DoEvents
Loop
For Each item In doc1.All.tags("input")
If item.Name = "q" Then item.Value = "Searchstring"
Next
End If
Next
End Sub
#13
'一个按钮 , 一个listbox:
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060& '关闭窗体
Private Const SC_MINIMIZE = &HF020& '最小化窗体
Private Const SC_MAXIMIZE = &HF030& '最大化窗体
Private Const SC_RESTORE = &HF120& '恢复窗体大小
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SendMessage mwnd(i), WM_SYSCOMMAND, SC_MAXIMIZE, ByVal 0 '使指定ie窗口最大化
SetForegroundWindow mwnd(i)
End Sub
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060& '关闭窗体
Private Const SC_MINIMIZE = &HF020& '最小化窗体
Private Const SC_MAXIMIZE = &HF030& '最大化窗体
Private Const SC_RESTORE = &HF120& '恢复窗体大小
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SendMessage mwnd(i), WM_SYSCOMMAND, SC_MAXIMIZE, ByVal 0 '使指定ie窗口最大化
SetForegroundWindow mwnd(i)
End Sub
#1
WebBrowser
#2
IE浏览器窗口类名可是IEFrame哦
#3
注意区别:
IE类名:
IEFrame
用于api函数,如findwindow
IE注册的类名为:InternetExplorer.Application(不同系统可能不同,可通过regedit.exe程序查阅Hkey_Classes_Root项目,找出类名)
用于用createobject(getobject)创建(得到)对象
你要的是哪一个?
IE类名:
IEFrame
用于api函数,如findwindow
IE注册的类名为:InternetExplorer.Application(不同系统可能不同,可通过regedit.exe程序查阅Hkey_Classes_Root项目,找出类名)
用于用createobject(getobject)创建(得到)对象
你要的是哪一个?
#4
我是想在VB下,编一段程序,找到IE,使IE窗口置到前台(置前),用findwindow()却找不到IE窗口的类名,怎样实现?请指点。
#5
单击按钮,找到所有ie窗口的句柄,显示在listbox内,单击listbox显示所选窗口:
一个按钮,一个listbox:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SetForegroundWindow mwnd(i)
End Sub
一个按钮,一个listbox:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SetForegroundWindow mwnd(i)
End Sub
#6
厉害
向 rainstormmaster(rainstormmaster)学习
向 rainstormmaster(rainstormmaster)学习
#7
\\单击listbox显示所选窗口:
TO rainstormmaster(rainstormmaster)
我单击listbox里的内容,可是它所对应的窗口为什么不 显示呢?我用的WIN98和IE6
TO rainstormmaster(rainstormmaster)
我单击listbox里的内容,可是它所对应的窗口为什么不 显示呢?我用的WIN98和IE6
#8
哦~~~原来是在listbox的内容所对应的窗口最小化了,当不是最小化的时候,单击listbox显示所选窗口
请问rainstormmaster(rainstormmaster)如何在listbox里内容所对应窗口最小化的情况下,单击listbox显示所选窗口(给窗口已经最小化)
请问rainstormmaster(rainstormmaster)如何在listbox里内容所对应窗口最小化的情况下,单击listbox显示所选窗口(给窗口已经最小化)
#9
那就用SetWindowPos重设窗口位置:
声明:
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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 Long
说明:
这个函数能为窗口指定一个新位置和状态。它也可改变窗口在内部窗口列表中的位置。该函数与DeferWindowPos函数相似,只是它的作用是立即表现出来的(在vb里使用:针对vb窗体,如它们在win32下屏蔽或最小化,则需重设最顶部状态。如有必要,请用一个子类处理模块来重设最顶部状态
返回值:
Long,非零表示成功,零表示失败。会设置GetLastError
参数:
hwnd ----------- Long,欲定位的窗口
hWndInsertAfter - Long,窗口句柄。在窗口列表中,窗口hwnd会置于这个窗口句柄的后面。也可能选用下述值之一:
HWND_BOTTOM
将窗口置于窗口列表底部
HWND_TOP
将窗口置于Z序列的顶部;Z序列代表在分级结构中,窗口针对一个给定级别的窗口显示的顺序
HWND_TOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的前面
HWND_NOTOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的后面
x -------------- Long,窗口新的x坐标。如hwnd是一个子窗口,则x用父窗口的客户区坐标表示
y -------------- Long,窗口新的y坐标。如hwnd是一个子窗口,则y用父窗口的客户区坐标表示
cx ------------- Long,指定新的窗口宽度
cy ------------- Long,指定新的窗口高度
wFlags --------- Long,包含了旗标的一个整数
SWP_DRAWFRAME
围绕窗口画一个框
SWP_HIDEWINDOW
隐藏窗口
SWP_NOACTIVATE
不激活窗口
SWP_NOMOVE
保持当前位置(x和y设定将被忽略)
SWP_NOREDRAW
窗口不自动重画
SWP_NOSIZE
保持当前大小(cx和cy会被忽略)
SWP_NOZORDER
保持窗口在列表的当前位置(hWndInsertAfter将被忽略)
SWP_SHOWWINDOW
显示窗口
SWP_FRAMECHANGED
强迫一条WM_NCCALCSIZE消息进入窗口,即使窗口的大小没有改变窗口成为最*窗口后,它下属的所有窗口也会进入最*。一旦将其设为非最*,则它的所有下属和物主窗口也会转为非最*。Z序列用垂直于屏幕的一根假想Z轴量化这种从顶部到底部排列的窗口顺序
声明:
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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 Long
说明:
这个函数能为窗口指定一个新位置和状态。它也可改变窗口在内部窗口列表中的位置。该函数与DeferWindowPos函数相似,只是它的作用是立即表现出来的(在vb里使用:针对vb窗体,如它们在win32下屏蔽或最小化,则需重设最顶部状态。如有必要,请用一个子类处理模块来重设最顶部状态
返回值:
Long,非零表示成功,零表示失败。会设置GetLastError
参数:
hwnd ----------- Long,欲定位的窗口
hWndInsertAfter - Long,窗口句柄。在窗口列表中,窗口hwnd会置于这个窗口句柄的后面。也可能选用下述值之一:
HWND_BOTTOM
将窗口置于窗口列表底部
HWND_TOP
将窗口置于Z序列的顶部;Z序列代表在分级结构中,窗口针对一个给定级别的窗口显示的顺序
HWND_TOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的前面
HWND_NOTOPMOST
将窗口置于列表顶部,并位于任何最顶部窗口的后面
x -------------- Long,窗口新的x坐标。如hwnd是一个子窗口,则x用父窗口的客户区坐标表示
y -------------- Long,窗口新的y坐标。如hwnd是一个子窗口,则y用父窗口的客户区坐标表示
cx ------------- Long,指定新的窗口宽度
cy ------------- Long,指定新的窗口高度
wFlags --------- Long,包含了旗标的一个整数
SWP_DRAWFRAME
围绕窗口画一个框
SWP_HIDEWINDOW
隐藏窗口
SWP_NOACTIVATE
不激活窗口
SWP_NOMOVE
保持当前位置(x和y设定将被忽略)
SWP_NOREDRAW
窗口不自动重画
SWP_NOSIZE
保持当前大小(cx和cy会被忽略)
SWP_NOZORDER
保持窗口在列表的当前位置(hWndInsertAfter将被忽略)
SWP_SHOWWINDOW
显示窗口
SWP_FRAMECHANGED
强迫一条WM_NCCALCSIZE消息进入窗口,即使窗口的大小没有改变窗口成为最*窗口后,它下属的所有窗口也会进入最*。一旦将其设为非最*,则它的所有下属和物主窗口也会转为非最*。Z序列用垂直于屏幕的一根假想Z轴量化这种从顶部到底部排列的窗口顺序
#10
用spy或程序间谍什么的找类名,当然也可以用api啦
#11
谢谢,不过,我试了一下,我也碰到当IE窗口最小化时,想变大前置,却不能实现,怎么办呢?
#12
如果你是想在vb控制ie而不是自己做浏览器:
用这几个对象试试
Dim doc1 As New MSHTML.HTMLDocument
Dim shWin As New ShellWindows
Dim IEObj As New InternetExplorer
Dim item As Object
Private Sub Form_Load()
For Each IEObj In shWin
If InStr(1, IEObj.LocationURL, "Google", vbTextCompare) > 0 Then
If InStr(1, IEObj.Document.Title, "Google", vbTextCompare) > 0 Then
Set doc1 = IEObj.Document
Do Until doc1.readyState = "complete"
DoEvents
Loop
For Each item In doc1.All.tags("input")
If item.Name = "q" Then item.Value = "Searchstring"
Next
End If
Next
End Sub
用这几个对象试试
Dim doc1 As New MSHTML.HTMLDocument
Dim shWin As New ShellWindows
Dim IEObj As New InternetExplorer
Dim item As Object
Private Sub Form_Load()
For Each IEObj In shWin
If InStr(1, IEObj.LocationURL, "Google", vbTextCompare) > 0 Then
If InStr(1, IEObj.Document.Title, "Google", vbTextCompare) > 0 Then
Set doc1 = IEObj.Document
Do Until doc1.readyState = "complete"
DoEvents
Loop
For Each item In doc1.All.tags("input")
If item.Name = "q" Then item.Value = "Searchstring"
Next
End If
Next
End Sub
#13
'一个按钮 , 一个listbox:
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060& '关闭窗体
Private Const SC_MINIMIZE = &HF020& '最小化窗体
Private Const SC_MAXIMIZE = &HF030& '最大化窗体
Private Const SC_RESTORE = &HF120& '恢复窗体大小
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SendMessage mwnd(i), WM_SYSCOMMAND, SC_MAXIMIZE, ByVal 0 '使指定ie窗口最大化
SetForegroundWindow mwnd(i)
End Sub
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060& '关闭窗体
Private Const SC_MINIMIZE = &HF020& '最小化窗体
Private Const SC_MAXIMIZE = &HF030& '最大化窗体
Private Const SC_RESTORE = &HF120& '恢复窗体大小
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Const GW_HWNDNEXT = 2
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim mwnd() As Long
Private Sub Command1_Click()
List1.Clear
Dim k As Long
k = 0
Dim mhwnd As Long
Dim cname As String * 260
Dim classname As String
mhwnd = FindWindow("IEFrame", vbNullString)
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
Dim s As String * 260
GetWindowText mhwnd, s, 260
Dim ss As String
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
If mhwnd <> 0 Then
Do While mhwnd <> 0
mhwnd = GetNextWindow(mhwnd, GW_HWNDNEXT)
GetClassName mhwnd, cname, 260
classname = Left(cname, InStr(1, cname, Chr(0)) - 1)
If UCase(classname) = "IEFRAME" Then
k = k + 1
ReDim Preserve mwnd(k)
mwnd(k) = mhwnd
GetWindowText mhwnd, s, 260
ss = Left(s, InStr(1, s, Chr(0)) - 1)
ss = "hwnd=" + CStr(mhwnd) + " 标题为:" + ss
List1.AddItem ss
End If
Loop
End If
End Sub
Private Sub List1_Click()
Dim i As Long
i = List1.ListIndex
SendMessage mwnd(i), WM_SYSCOMMAND, SC_MAXIMIZE, ByVal 0 '使指定ie窗口最大化
SetForegroundWindow mwnd(i)
End Sub