VB返回任务栏所有程序
就是这个意思,例如当前计算机运行下图的4个程序,我想在窗体上打印出这四个程序标题,即:杜昌彬angelcsf-zhanghaoxnm2345导航百度知道问问后面QQ图标程...
就是这个意思,例如当前计算机运行下图的4个程序,我想在窗体上打印出这四个程序标题,即:杜昌彬 angelcsf-zhanghaoxnm 2345导航 百度知道问问 后面QQ图标程序就不管了
展开
展开全部
建议使用枚举窗体的API函数
FindWindowsEx(忘了是window还是windows了)
你可以去查一下API函数技术资料
或者相关的MSDN
FindWindowsEx(忘了是window还是windows了)
你可以去查一下API函数技术资料
或者相关的MSDN
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分三步:
一、建立一个模拟,复制下面代码:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 OpenProcess Lib "KERNEL32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
Private Const READ_CONTROL As Long = &H20000
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const STANDARD_RIGHTS_READ As Long = (READ_CONTROL)
Private Const STANDARD_RIGHTS_EXECUTE As Long = (READ_CONTROL)
Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Private Const STANDARD_RIGHTS_WRITE As Long = (READ_CONTROL)
Private Const SYNCHRONIZE As Long = &H100000
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Const PROCESS_TERMINATE As Long = (&H1)
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Const WM_USER As Long = &H400
Private Const TB_BUTTONCOUNT As Long = (WM_USER + 24)
Private Const TB_HIDEBUTTON As Long = (WM_USER + 4)
Private Const TB_GETBUTTON As Long = (WM_USER + 23)
Private Const TB_GETBITMAP As Long = (WM_USER + 44)
Private Const TB_DELETEBUTTON As Long = (WM_USER + 22)
Private Const TB_ADDBUTTONS As Long = (WM_USER + 20)
Private Const TB_INSERTBUTTON As Long = (WM_USER + 21)
Private Const TB_ISBUTTONHIDDEN As Long = (WM_USER + 12)
Private Const ILD_NORMAL As Long = &H0
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function WriteProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long
Private Const PROCESS_VM_OPERATION As Long = (&H8)
Private Const PROCESS_VM_READ As Long = (&H10)
Private Const PROCESS_VM_WRITE As Long = (&H20)
Private Const MEM_RESERVE As Long = &H2000
Private Const MEM_COMMIT As Long = &H1000
Private Const MEM_RELEASE As Long = &H8000
Private Const PAGE_READWRITE As Long = &H4
'功能:获取任务栏内的窗口名称
Function GetSysTrayMsg() As String
Dim lngTemp As Long
Dim lngTray, Hwd As Long
Dim lngPID As Long
Dim lngPID2 As Long
Dim hProcess As Long
Dim lngProcess As Long
Dim lngAddress As Long
Dim lngCount As Long
Dim lngButtons As Long
Dim ret As Long
Dim lngTextAdr As Long
Dim lngHwndAdr As Long
Dim lngButtonID As Long
Dim hIcon As Long
Dim lngHwnd As Long
Dim lpFileName As String * 1024
Dim i As Long
Dim strBuff(1024) As Byte
Dim strText As String
Dim lngTrayDC As Long
lngTemp = FindWindow("Shell_TrayWnd", vbNullString)
lngTemp = FindWindowEx(lngTemp, 0, "ReBarWindow32", vbNullString)
lngTemp = FindWindowEx(lngTemp, 0, "MSTaskSwWClass", vbNullString)
lngTray = FindWindowEx(lngTemp, 0, "ToolbarWindow32", vbNullString)
ret = GetWindowThreadProcessId(lngTray, lngPID)
hProcess = OpenProcess(PROCESS_ALL_ACCESS Or PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, lngPID)
lngAddress = VirtualAllocEx(hProcess, ByVal 0&, ByVal 4096&, MEM_COMMIT, PAGE_READWRITE)
lngButtons = SendMessage(lngTray, TB_BUTTONCOUNT, 0, 0)
For i = 1 To lngButtons - 1 Step 2
ret = SendMessage(lngTray, TB_GETBUTTON, ByVal i, ByVal lngAddress)
ret = ReadProcessMemory(hProcess, ByVal lngAddress + 16, ByVal VarPtr(lngTextAdr), ByVal 4, ByVal 0&)
If lngTextAdr <> -1 Then
ret = ReadProcessMemory(hProcess, ByVal lngTextAdr, ByVal VarPtr(strBuff(0)), ByVal 1024, ByVal 0&)
ret = ReadProcessMemory(hProcess, ByVal lngAddress + 12, ByVal VarPtr(lngHwndAdr), ByVal 4, ByVal 0&)
ret = ReadProcessMemory(hProcess, ByVal lngHwndAdr, ByVal VarPtr(lngHwnd), ByVal 4, ByVal 0&)
ret = ReadProcessMemory(hProcess, ByVal lngAddress + 4, ByVal VarPtr(lngButtonID), ByVal 4, ByVal 0&)
strText = ConverNull(strBuff)
GetSysTrayMsg = GetSysTrayMsg & strText & vbNewLine
End If
Next i
VirtualFreeEx hProcess, ByVal lngAddress, ByVal 4096&, MEM_RELEASE
CloseHandle hProcess
End Function
Function ConverNull(ByVal s As String) As String
Dim nullpos As Long
nullpos = InStr(s, Chr$(0))
If nullpos > 0 Then
ConverNull = Left(s, nullpos - 1)
Else
ConverNull = s
End If
End Function
二、在窗体内加入控件command1,然后复制下面代码:
Option Explicit
Private Sub Command1_Click()
Dim a() As String, i As Integer
a = Split(GetSysTrayMsg, vbNewLine)
For i = 0 To UBound(a) - 1
Print a(i)
Next
End Sub
三、运行,点击command1按钮即可显示任务栏所有程序的标题。
一、建立一个模拟,复制下面代码:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 OpenProcess Lib "KERNEL32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
Private Const READ_CONTROL As Long = &H20000
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const STANDARD_RIGHTS_READ As Long = (READ_CONTROL)
Private Const STANDARD_RIGHTS_EXECUTE As Long = (READ_CONTROL)
Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Private Const STANDARD_RIGHTS_WRITE As Long = (READ_CONTROL)
Private Const SYNCHRONIZE As Long = &H100000
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Const PROCESS_TERMINATE As Long = (&H1)
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Const WM_USER As Long = &H400
Private Const TB_BUTTONCOUNT As Long = (WM_USER + 24)
Private Const TB_HIDEBUTTON As Long = (WM_USER + 4)
Private Const TB_GETBUTTON As Long = (WM_USER + 23)
Private Const TB_GETBITMAP As Long = (WM_USER + 44)
Private Const TB_DELETEBUTTON As Long = (WM_USER + 22)
Private Const TB_ADDBUTTONS As Long = (WM_USER + 20)
Private Const TB_INSERTBUTTON As Long = (WM_USER + 21)
Private Const TB_ISBUTTONHIDDEN As Long = (WM_USER + 12)
Private Const ILD_NORMAL As Long = &H0
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function WriteProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long
Private Const PROCESS_VM_OPERATION As Long = (&H8)
Private Const PROCESS_VM_READ As Long = (&H10)
Private Const PROCESS_VM_WRITE As Long = (&H20)
Private Const MEM_RESERVE As Long = &H2000
Private Const MEM_COMMIT As Long = &H1000
Private Const MEM_RELEASE As Long = &H8000
Private Const PAGE_READWRITE As Long = &H4
'功能:获取任务栏内的窗口名称
Function GetSysTrayMsg() As String
Dim lngTemp As Long
Dim lngTray, Hwd As Long
Dim lngPID As Long
Dim lngPID2 As Long
Dim hProcess As Long
Dim lngProcess As Long
Dim lngAddress As Long
Dim lngCount As Long
Dim lngButtons As Long
Dim ret As Long
Dim lngTextAdr As Long
Dim lngHwndAdr As Long
Dim lngButtonID As Long
Dim hIcon As Long
Dim lngHwnd As Long
Dim lpFileName As String * 1024
Dim i As Long
Dim strBuff(1024) As Byte
Dim strText As String
Dim lngTrayDC As Long
lngTemp = FindWindow("Shell_TrayWnd", vbNullString)
lngTemp = FindWindowEx(lngTemp, 0, "ReBarWindow32", vbNullString)
lngTemp = FindWindowEx(lngTemp, 0, "MSTaskSwWClass", vbNullString)
lngTray = FindWindowEx(lngTemp, 0, "ToolbarWindow32", vbNullString)
ret = GetWindowThreadProcessId(lngTray, lngPID)
hProcess = OpenProcess(PROCESS_ALL_ACCESS Or PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, lngPID)
lngAddress = VirtualAllocEx(hProcess, ByVal 0&, ByVal 4096&, MEM_COMMIT, PAGE_READWRITE)
lngButtons = SendMessage(lngTray, TB_BUTTONCOUNT, 0, 0)
For i = 1 To lngButtons - 1 Step 2
ret = SendMessage(lngTray, TB_GETBUTTON, ByVal i, ByVal lngAddress)
ret = ReadProcessMemory(hProcess, ByVal lngAddress + 16, ByVal VarPtr(lngTextAdr), ByVal 4, ByVal 0&)
If lngTextAdr <> -1 Then
ret = ReadProcessMemory(hProcess, ByVal lngTextAdr, ByVal VarPtr(strBuff(0)), ByVal 1024, ByVal 0&)
ret = ReadProcessMemory(hProcess, ByVal lngAddress + 12, ByVal VarPtr(lngHwndAdr), ByVal 4, ByVal 0&)
ret = ReadProcessMemory(hProcess, ByVal lngHwndAdr, ByVal VarPtr(lngHwnd), ByVal 4, ByVal 0&)
ret = ReadProcessMemory(hProcess, ByVal lngAddress + 4, ByVal VarPtr(lngButtonID), ByVal 4, ByVal 0&)
strText = ConverNull(strBuff)
GetSysTrayMsg = GetSysTrayMsg & strText & vbNewLine
End If
Next i
VirtualFreeEx hProcess, ByVal lngAddress, ByVal 4096&, MEM_RELEASE
CloseHandle hProcess
End Function
Function ConverNull(ByVal s As String) As String
Dim nullpos As Long
nullpos = InStr(s, Chr$(0))
If nullpos > 0 Then
ConverNull = Left(s, nullpos - 1)
Else
ConverNull = s
End If
End Function
二、在窗体内加入控件command1,然后复制下面代码:
Option Explicit
Private Sub Command1_Click()
Dim a() As String, i As Integer
a = Split(GetSysTrayMsg, vbNewLine)
For i = 0 To UBound(a) - 1
Print a(i)
Next
End Sub
三、运行,点击command1按钮即可显示任务栏所有程序的标题。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询