请问VB调用API函数可以修改系统托盘里时间显示格式么?
详情:系统托盘里可以显示长时间格式,但是要把任务栏拉高才能全部显示。有什么办法可以把时间信息重新组合,能不用拉高任务栏就可以显示全部时间信息。像图中显示的
而不是系统显示的

解决方案 »

  1.   

    我自己调查了一下只能找到时间的相关内容,找不到日期和星期的。
    以下是取时间的代码:
    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
    以上不能取到系统托盘中显示出来的信息。不知道是什么状况。哪位知道的能帮忙说明一下么?
      

  2.   

    楼主你那个tyaywnd变量名写错了,当然找不到了,你的模块顶部大概没加
    Option Explicit
    吧,这样调试很麻烦的。
    而且你FindWindowEx的第2个参数类型明显都没对上。建议你还是先分别找这些API的示例来学习下,再弄这种API组合使用的东西。
      

  3.   

    这是我能执行的代码。TrayClockWClass的句柄都取到了怎么还会参数类型都不对上,对不上都报错了呀。
      

  4.   

    FindWindowEx第二个参数明先生long型,string型竟然还能运行,挺牛啊
      

  5.   

    你的代码能执行才怪,楼主真固执……废话不说了,你那个函数我给你修正贴出来,这样可以读取到系统托盘的时间了:
    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
      

  6.   

    你的 GetWinText() 中两次调用 GetHwnd() ,何必呢……
    要是GetHwnd()是一个比较复杂的操作过程,你的代码岂不是严重影响运行速度?这种情况应该是定义一个Long类型的局部变量,用它保存GetHwnd()的值。
    然后用这个局部变量来进行判断及参数传递。
      

  7.   

    另外就说楼主的提问了。
    你想要改它的显示样式为‘你想要的那种’,不是什么设置啊、API啊之类的就能搞定的。
    这是操作系统它固定了那几种显示格式。
    要达到你的要求,恐怕只有你自己不停地‘画’。
    (我认为稍微方便点的就是自己弄个窗体去覆盖掉它,在自己的窗口中输出想要显示的内容,很容易。)
      

  8.   

    [HKEY_CURRENT_USER\Control Panel\International]
    "sLongDate"="yyyy'年'M'月'd'日' dddd"
    "sShortDate"="yyyy-MM-dd"
    "sTimeFormat"="HH:mm:ss"
      

  9.   


    '添加托盘图标
    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消息的时候要交给本程序处理,那么时间区域的响应消息是什么呢?
    是不是只要我拦截到这个消息,就能在时间区域做单击,右击处理呢?
    等回复
      

  10.   

    有两种方法,第一是自己弄个无标题窗口,把TrayClock替换掉。
    第二种方法是DLL注入,然后自己重新画TrayClock。