我自己调查了一下只能找到时间的相关内容,找不到日期和星期的。 以下是取时间的代码: 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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPublic Function GetHwnd() As Long Dim TrayWnd As Long Dim NotifyWnd As Long Dim ClockWnd As Long TrayWnd = FindWindow("Shell_TrayWnd", vbNullString) NotifyWnd = FindWindowEx(tyaywnd, "TrayNotifyWnd", "", "") ClockWnd = FindWindowEx(NotifyWnd, "TrayClockWClass", "", "") GetHwnd = ClockWnd End Function Public Function GetWinText() As String Dim strT As String * 256 If GetHwnd Then GetWindowText GetHwnd, strT, 255 GetWinText=strT Else GetWinText = vbNullString End If End Function Private Sub Command1_Click() MsgBox GetWinText End Sub 以上不能取到系统托盘中显示出来的信息。不知道是什么状况。哪位知道的能帮忙说明一下么?
你的代码能执行才怪,楼主真固执……废话不说了,你那个函数我给你修正贴出来,这样可以读取到系统托盘的时间了: Public Function GetHwnd() As Long Dim TrayWnd As Long Dim NotifyWnd As Long 'Dim ClockWnd As Long TrayWnd = FindWindow("Shell_TrayWnd", vbNullString) NotifyWnd = FindWindowEx(TrayWnd, 0, "TrayNotifyWnd", "") 'ClockWnd = FindWindowEx(NotifyWnd, 0, "TrayClockWClass", "") 'GetHwnd = ClockWnd GetHwnd = FindWindowEx(NotifyWnd, 0, "TrayClockWClass", vbNullString) End Function
'添加托盘图标 Public Sub AddTrayIocn(Frm As Form, mnu As Menu, Optional tip As String = "", Optional strTitle As String = "", Optional strInfo As String = "") Set TheForm = Frm Set TheMenu = mnu
OldWindowProc = SetWindowLong(Frm.hwnd, GWL_WNDPROC, AddressOf NewWindowProc) With TheData .uId = 0 .hwnd = Frm.hwnd .cbSize = Len(TheData) .hIcon = Frm.Icon.Handle .uCallBackMessage = TRAY_CALLBACK .cbSize = Len(TheData) .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE .szTip = tip & vbNullChar End With Shell_NotifyIcon NIM_ADD, TheData End Sub SetWindowLong相当于给本程序添加了一个监听入口,Shell_NotifyIcon NIM_ADD, TheData中给定了响应消息为TRAY_CALLBACK,也就是说系统监听到有TRAY_CALLBACK消息的时候要交给本程序处理,那么时间区域的响应消息是什么呢? 是不是只要我拦截到这个消息,就能在时间区域做单击,右击处理呢? 等回复
以下是取时间的代码:
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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPublic Function GetHwnd() As Long
Dim TrayWnd As Long
Dim NotifyWnd As Long
Dim ClockWnd As Long
TrayWnd = FindWindow("Shell_TrayWnd", vbNullString)
NotifyWnd = FindWindowEx(tyaywnd, "TrayNotifyWnd", "", "")
ClockWnd = FindWindowEx(NotifyWnd, "TrayClockWClass", "", "")
GetHwnd = ClockWnd
End Function
Public Function GetWinText() As String
Dim strT As String * 256
If GetHwnd Then
GetWindowText GetHwnd, strT, 255
GetWinText=strT
Else
GetWinText = vbNullString
End If
End Function
Private Sub Command1_Click()
MsgBox GetWinText
End Sub
以上不能取到系统托盘中显示出来的信息。不知道是什么状况。哪位知道的能帮忙说明一下么?
Option Explicit
吧,这样调试很麻烦的。
而且你FindWindowEx的第2个参数类型明显都没对上。建议你还是先分别找这些API的示例来学习下,再弄这种API组合使用的东西。
Public Function GetHwnd() As Long
Dim TrayWnd As Long
Dim NotifyWnd As Long
'Dim ClockWnd As Long
TrayWnd = FindWindow("Shell_TrayWnd", vbNullString)
NotifyWnd = FindWindowEx(TrayWnd, 0, "TrayNotifyWnd", "")
'ClockWnd = FindWindowEx(NotifyWnd, 0, "TrayClockWClass", "")
'GetHwnd = ClockWnd
GetHwnd = FindWindowEx(NotifyWnd, 0, "TrayClockWClass", vbNullString)
End Function
要是GetHwnd()是一个比较复杂的操作过程,你的代码岂不是严重影响运行速度?这种情况应该是定义一个Long类型的局部变量,用它保存GetHwnd()的值。
然后用这个局部变量来进行判断及参数传递。
你想要改它的显示样式为‘你想要的那种’,不是什么设置啊、API啊之类的就能搞定的。
这是操作系统它固定了那几种显示格式。
要达到你的要求,恐怕只有你自己不停地‘画’。
(我认为稍微方便点的就是自己弄个窗体去覆盖掉它,在自己的窗口中输出想要显示的内容,很容易。)
"sLongDate"="yyyy'年'M'月'd'日' dddd"
"sShortDate"="yyyy-MM-dd"
"sTimeFormat"="HH:mm:ss"
'添加托盘图标
Public Sub AddTrayIocn(Frm As Form, mnu As Menu, Optional tip As String = "", Optional strTitle As String = "", Optional strInfo As String = "")
Set TheForm = Frm
Set TheMenu = mnu
OldWindowProc = SetWindowLong(Frm.hwnd, GWL_WNDPROC, AddressOf NewWindowProc) With TheData
.uId = 0
.hwnd = Frm.hwnd
.cbSize = Len(TheData)
.hIcon = Frm.Icon.Handle
.uCallBackMessage = TRAY_CALLBACK
.cbSize = Len(TheData)
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.szTip = tip & vbNullChar
End With Shell_NotifyIcon NIM_ADD, TheData
End Sub
SetWindowLong相当于给本程序添加了一个监听入口,Shell_NotifyIcon NIM_ADD, TheData中给定了响应消息为TRAY_CALLBACK,也就是说系统监听到有TRAY_CALLBACK消息的时候要交给本程序处理,那么时间区域的响应消息是什么呢?
是不是只要我拦截到这个消息,就能在时间区域做单击,右击处理呢?
等回复
第二种方法是DLL注入,然后自己重新画TrayClock。