.net中有现成的部件
vb6好象就只能用api了。

解决方案 »

  1.   

    to csdnlee()
    我就是用的vb6,我正是想知道调api的详细定义和用法~~~~~~请tell me
    先谢过了~~~~
    你说的哪个网址好象根本没有写全~~~~:)
      

  2.   

    http://support.microsoft.com/support/kb/articles/Q176/0/85.aspHOWTO: Use the System Tray Directly from Visual Basic --------------------------------------------------------------------------------
    The information in this article applies to:Microsoft Visual Basic Learning Edition for Windows, version 6.0 
    Microsoft Visual Basic Professional Edition for Windows, version 6.0 
    Microsoft Visual Basic Enterprise Edition for Windows, version 6.0 
    Microsoft Visual Basic Control Creation Edition for Windows, version 5.0 
    Microsoft Visual Basic Learning Edition for Windows, version 5.0 
    Microsoft Visual Basic Professional Edition for Windows, version 5.0 
    Microsoft Visual Basic Enterprise Edition for Windows, version 5.0--------------------------------------------------------------------------------
    SUMMARY
    This article demonstrates how to take full advantage of the Windows System Tray, or Taskbar Notification Area, using Visual Basic. It places an icon of your choice into the Taskbar Notification Area that will display a ToolTip of your choice when the mouse is rested over it, will restore the application when clicked, and will display a popup menu when right-clicked. This is all possible because of Visual Basic's ability to directly handle callbacks, therefore taking full advantage of the Shell_NotifyIcon function that is exported by Shell32.dll. MORE INFORMATION
    The following example can be added to any Visual Basic Project that has at least one form and a standard module. Step-by-Step Example
    Add the following code to the declarations section of a standard module in your project:
          '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 
    Add the following code to any form in your project that you want to respond to the System Tray Icon, or Notification Icon, for your application:
          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      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      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)
           Me.Show
          End Sub 
    Make the following Property Settings on the same form to which you added the above code:
       Property         Required Setting for Taskbar Notification Area example
       -----------------------------------------------------------------------
       Icon           = The icon you want to appear in the system tray.
       Minbutton      = True
       ShownInTaskbar = False 
    Add the following Menu items to the same form using the 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 
    You can add additional menu items as needed. 
    Taskbar Notification Area Flexibility
    You can modify the ToolTip that appears over the Notification icon by changing the following line in the Form_Load procedure: 
       .szTip = "Your ToolTip" & vbNullChar 
    Replace "Your ToolTip" with the text that you want to appear.You can modify the Icon that appears in the Taskbar Notification Area by changing the following line in the Form_Load procedure: 
       .hIcon = Me.Icon 
    Replace Me.Icon with any Icon in your project.You can change any of the Taskbar Notification Area settings at any time after the use of the NIM_ADD constant by reassigning the values in the nid variable and then using the following variation of the Shell_NotifyIcon API call: 
       Shell_NotifyIcon NIM_MODIFY, nid. 
    However, if you want a different form to receive the callback, then you will need to delete the current icon first using "Shell_NotifyIcon NIM_Delete, nid" as the NIM_Modify function will not accept a new Hwnd, or you will need to add another Icon to the systray for the new form using "Shell_NotifyIcon NIM_ADD, nid" after refilling the nid type with the new forms Hwnd. You can also declare separate copies of the nid type for each form that you want to display an icon for in the Windows System Tray and change them in each form's activate event using the NIM_DELETE and NIM_ADD sequence. REFERENCES
    For information regarding using the System Tray, or Taskbar Notification Area, from Visual Basic 4.0 or earlier, please see the following article in the Microsoft Knowledge Base: Q149276 HOWTO: Use Icons with the Windows 95 System Tray Additional query words: Taskbar Keywords : kbVBp kbVBp500 kbVBp600bug kbGrpDSVBDB kbDSupport 
    Issue type : kbhowto 
    Technology : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB500Search kbVB600Search kbVBA500Search kbVBA500 kbVBA600 kbVB500 kbVB600 kbZNotKeyword3 
     
    Last Reviewed: January 11, 2001
    © 2001 Microsoft Corporation. All rights reserved. Terms of Use.  Disability/accessibility  Privacy Policy
     
      

  3.   

    Attribute VB_Name = "Tray"
    Option Explicit
    'Win32 API declaration
    Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean' Constants used to detect clicking on the icon
    Public Const WM_LBUTTONDBLCLK = &H203
    Public Const WM_RBUTTONUP = &H205
    Public Const WM_LBUTTONDOWN = &H201
    Public Const WM_LBUTTONUP = &H202' Constants used to control the icon
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIF_MESSAGE = &H1
    Public Const NIM_DELETE = &H2
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4' Used as the ID of the call back message
    Public Const WM_MOUSEMOVE = &H200' Used by Shell_NotifyIcon
    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'create variable of type NOTIFYICONDATA
    Public TrayIcon As NOTIFYICONDATAVERSION 5.00
    Begin VB.Form frmTrayIcon 
       Caption         =   "Mind's Tray Icon Example"
       ClientHeight    =   1485
       ClientLeft      =   2625
       ClientTop       =   2175
       ClientWidth     =   3480
       Icon            =   "TrayIcon.frx":0000
       LinkTopic       =   "Form1"
       LockControls    =   -1  'True
       PaletteMode     =   1  'UseZOrder
       ScaleHeight     =   1485
       ScaleWidth      =   3480
       Begin VB.CommandButton cmdExit 
          Caption         =   "E&xit"
          Height          =   375
          Left            =   1200
          TabIndex        =   0
          Top             =   840
          Width           =   1215
       End
       Begin VB.Image imgIcon2 
          Height          =   480
          Left            =   1920
          Picture         =   "TrayIcon.frx":030A
          Top             =   240
          Width           =   480
       End
       Begin VB.Image imgIcon1 
          Height          =   480
          Left            =   1200
          Picture         =   "TrayIcon.frx":074C
          Top             =   240
          Width           =   480
       End
       Begin VB.Menu mnuPopUp 
          Caption         =   "PopUp_Menu"
          Visible         =   0   'False
          Begin VB.Menu mnuChange 
             Caption         =   "Change &Icon"
          End
          Begin VB.Menu line2 
             Caption         =   "-"
          End
          Begin VB.Menu mnuExit 
             Caption         =   "E&xit"
          End
          Begin VB.Menu line 
             Caption         =   "-"
          End
          Begin VB.Menu mnuAbout 
             Caption         =   "&About"
          End
       End
    End
    Attribute VB_Name = "frmTrayIcon"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option ExplicitPrivate Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongConst SW_RESTORE = 9Const SW_SHOWNORMAL = 1Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_SYSCOMMAND = &H112
    Private Const SC_MOVE = &HF010&
    Private Const SC_RESTORE = &HF120&
    Private Const SC_SIZE = &HF000&
    Private Sub cmdExit_Click()    Unload Me
        
    End Sub
    Private Sub Form_Load()    
        'centers form
        Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2    'sets cbSize to the Length of TrayIcon
        TrayIcon.cbSize = Len(TrayIcon)
        ' Handle of the window used to handle messages - which is the this form
        TrayIcon.hwnd = Me.hwnd
        ' ID code of the icon
        TrayIcon.uId = vbNull
        ' Flags
        TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        ' ID of the call back message
        TrayIcon.ucallbackMessage = WM_MOUSEMOVE
        ' The icon - sets the icon that should be used
        TrayIcon.hIcon = imgIcon1.Picture
        ' The Tooltip for the icon - sets the Tooltip that will be displayed
        TrayIcon.szTip = "Mind's Tray Icon Example" & Chr$(0)
        
        ' Add icon to the tray by calling the Shell_NotifyIcon API
        'NIM_ADD is a Constant - add icon to tray
        Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
        
        ' Don't let application appear in the Windows task list
        App.TaskVisible = False
        Me.Hide
    End Sub
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Static Message As Long
    Static RR As Boolean
        
        'x is the current mouse location along the x-axis
        Message = X / Screen.TwipsPerPixelX
        
        If RR = False Then
            RR = True
            Select Case Message
                Case WM_LBUTTONUP
                'Me.Visible = True
                   
                    SendMessage Me.hwnd, WM_SYSCOMMAND, SC_RESTORE, 0&
                    ShowWindow Me.hwnd, SW_SHOWNORMAL
                    SetForegroundWindow Me.hwnd
                    
    '            ' Left double click (This should bring up a dialog box)
    '            Case WM_LBUTTONDBLCLK
    '                'Me.Visible = True
    '
    '                Me.Show
    '
    '                SetForegroundWindow Me.hwnd
    '                Me.SetFocus
    '            ' Right button up (This should bring up a menu)
                Case WM_RBUTTONUP
                    Me.PopupMenu mnuPopUp
            End Select
            RR = False
        End If
        
    End Sub
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)    TrayIcon.cbSize = Len(TrayIcon)
        TrayIcon.hwnd = Me.hwnd
        TrayIcon.uId = vbNull
        'Remove icon for Tray
        Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
        
    End Sub
    Private Sub Form_Resize()    If Me.WindowState = vbMinimized Then
         Me.Hide
        End If
        
    End SubPrivate Sub mnuAbout_Click()    frmAbout.ShowEnd SubPrivate Sub mnuChange_Click()    'checks to find what icon is currently displayed
        If TrayIcon.hIcon = imgIcon1.Picture Then
            'changes the icon to display
            TrayIcon.hIcon = imgIcon2.Picture
            'removes current icon from tray
            Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
             'calls the API to add in new icon
            Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
        Else
            'changes the icon to display
            TrayIcon.hIcon = imgIcon1.Picture
            'removes current icon from tray
             Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
            'calls the API to add in new icon
            Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
        End If
            
    End Sub
    Private Sub mnuExit_Click()    Unload MeEnd Sub