Avatar billede jolldasch Nybegynder
26. december 2000 - 23:32 Der er 4 kommentarer og
1 løsning

Minimere til ikon

Hvordan gør man, når det minimerede program skal vises ved siden af uret i proceslinjen  i stedet for på bjælken?
Avatar billede stigc Nybegynder
26. december 2000 - 23:35 #1
Avatar billede stigc Nybegynder
26. december 2000 - 23:35 #2
Avatar billede madd Nybegynder
26. december 2000 - 23:36 #3
Jeg har et modul der gør det...stik mig din e-mail så sender jeg den...

/MadD
Avatar billede jolldasch Nybegynder
26. december 2000 - 23:41 #4
kfr@mobilixnet.dk
Avatar billede madd Nybegynder
26. december 2000 - 23:48 #5
Jeg kan bare smide den her:
----------------------------------------
Option Explicit
\'This will make a form that can hide on the systray.
\'Also it includes code for a right click menu and all other \'click events are availible.


\'Add to a module called systray
\'This is for the API portion of the procedure.

\'Create a form with a menu named zmnufile


\'Under that menu create your items for the menu with the
\'array names mfile, as many as you want and there caption can
\'can be what ever you want.
\'The form must have an icon setup in it\'s properties.

\'Also create a command button to execute the hide. When you do \'the hide you just need to enter Me.Visible = False



\'Required Public constants, types & declares
\'for the Shell_Notify API method
Public Const NIM_ADD As Long = &H0
Public Const NIM_MODIFY As Long = &H1
Public Const NIM_DELETE As Long = &H2
Public Const NIF_ICON As Long = &H2    \'adding an ICON
Public Const NIF_TIP As Long = &H4      \'adding a TIP
Public Const NIF_MESSAGE As Long = &H1  \'want return messages
\'rodent constant we\'ll need for the callback
Public Const WM_LBUTTONDOWN As Long = &H201
Public Const WM_LBUTTONUP As Long = &H202
Public Const WM_LBUTTONDBLCLK As Long = &H203
Public Const WM_MBUTTONDOWN As Long = &H207
Public Const WM_MBUTTONUP As Long = &H208
Public Const WM_MBUTTONDBLCLK As Long = &H209
Public Const WM_RBUTTONDOWN As Long = &H204
Public Const WM_RBUTTONUP As Long = &H205
Public Const WM_RBUTTONDBLCLK As Long = &H206 \'the actual workhorse
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
Public NID As NOTIFYICONDATA

Declare Function Shell_NotifyIcon Lib \"shell32.dll\" _
    Alias \"Shell_NotifyIconA\" (ByVal dwMessage As Long, _
    lpData As NOTIFYICONDATA) As Long
_______________________________________________________________

Option Explicit
\'Add to a module called winproc
\'This is the class portion if the funtion.



\'defWindowProc: Variable to hold the ID of the
\'  default window message processing
\'  procedure. Returned by SetWindowLong.
Public defWindowProc As Long
\'isSubclassed: flag indicating that subclassing
\'  has been done. Provides the means
\'  to call the correct message-handler.
Public isSubclassed As Boolean

\'Get/SetWindowLong messages
Public Const GWL_WNDPROC As Long = (-4)
Public Const GWL_HWNDPARENT As Long = (-8)
Public Const GWL_ID As Long = (-12)
Public Const GWL_STYLE As Long = (-16)
Public Const GWL_EXSTYLE As Long = (-20)
Public Const GWL_USERDATA As Long = (-21) \'general windows messages
Public Const WM_USER As Long = &H400
Public Const WM_MYHOOK As Long = WM_USER + 1
Public Const WM_NOTIFY As Long = &H4E
Public Const WM_COMMAND As Long = &H111
Public Declare Function SetForegroundWindow Lib \"user32\" _
  (ByVal hwnd As Long) As Long
Public Declare Function PostMessageLong Lib \"user32\" Alias \"PostMessageA\" _
  (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib \"user32\" Alias \"SetWindowLongA\" _
  (ByVal hwnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Any) As Long
Public Declare Function CallWindowProc Lib \"user32\" Alias \"CallWindowProcA\" _
  (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _
    ByVal uMsg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long

Public Function WindowProc(ByVal hwnd As Long, _
        ByVal uMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
  \'If the handle returned is to our form,
  \'call a form-specific message handler to
  \'deal with the tray notifications.  If it
  \'is a general system message, pass it on to  \'the default window procedure.
  On Error Resume Next
  Select Case hwnd
 
    Case FrmReqQueue.hwnd
        \'our form-specific handler
        FrmReqQueue.ProcMsg hwnd, uMsg, wParam, lParam
    End Select
  \'if subclassing has been activated, pass
  \'messages to the default message handler  \'
  \'If it hasn\'t, then the default handler
  \'will take care of them by default (duh!).
    If isSubclassed = True Then
        WindowProc = CallWindowProc(defWindowProc, hwnd, uMsg, wParam, ByVal lParam)
    Else
        isSubclassed = False
        isSubclassed = True
    End If
   
End Function

_______________________________________________________________
\'Add below to a form you want to hide. This code
\'

Private Sub Form_Unload(Cancel As Integer)
On Error GoTo endit
Dim X
   
        \'Delete the added icon from the taskbar status area \'when the program ends.
        \'Remove the icon added to the taskbar

        ShellTrayRemove

        \'remove subclassing

        UnSubClass

        Cancel = 0


        Screen.MousePointer = vbDefault

        End

        GoTo endit
   
endit:
    Exit Sub
End Sub


Private Sub Form_Load()

\'centre this form
  Me.Move (Screen.Width - Me.Width) \\ 2, (Screen.Height - Me.Height) \\ 2
 
  \'add an icon to the system tray
  ShellTrayAdd

  \'prepare to receive the systray events
  SubClass Me.hwnd

End Sub

Private Sub mFile_Click(Index As Integer)
  \'code demonstrating typical reaction to
  \'the menu clicks.
 
 
   
  Select Case Index
       
        Case 1 \' Open HelpDesk
            NID.hIcon = Me.Icon
            Call Shell_NotifyIcon(NIM_MODIFY, NID)
            FrmReqQueue.Visible = True
            Refresh_Click
               
                   
        Case 2 \' Open and Add Ticket to HelpDesk
            NID.hIcon = Me.Icon
            Call Shell_NotifyIcon(NIM_MODIFY, NID)
            FrmReqQueue.Visible = True
           
           
        \'Case 3 \' Close HelpDesk
            \'HDExit = True
            \'Unload FrmReqQueue
           
        Case Else
       
        End Select

End Sub


Public Function ShellTrayAdd() As Long
Dim r As Long
\'prepare the NOTIFYICONDATA type with the \'required parameters:
\'.cbSize: Size of this structure, in bytes. \'
\'.hwnd:  Handle of the window that will receive
\'        notification messages associated with
\'        an icon in the taskbar status area. \'
\'uID:    Application-defined identifier of
\'        the taskbar icon. In an application
\'        with a single tray icon, this can be
\'        an arbitrary number.  For apps with
\'        multiple icons, each icon ID must be
\'        different as this member identifies
\'        which of the icons was selected. \'
\'.uFlags: flags that indicate which of the other
\'        members contain valid data. This member
\'        can be a combination of the following:
\'        NIF_ICON    hIcon member is valid.
\'        NIF_MESSAGE uCallbackMessage member is valid.
\'        NIF_TIP    szTip member is valid. \'
\'uCallbackMessage: Application-defined message identifier.
\'        The system uses this identifier for
\'        notification messages that it sends
\'        to the window identified in hWnd.
\'        These notifications are sent when a
\'        mouse event occurs in the bounding
\'        rectangle of the icon. (Note: \'callback\'
\'        is a bit misused here (in the context of
\'        other callback demonstrations); there is
\'        no systray-specific callback defined -
\'        instead the form itself must be subclassed
\'        to respond to this message. \'
\'.hIcon:  Handle to the icon to add, modify, or delete. \'
\'szTip:  Tooltip text to display for the icon. Must
\'        be terminated with a chr$(0).  \'Shell_NotifyIcon messages:
\'dwMessage: Message value to send. This parameter
\'          can be one of these values:
\'          NIM_ADD  Adds icon to status area
\'          NIM_DELETE  Deletes icon from status area
\'          NIM_MODIFY  Modifies icon in status area \'
\'pnid:      Address of the prepared NOTIFYICONDATA.
\'          The content of the structure depends
\'          on the value of dwMessage.
    With NID
        .cbSize = LenB(NID)
        .hwnd = Me.hwnd
        .uID = 125&
        .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        .uCallbackMessage = WM_MYHOOK
        .hIcon = Me.Icon
        .szTip = \"HelpDesk - Guaranteed!\" & Chr$(0)
    End With
  r = Shell_NotifyIcon(NIM_ADD, NID)
  End Function
 
Private Sub ShellTrayRemove()
  \'Remove the icon from the taskbar
  Call Shell_NotifyIcon(NIM_DELETE, NID)
 
End Sub

Public Sub ProcMsg(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
    \'Our custom message handler. WindowProc
    \'assured that only our messages were  \'passed (hWnd), so now we check uMsg
    \'for the custom application-defined  \'identifier (NID.uID) assigned to the
    \'systray icon in NOTIFYICONDATA (NID).  \'
    \'If its ours, we look at lParam for the
    \'message generated, and react appropriately.  On Error Resume Next
  Select Case uMsg
    Case WM_MYHOOK
        \'lParam is the value of the message
        \'that generated the tray notification.
        Select Case lParam
            \'Case WM_MOUSEMOVE
            \'Case WM_LBUTTONDOWN
            \'Case WM_LBUTTONUP
            Case WM_LBUTTONDBLCLK
                NID.hIcon = Me.Icon
                Call Shell_NotifyIcon(NIM_MODIFY, NID)
                FrmReqQueue.Visible = True
                Refresh_Click
               
            \'Case WM_RBUTTONDOWN
            Case WM_RBUTTONUP:
                  Call SetForegroundWindow(Me.hwnd)
                  PopupMenu zmnuFile
                  Call PostMessageLong(Me.hwnd, WM_USER, 0, 0)
        End Select
    Case Else
    End Select
   
End Sub

Private Sub UnSubClass()


\'restore the default message handling
\'before exiting
   
Dim hwndMe As Long
   
    hwndMe = Me.hwnd
    If defWindowProc Then
        SetWindowLong hwndMe, GWL_WNDPROC, defWindowProc
        defWindowProc = 0
  End If
End Sub
Private Sub SubClass(hwnd As Long)
    \'assign our own window message
    \'procedure (WindowProc)
On Error Resume Next
    defWindowProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
   
End Sub
----------------------------------------

/MadD
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester