
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDFIRST = 0
Private Const WM_GETTEXT = &HD
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Function GetWindowList() As String
Dim hwnd As Long
Dim s As String
hwnd = Mehwnd
hwnd = GetWindow(hwnd, GW_HWNDFIRST)
While hwnd <> 0
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
If s = "CabinetWClass" Then
GetWindowList = GetWindowList & GetUrl(hwnd) & vbCrLf
End If
hwnd = GetNextWindow(hwnd, GW_HWNDNEXT)
Wend
End Function
Private Function GetUrl(hwnd As Long) As String
Dim NexthWnd As Long
Dim s As String
NexthWnd = 0
NexthWnd = FindWindowEx(hwnd, NexthWnd, vbNullString, vbNullString)
While NexthWnd <> 0
s = String(256, Chr(0))
GetClassName NexthWnd, s, 255
s = Replace(s, Chr(0), "")
If s = "Edit" Then
s = String(256, Chr(0))
SendMessage NexthWnd, WM_GETTEXT, 255, s
s = Replace(s, Chr(0), "")
GetUrl = s
If Len(s) > 0 Then Exit Function
Else
GetUrl = GetUrl(NexthWnd)
If Len(GetUrl) > 0 Then Exit Function
End If
NexthWnd = FindWindowEx(hwnd, NexthWnd, vbNullString, vbNullString)
Wend
End Function
Private Sub Command1_Click()
text1text=GetWindowList
End Sub
能,几个API函数的事情
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal Hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim Hwnd As Long
Dim WinRECT As RECT
Hwnd = FindWindow("Shell_TrayWnd", vbNullString)
GetWindowRect Hwnd, WinRECT
MsgBox "任务栏长度: " & WinRECTRight - WinRECTLeft & vbCrLf & "任务栏宽度: " & WinRECTBottom - WinRECTTop, , "单位:Pixel"
End Sub
得出的宽度,长度单位是Pixel,根据你的需要换算一下,如果你的窗体是Twip模式的那么就把原值乘以15就好了。
在窗体上建一个叫"CMB_Hide"的按钮,然后粘贴下述代码,等你按CMB_Hide按钮的时候,窗体就收到系统托盘了。
Option Explicit
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private nfIconData As NOTIFYICONDATA
Private Sub CMB_Hide_Click()
ShowWindow Mehwnd, SW_HIDE
End Sub
Private Sub Form_DblClick()
MeShow
MeWindowState = 0
End Sub
答案补充:兄弟,不可能不行啊。我都是亲自测试好了才发上答案来的!
===============
先把BorderStyle属性设置为0,然后把ShowInTaskBar属性设置为True(注意:次序不可颠倒)。但是,此时只是一个任务栏标题,右键不会有菜单。
Option Explicit
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 Long
Public Const HWND_TOPMOST = -1
Public Const HWND_TOP = -1
Public Const SWP_SHOWWINDOW = &H40
Private Sub Form_Load()
Dim retValue As Long retValue = SetWindowPos(Mehwnd, HWND_TOPMOST, 0, 0, MeWidth, MeHeight, SWP_SHOWWINDOW)
End Sub
获取任务栏高度>
以上就是关于VB如何获取窗口地址栏内容全部的内容,包括:VB如何获取窗口地址栏内容、VB如何判断出任务栏的高度。、用vb如何实现刷新任务栏等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)