Lm th? no ? s? d?ng cc khay h? th?ng tr?c ti?p t? Visual Basic

D?ch tiu ? D?ch tiu ?
ID c?a bi: 176085 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny


Bi vi?t ny ch?ng t? lm th? no ? t?n d?ng ?y ? c?a cc Khay h? th?ng Windows, ho?c Taskbar Notification Area, b?ng cch s? d?ng Visual Basic. N ?t m?t bi?u t?ng c?a s? l?a ch?n c?a b?n vo vng thng bo trn thanh tc v? s? hi?n th? m?t ToolTip c?a s? l?a ch?n c?a b?n khi con chu?t ?c ngh? trn n, s? khi ph?c l?i cc ?ng d?ng khi nh?n vo, v s? hi?n th? m?t popup menu khi nh?p. i?u ny l t?t c? c th? do Visual Basic kh? nng x? l? tr?c ti?p callbacks, do l?i d?ng ?y ? cc ch?c nng Shell_NotifyIcon xu?t kh?u b?i Shell32.dll.


V d? sau c th? ?c thm vo b?t k? Visual Basic D? n c t nh?t m?t m?u v m?t m-un chu?n.

V d?-by-step

  1. Thm m? sau vo ph?n khai bo c?a m?t tiu chu?n phn h? trong d? n c?a b?n:
          '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
          'constants required by Shell_NotifyIcon API call:
          Public Const NIM_ADD = &H0
          Public Const NIM_MODIFY = &H1
          Public Const NIM_DELETE = &H2
          Public Const NIF_MESSAGE = &H1
          Public Const NIF_ICON = &H2
          Public Const NIF_TIP = &H4
          Public Const WM_MOUSEMOVE = &H200
          Public Const WM_LBUTTONDOWN = &H201     'Button down
          Public Const WM_LBUTTONUP = &H202       'Button up
          Public Const WM_LBUTTONDBLCLK = &H203   'Double-click
          Public Const WM_RBUTTONDOWN = &H204     'Button down
          Public Const WM_RBUTTONUP = &H205       'Button up
          Public Const WM_RBUTTONDBLCLK = &H206   'Double-click
          Public Declare Function SetForegroundWindow Lib "user32" _
          (ByVal hwnd As Long) As Long
          Public Declare Function Shell_NotifyIcon Lib "shell32" _
          Alias "Shell_NotifyIconA" _
          (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
          Public nid As NOTIFYICONDATA
  2. Thm d?i y m? ? b?t k? h?nh th?c trong d? n c?a b?n m b?n mu?n ? p ?ng v?i cc bi?u t?ng khay h? th?ng, ho?c thng bo bi?u t?ng, cho b?n ?ng d?ng:
          Private Sub Form_Load()
           'the form must be fully visible before calling Shell_NotifyIcon
           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
          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
            msg = X / Screen.TwipsPerPixelX
           End If
           Select Case msg
            Case WM_LBUTTONUP        '514 restore form window
             Me.WindowState = vbNormal
             Result = SetForegroundWindow(Me.hwnd)
            Case WM_LBUTTONDBLCLK    '515 restore form window
             Me.WindowState = vbNormal
             Result = SetForegroundWindow(Me.hwnd)
            Case WM_RBUTTONUP        '517 display popup menu
             Result = SetForegroundWindow(Me.hwnd)
             Me.PopupMenu Me.mPopupSys
           End Select
          End Sub
          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 Form_Unload(Cancel As Integer)
           'this removes the icon from the system tray
           Shell_NotifyIcon NIM_DELETE, nid
          End Sub
          Private Sub mPopExit_Click()
           'called when user clicks the popup menu Exit command
           Unload Me
          End Sub
          Private Sub mPopRestore_Click()
           'called when the user clicks the popup menu Restore command
           Dim Result As Long
           Me.WindowState = vbNormal
           Result = SetForegroundWindow(Me.hwnd)
          End Sub
  3. Th?c hi?n cc thi?t ?t ti s?n sau ngy gi?ng nh h?nh th?c ? m b?n thm vo m? ? trn:
       Property         Required Setting for Taskbar Notification Area example
       Icon           = The icon you want to appear in the system tray.
       Minbutton      = True
       ShownInTaskbar = False
  4. Thm cc kho?n m?c Menu sau vo cng m?t h?nh th?c s? d?ng cc Menu Editor:
       Caption      Name          Enabled   Visible   Position
       &SysTray     mPopupSys      True      False    Main Level
       &Restore     mPopRestore    True      True     Inset one
       &Exit        mPopExit       True      True     Inset one
B?n c th? thm m?c tr?nh n thm khi c?n thi?t.

Taskbar Notification Area linh ho?t

B?n c th? s?a ?i ToolTip s? xu?t hi?n trong thng bo bi?u t?ng b?ng cch thay ?i d?ng sau trong th? t?c Form_Load:
   .szTip = "Your ToolTip" & vbNullChar
Thay th? "Your tooltip" v?i vn b?n m b?n mu?n xu?t hi?n.

B?n c th? s?a ?i bi?u t?ng s? xu?t hi?n trong Taskbar Notification Area b?i thay ?i d?ng sau trong th? t?c Form_Load:
   .hIcon = Me.Icon
Thay th? Me.Icon v?i b?t k? bi?u t?ng trong d? n c?a b?n.

B?n c th? thay ?i b?t k? c?a cc ci ?t Taskbar Notification Area t?i b?t k? th?i i?m no sau khi vi?c s? d?ng cc H?ng s? NIM_ADD b?i b? cc gi tr? trong bi?n nid v sau b?ng cch s? d?ng cc bi?n th? sau y c?a cc cu?c g?i Shell_NotifyIcon API:
   Shell_NotifyIcon NIM_MODIFY, nid.
Tuy nhin, n?u b?n mu?n c m?t h?nh th?c khc nhau ? nh?n ?c g?i l?i, sau b?n s? c?n ph?i xo bi?u t?ng hi?n t?i tr?c b?ng cch s? d?ng "Shell_NotifyIcon NIM_Delete, Nid"nh ch?c nng NIM_Modify s? khng ch?p nh?n m?t Hwnd m?i, ho?c b?n s? c?n ph?i thm m?t bi?u t?ng ? systray cho h?nh th?c m?i b?ng cch s? d?ng "Shell_NotifyIcon NIM_ADD, nid"sau khi refilling nid lo?i v?i cc m?i t?o thnh Hwnd. B?n c th? c?ng tuyn b? b?n sao ring bi?t c?a lo?i nid cho m?i m?u m b?n mu?n hi?n th? m?t bi?u t?ng cho trong khay h? th?ng Windows v thay ?i chng trong m?i m?u Kch ho?t cc s? ki?n b?ng cch s? d?ng tr?nh t? NIM_DELETE v NIM_ADD.


? bi?t thm chi ti?t v? vi?c s? d?ng cc khay h? th?ng ho?c b?ng cch s? d?ng vng thng bo trn thanh tc v? t? Visual Basic 4.0 ho?c tr?c , nh?p vo s? bi vi?t sau ? xem bi vi?t trong c s? ki?n th?c Microsoft:
149276Lm th? no ? s? d?ng bi?u t?ng v?i Windows 95/98/Me Taskbar vng thng bo

Thu?c tnh

ID c?a bi: 176085 - L?n xem xt sau cng: 19 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Control Creation Edition
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
T? kha:
kbbug kbhowto kbmt KB176085 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:176085

Cung cp Phan hi


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com