ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 0 2

7 ѹҤ ..2549
56 Users On-Line.
Visitors - Page views
 8 9 7 3 8 4 5
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ʴͤ͹ System Tray

Category »  VB 6/VB.Net
: Webmaster 5/11/2549 13:11:00
(ҹ : 40370) 
㹺йʹ͵ҧ㹡ʴͤ͹ System Tray ǹʴʶҹТͧʡ çԡҹФѺ ·Ҩ API ʴͤ͹ System Tray ¡¡ҹ Shell_NotifyIcon
ѧ Shell_NotifyIcon ѡɳдѧ仹
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" & _
(ByVal dwMessage As Long, & _
pnid As NOTIFYICONDATA) As Boolean

·
´ MSDN Library:
» HOWTO: Use the System Tray Directly from Visual Basic 5.0
Article ID: Q176085
» HOWTO: Use Icons with the Windows 95 System Tray
Article ID: Q149276

ǹŴ Source Code (VB6) ...

dwMessage ʨкҵͧ÷ӧҹ դҴѧ仹
' Constants required by Shell_NotifyIcon API call:
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
' -----------------------------------------
' ͸Ժ:
NIM_ADD ͤ͹ System Tray
NIM_MODIFY ͤ͹
NIM_DELETE źͤ͹͡ҡ System Tray

pnid Pointer ѧçҧ NOTIFYICONDATA 觨лСͺҪԡ仹
' User defined type required by Shell_NotifyIcon API call
Public Type NOTIFYICONDATA
    cbSize As Long
    hwnd As Long
    uId As Long
    uFlags As Long
    uCallBackMessage As Long
    hIcon As Long
    szTip As String * 64
End Type

ҪԡеǨդ´ѧ仹

cbSize
Ҵͧçҧ NOTIFYICONDATA öѧ Len ҢҴͧçҧ

hWnd
ιŢͧ Windows Ѻʨ öسѵ hWnd ͧ͹ Ѻǹ

uId
кͤ͹ʴ System Tray ö˹繤 Ҩ˹ vbNull

uFlags
ͧš (Flag) кҪԡҧçҧ ʴ֧ ¡ùӤҢͧšҺǡѹ OR šդ´ѧ仹
' á˹ǹͧ uFlags
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4

NIF_ICON кҤ hIcon ͤ͹ʴ System Tray
NIF_MESSAGE кҤ uCallBackMessage ж١Ѻ Callback message
NIF_TIP кҤ szTip ѺʴŷԻ (ToolTip) ͧͤ͹

uCallBackMessage
ʨж١觡Ѻ к˵ءó (Event) Դ鹷 System Tray Ҩ WM_MOUSEMOVE դҡѺǹ MouseMove Visual Basic ͧ Sub Class ʹѡѺʨ ѹзդѺ͹ҡ

hIcon
ιŢͧͤ͹ʴ System Tray Ҩ繤سѵ Icon ͧ͹ image ͧ͹ image Ҿͤ͹

szTip
ͤ繷ŷԻ Ǥ 64 亵 ͤͧŧ´ѡ Null ( vbNullChar)


÷ӧҹ


ѹѺáҵͧ˹ŵҧѺѧ Shell_NotifyIcon ó (´ҹ) ¡˹ Module ¡ҧҡҡФѺ ͨҡҨ֧ͤ͹ System Tray ѧ

Private Sub Form_Load()
    'the form must be fully visible before calling Shell_NotifyIcon
    Me.Show
    Me.Refresh
    With nid
        .cbSize = Len(nid)
        .hwnd = Me.hwnd
        .uId = vbNull
        .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        .uCallBackMessage = WM_MOUSEMOVE
        .hIcon = Me.Icon
        .szTip = "Your ToolTip" & vbNullChar
    End With
    '
    Shell_NotifyIcon NIM_ADD, nid
End Sub

¡ҹѧ蹹 ͤ͹ͧлҡ躹 System Tray ѧҡ͹˹ͤ͹ System Tray Ѻʨ WM_MOUSEMOVE 觡͡Դ˵ءó MouseMove ͧͧ

Argument X ͧë Form_MouseMove ˹ҷкض֧Թص ѹ äꡫ, ꡢ áѺŤ Фسѵ TwipsPerPixelX ͧҾ öѺԹص¡ä Argument ¤سѵԹ (Screen.TwipsPerPixelX) ǹӤҷһżŵͧ

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'this procedure receives the callbacks from the System Tray icon.
Dim Result As Long
Dim msg As Long
    ' The value of X will vary depending upon the scalemode setting
    If Me.ScaleMode = vbPixels Then
        msg = X
    Else
        msg = X / Screen.TwipsPerPixelX
    End If
    Select Case msg
        Case WM_LBUTTONUP ' 514 restore form window
            Me.WindowState = vbNormal
            Result = SetForegroundWindow(Me.hwnd)
            Me.Show
        Case WM_LBUTTONDBLCLK ' 515 restore form window
            Me.WindowState = vbNormal
            Result = SetForegroundWindow(Me.hwnd)
            Me.Show
        Case WM_RBUTTONUP ' 517 display popup menu
            Result = SetForegroundWindow(Me.hwnd)
            Me.PopupMenu Me.mPopupSys
    End Select
    '
End Sub

źͤ͹͡ҡ System Tray ˹ dwMessage NIM_DELETE Ǩ֧¡ѧ Shell_NotifyIcon ա駴ѧ

Private Sub Form_Unload(Cancel As Integer)
    ' This removes the icon from the system tray
    Shell_NotifyIcon NIM_DELETE, nid
End Sub

Code ͧ͢
Private Sub Form_Resize()
    ' This is necessary to assure that the minimized window is hidden
    If Me.WindowState = vbMinimized Then Me.Hide
End Sub

Private Sub mPopExit_Click()' ͧҧ Menu Editor mPopupExit
    ' Called when user clicks the popup menu Exit command
    Unload Me
End Sub

Private Sub mPopRestore_Click()' ͧҧ Menu Editor mPopupRestore
Dim Result As Long
    ' Called when the user clicks the popup menu Restore command
    Me.WindowState = vbNormal
    Result = SetForegroundWindow(Me.hwnd)
    Me.Show
End Sub

ҧ ͷسöꡢ㹡͡˵ءó MouseMove


䧺ҧФѺ ҡ´ҹ ʴ繶֧ źͤ͹ System Tray 鹤͹ҧЧ´ (Թ) ŷѹҾѲҢҴٴժҵԵСŢա¤Ѻ ҡҤ 200 ҨѺ价 299 ҷҴǡ

Ѻ´ سͧ֡ҷ MSDN Library
HOWTO: Use the System Tray Directly from Visual Basic 5.0
Article ID: Q176085

HOWTO: Use Icons with the Windows 95 System Tray
Article ID: Q149276

͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560