Systray

Started by Marc Van Cauwenberghe, June 02, 2008, 11:42:20 AM

Previous topic - Next topic

Marc Van Cauwenberghe

Hello,

since this isn't the powerbasic site  ;) .
Does anyone have a small yes complete firefly example of how to hide a program to the systray. I would be ever so gratefull.

Regards,
Marc



paulDiagnos

#1
sure...

for the prj...

global gCHANGEICON as long
'------------------------------------------------------------------------------------------------------------------------
Function ICON_WM_CREATE ( _
                        hWndForm As Dword, _  ' handle of Form
                        ByVal UserData As Long _  'optional user defined Long value
                        ) As Long
Icons_SetupTrayIcons         
ShowWindow hwnd_icon, %SW_HIDE
End Function


'------------------------------------------------------------------------------------------------------------------------
Function ICON_CUSTOM ( _
                     hWndForm      As Dword, _  ' handle of Form
                     wMsg          As Long,  _  ' type of message
                     wParam        As Dword, _  ' first message parameter
                     lParam        As Long   _  ' second message parameter
                     ) As Long               
Select Case wMsg       
           Case %WM_TRAYICON
            Select Case LoWrd(lParam)
                    Case %WM_LBUTTONUP
If IsWindowVisible(hwnd_icon)= 0 Then
ShowWindow hwnd_icon, %SW_SHOW
End If
SetForegroundWindow(hwnd_icon)                            
            End Select
          Case %WM_SYSCOMMAND
Select Case wParam
          Case %SC_MINIMIZE
            ShowWindow hwnd_icon, %SW_HIDE 
              Function = %TRUE                    
          End Select 
End Select         
End Function
'------------------------------------------------------------------------------------------------------------------------
Function ICON_WM_DESTROY ( _
                         hWndForm      As Dword _  ' handle of Form
                         ) As Long
                         
Icons_DestroyTrayIcons
End Function



and then for my include file to deal with icons and trays etc...

Global gTrayMenu As Dword
Global ti As NOTIFYICONDATA

%WM_TRAYICON            = %WM_USER + 500
%WM_SYSHIDE             = %WM_USER + 512
'------------------------------------------------------------------------------------------------------------------------
Function Icons_SetupTrayIcons As Long
Local mi As MENUITEMINFO                     
Local lngSystemMenu As Long
Local tempsz As String
mi.cbSize=SizeOf(mi)
mi.fMask= %MIIM_TYPE Or %MIIM_STATE Or %MIIM_ID
mi.fType= %MF_STRING
mi.wID= %WM_SYSHIDE
tempsz= "&Hide"
mi.dwTypeData= VarPtr(tempsz)
lngSystemMenu = GetSystemMenu(hwnd_icon, 0)
InsertMenuItem(lngSystemMenu, 0, %TRUE, mi)
ti.cbSize = SizeOf(ti)
ti.hWnd = hwnd_icon
ti.uID = App.hInstance
ti.uFlags = %NIF_ICON Or %NIF_MESSAGE Or %NIF_TIP
ti.uCallbackMessage = %WM_TRAYICON
ti.hIcon            = LoadIcon(App.hInstance, "icon1") 
ti.szTip = "eggg"
Shell_NotifyIcon %NIM_ADD, ti             
gTrayMenu= CreatePopupMenu()
End Function   
'------------------------------------------------------------------------------------------------------------------------
Function Icons_DestroyTrayIcons As Long
Shell_NotifyIcon %NIM_DELETE, ti
DestroyMenu(gTrayMenu)
End Function
'------------------------------------------------------------------------------------------------------------------------
Sub Change_IconTray1 
ti.hIcon = LoadIcon(App.hInstance, "icon1")
ti.szTip = "egg"
Shell_NotifyIcon %NIM_MODIFY, ti
DestroyIcon ti.hIcon   
End Sub                             
'------------------------------------------------------------------------------------------------------------------------
Sub Change_IconTray2
ti.hIcon = LoadIcon(App.hInstance, "icon2")
ti.szTip = "eggs"
Shell_NotifyIcon %NIM_MODIFY, ti
DestroyIcon ti.hIcon             
End Sub



you may wnat to have some icon resources.

ICON1    ICON DISCARDABLE "pallet.ICO"
ICON2    ICON DISCARDABLE "tech.ICO"




hope this helps....

i should add this is probably not my code i think i must have stole it and adapted it some how, (like all good engineers)

Paul.



[attachment deleted by admin]

Marc Van Cauwenberghe

Thank you very, very much.

Regards,
Marc

paulDiagnos

no problems
im just glad i can help someone else for a change, rather than relying on other. :-)

Roger Garstang

#4
When porting to PB or posting for help in PB forum you will need to switch ti.uID = App.hInstance to use the GetModuleHandle function.  Otherwise MCM and the bunch will have a cow and then the FF bashers will start in.  I get that a lot.