![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 29
Rep Power: 0
![]() |
how to Minimize application to taskbar ?
I have created software on Library database but when I minimize the program I want to display that as a icon in the system tray not on taskbar. Could you give me some idea?
|
|
|
|
|
|
#2 |
|
Expert Programmer
|
Right...
1. Start a new standardEXE project 2. Add a picture box called picTrayClass and set Visible to false 3. Add a button called cmdHide and set Caption to "Hide to System Tray" 4. Put this code in: Private 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
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayIcon As NOTIFYICONDATA
Const IDANI_OPEN = &H1
Const IDANI_CLOSE = &H2
Const IDANI_CAPTION = &H3
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawAnimatedRects Lib "User32" (ByVal hwnd As Long, ByVal idAni As Long, lprcFrom As RECT, lprcTo As RECT) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private rMe As RECT
Private rTray As RECT
Private Sub DoTrayHide()
'animates tray icon minimize
GetWindowRect Me.hwnd, rMe
'gets the rect of this window
GetWindowRect FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "Button", vbNullString), "TrayNotifyWnd", vbNullString), rTray
'gets the rect of the system tray
Me.Hide
DrawAnimatedRects Me.hwnd, IDANI_CLOSE Or IDANI_CAPTION, rMe, rTray
End Sub
Private Sub DoTrayShow()
'animates tray icon restore
GetWindowRect FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "Button", vbNullString), "TrayNotifyWnd", vbNullString), rTray
'gets the rect of the system tray
DrawAnimatedRects Me.hwnd, IDANI_CLOSE Or IDANI_CAPTION, rTray, rMe
Me.Show
End Sub
Private Sub cmdHide_Click()
DoTrayHide
End Sub
Private Sub Form_Load()
With TrayIcon
.cbSize = Len(TrayI)
.hwnd = picTrayClass.hwnd
.uId = 1&
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.ucallbackMessage = WM_LBUTTONDOWN
.hIcon = Me.Icon
.szTip = "My Application Icon" & Chr$(0)
End With
Shell_NotifyIcon NIM_ADD, TrayIcon
End Sub
Private Sub Form_Unload(Cancel As Integer)
With TrayIcon
.cbSize = Len(TrayIcon)
.hwnd = picTrayClass.hwnd
.uId = 1&
Shell_NotifyIcon NIM_DELETE, TrayIcon
End With
End Sub
Private Sub picTrayClass_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Msg = X / Screen.TwipsPerPixelX
If Msg = WM_LBUTTONDBLCLK Then
'Left button double click
If Not Me.Visible Then DoTrayShow
ElseIf Msg = WM_RBUTTONUP Then
'Right button click
MsgBox "Right button"
End If
End SubThis code is probably unecessarily complicated, and you don't actually need the animation but I thought it looked cool... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|