PDA

View Full Version : minimize to system tray



Ronald_yoh
04-26-2009, 09:45 PM
does anyone know how to minimize ms access into a system tray?

thanks

CreganTur
04-27-2009, 05:30 AM
DoCmd.RunCommand acCmdAppMinimize

HTH:thumb

Ronald_yoh
04-28-2009, 05:47 AM
i believe ur code will only minimize the window.

what i'm after is minimizing to system tray (next to clock, on the lower right hand corner).

do you have any further suggestions?

CreganTur
04-28-2009, 06:25 AM
i believe ur code will only minimize the window.

what i'm after is minimizing to system tray (next to clock, on the lower right hand corner).

do you have any further suggestions?

That's a lot more invovled. You would actually have to create a TaskIcon object. This is going to involve some very advanced VBA.

Take a look at this thread (http://www.experts-exchange.com/Programming/Misc/Q_21347205.html)- scroll all the wya to the bottom to see replies. One guy provides code to create the Task Icon.

Hope it works.

Movian
05-05-2009, 08:53 AM
Would you mind posting that code for those of us who are not blessed with having a experts exchange account ?

:)

CreganTur
05-05-2009, 08:54 AM
Would you mind posting that code for those of us who are not blessed with having a experts exchange account ?

:)

If you scroll all the way to the bottom of the page, you should be able to see the solution without having an account. I don't have an account, and that's how I see it.

Movian
05-05-2009, 12:11 PM
i know what you mean, sometimes if its a long thread they show the last few however this time every single thread just says to view try out the 7 days free trial... which i already did ^_^;;

i guess i could use a different e-mail though

Ronald_yoh
05-06-2009, 05:02 AM
yes.. i think you need to accept the 7 days trial offer before viewing the complete code... to be honest mate.. i'm still struggle with this (haven't really looked at the epert-exchange and can't be bother to do so)....

Movian
05-14-2009, 12:19 PM
Here is the contents of that post

I signed up for the 2 week trial then de activated my account


jkorz (https://secure.experts-exchange.com/M_3519366.html):
I am pretty sure it can be done in vba

**BEGIN MOD_TrayIcon**
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

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

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBL = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_ACTIVATEAPP = &H1C
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const MAX_TOOLTIP As Integer = 64
Public Const GWL_WNDPROC = (-4)

Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type

Public nfIconData As NOTIFYICONDATA

Private FHandle As Long
Private WndProc As Long
Private Hooking As Boolean

Public Sub Hook(Lwnd As Long)
If Hooking = False Then
FHandle = Lwnd
WndProc = SetWindowLong(Lwnd, GWL_WNDPROC, AddressOf WindowProc)
Hooking = True
End If
End Sub

Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If Hooking = True Then
If uMsg = WM_RBUTTONUP And lParam = WM_RBUTTONDOWN Then
fMainForm.SysTrayMouseEventHandler
WindowProc = True
Exit Function
ElseIf lParam = WM_LBUTTONDBL Then
fMainForm.open_Click
WindowProc = True
Exit Function
End If
WindowProc = CallWindowProc(WndProc, hw, uMsg, wParam, lParam)
End If
End Function

Public Sub RemoveIconFromTray()
Shell_NotifyIcon NIM_DELETE, nfIconData
End Sub

Public Sub Unhook()
If Hooking = True Then
SetWindowLong FHandle, GWL_WNDPROC, WndProc
Hooking = False
End If
End Sub

Public Sub AddIconToTray(MeHwnd As Long, MeIcon As Long, MeIconHandle As Long, Tip As String)
With nfIconData
.hwnd = MeHwnd
.uID = MeIcon
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_RBUTTONUP
.hIcon = MeIconHandle
.szTip = Tip & Chr$(0)
.cbSize = Len(nfIconData)
End With
Shell_NotifyIcon NIM_ADD, nfIconData
End Sub
**END MOD_TRAYICON**

Ronald_yoh
05-14-2009, 03:41 PM
thanks.. but i tried the code.. and it minimize to tray while trying to close it... also how do i add an item if the user right clicks the icon in the system tray?

thanks

CreganTur
05-15-2009, 05:23 AM
thanks.. but i tried the code.. and it minimize to tray while trying to close it... also how do i add an item if the user right clicks the icon in the system tray?


If you're talking about adding in a context menu that appears when you right-click the icon, then that's going to be another large undertaking, since it means creating another new object with VBA.

I've found a number of artcles on creating context menus with VBA, but they all rely on either 1) manipulating context menus in Excel, or 2) adding context menus to objects in an Access Form (or other Office product UserForm).

I haven't found anything about adding a context menu to an external object. Try a little google-fu, some digging might reveal an answer.:dunno

DarkSprout
05-21-2009, 06:25 PM
The trick to reading those experts-exchange posts is to get the Q_ number like Q_21347205 from the address bar, search Google for that site and then click on the 'Cached' button - and like magic you've open the genie's box.
- the Accepted Solution will always be left open.

Movian
05-22-2009, 08:07 AM
that is one of the most useful tips i have found on the forum :D
Thanks!

BIRD_FAT
05-24-2009, 01:53 AM
I know this is not a VBA solution, BUT...

There are two freeware apps that do what you are trying to do!

TrayIt (http://www.trayit.com)- you can add programs to it's menu, and when you click minimize they go to the system tray, click the icon to return them to the screen.

or

PowerMenu (http://www.abstractpath.com/powermenu/)- adds some extra options to the context menu, including transparency, always on top and minimize to system tray.

I've used them both for years!