How to remove systray icon?
Re: How to remove systray icon?
Then how do you normally close this program?
			
			
									
									I may look like a mule, but I'm not a complete ass.
						Re: How to remove systray icon?
You have to right click on the system tray icon and select exit.srod wrote:Then how do you normally close this program?
Re: How to remove systray icon?
srod I think it is not that easy
I only succeeded to delete one icon ( the network )
			
			
									
									I only succeeded to delete one icon ( the network )
Egypt my love
						Re: How to remove systray icon?
Rashad, that code does not retrieve all taskbar icons. I recall reading that this method does/will not retrieve all icons so it is probably something we just have to accept.
 )
			
			
									
									Doesn't surprise me really. I think in Whertz's case, given that he is killing the program, deleting the systray icon will probably succeed. (By probably I mean that I haven't got a clue really!srod I think it is not that easy
I only succeeded to delete one icon ( the network )
I may look like a mule, but I'm not a complete ass.
						Re: How to remove systray icon?
Thanks srod and rashad!
Learned a lot from this thread.
Whertz, didn't realize you wanted to remove systray icons from programs you didn't start.
That is not in my plans.
I only want to control what I create and initiate and try not to do too much damage.
			
			
													Learned a lot from this thread.
Whertz, didn't realize you wanted to remove systray icons from programs you didn't start.
That is not in my plans.
I only want to control what I create and initiate and try not to do too much damage.
					Last edited by skywalk on Mon Jul 07, 2014 11:29 pm, edited 1 time in total.
									
			
									
						Re: How to remove systray icon?
I do start the program with runprogram, but when I run it with your code example, it makes an extra system tray icon the same as the program, closes the program and removes the system tray icon that was created. The original system tray icon remains.skywalk wrote:Thanks srod and rashad!
Learned a lot from this thread.
Whertz, didn't realize you wanted to remove systray icons from programs you didn't start.
That is not in my plans.
I only want to control what I create and initiate and try not to do too much damage.
-Steve
Re: How to remove systray icon?
Thanks Whertz, now I really understand the issue... 
I wasn't testing that case, since "Notepad.exe" doesn't open a systray icon. Doh!
Better test would have been to create a simple exe that opens a systray icon and waits to be closed.
Then attempt to close it with the code in this thread.
			
			
													I wasn't testing that case, since "Notepad.exe" doesn't open a systray icon. Doh!
Better test would have been to create a simple exe that opens a systray icon and waits to be closed.
Then attempt to close it with the code in this thread.
					Last edited by skywalk on Mon Jul 07, 2014 11:29 pm, edited 1 time in total.
									
			
									
						Re: How to remove systray icon?
Here's an example: Compile this as trayicon.exe:skywalk wrote:Thanks Whertz, now I really understand the issue...
I wasn't testing that case, since "Notepad.exe" doesn't open a systray icon. Doh!
Better test would have been to create a simple exe that opens a systray icon and waits to be closed.
Then attempt to close it with the code in this thread.
-Steve
Code: Select all
OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible)
AddSysTrayIcon(1, WindowID(0), ExtractIcon_(0,"notepad.exe",0)) 
Repeat
  WaitWindowEvent()
ForEver
Now run it with this:
Code: Select all
processID.l = RunProgram("trayicon.exe","","",#PB_Program_Open) 
Delay(10000)
KillProgram(processID)
CloseProgram(processID) 
Re: How to remove systray icon?
Okay, I have tested the following with my MSN/ICQ... chat client (Trillian) which is a program which has to be closed by right-clicking the tray icon and selecting EXIT etc.
When I use RunProgram() to start the program and then KillProgram() to terminate it, the icon is left in the tray, so exactly the same situation as yours Whertz. The function RemoveTrayIcon() (in the code below), used after killing the program, manages to remove the icon without a problem.
@Whertz : note the steps I have taken in my test code to secure the hWnd of the main Trillian window. I used Rashad's Enum_TrayIcons() routine to first check that the owner hWnd corresponding to the tray icon placed there by Trillian is the same one returned by FindWindow_(). I cannot stress this enough. If the code fails for you then it will most likely be because you have not identified the correct handle (hWnd). (I actually used EnumWindows_() first and then compared all hWnd values with that returned by Rashad's code in order to obtain the correct class name. I then use this classname with the FindWindow() call).
The code is based upon Rashad's code based upon Netmaestro's original routine.
 
			
			
									
									When I use RunProgram() to start the program and then KillProgram() to terminate it, the icon is left in the tray, so exactly the same situation as yours Whertz. The function RemoveTrayIcon() (in the code below), used after killing the program, manages to remove the icon without a problem.
@Whertz : note the steps I have taken in my test code to secure the hWnd of the main Trillian window. I used Rashad's Enum_TrayIcons() routine to first check that the owner hWnd corresponding to the tray icon placed there by Trillian is the same one returned by FindWindow_(). I cannot stress this enough. If the code fails for you then it will most likely be because you have not identified the correct handle (hWnd). (I actually used EnumWindows_() first and then compared all hWnd values with that returned by Rashad's code in order to obtain the correct class name. I then use this classname with the FindWindow() call).
The code is based upon Rashad's code based upon Netmaestro's original routine.
Code: Select all
Structure TRAYDATA
  hwnd.l                
  uID.l             
  uCallbackMessage.i    
  Reserved.l[2]      
  hIcon.l                
EndStructure
Structure _TBBUTTON
  iBitmap.l 
  idCommand.l
  fsState.b 
  fsStyle.b 
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
  bReserved.b[6]
CompilerElse
  bReserved.b[2]
CompilerEndIf
  dwData.i 
  iString.i 
EndStructure
;Returns #True if successful.
Procedure.i RemoveTrayIcon(hWndOwner)
  Protected result, hWnd, hTray, count, dwExplorerThreadId, i, hProc, *lpData, button._TBBUTTON, button_td.TRAYDATA
  Protected nid.NOTIFYICONDATA
  hWnd = FindWindow_("Shell_TrayWnd", #Null)
  If hWnd
    hWnd = FindWindowEx_(hWnd, #Null, "TrayNotifyWnd", #Null)
    If hWnd
      hWnd = FindWindowEx_(hWnd,#Null, "SysPager", #Null)
      If hWnd 
        hTray = FindWindowEx_(hWnd, #Null, "ToolbarWindow32", #Null)
        If hTray
          dwExplorerThreadId=GetWindowThreadProcessId_(hTray, @dwExplorerProcessId)
          If dwExplorerProcessId
            hProc = OpenProcess_(#PROCESS_ALL_ACCESS, #False, dwExplorerProcessId)
            If hProc
              *lpData = VirtualAllocEx_(hProc, #Null, SizeOf(_TBBUTTON), #MEM_COMMIT, #PAGE_READWRITE)
              If *lpData
                count = SendMessage_(hTray, #TB_BUTTONCOUNT, 0, 0)
                For i = 0 To count-1
                  SendMessage_(hTray, #TB_GETBUTTON, i, *lpData)
                  ReadProcessMemory_(hProc, *lpData, @button, SizeOf(_TBBUTTON), #Null)    
                  ReadProcessMemory_(hProc, button\dwData, @button_td, SizeOf(TRAYDATA), #Null)
                  If button_td\hwnd = hWndOwner
                    With nid
                      \cbSize = SizeOf(NOTIFYICONDATA)
                      \hWnd = hWndOwner
                      \uID = button_td\uID
                      \uFlags = #NIF_ICON
                      \hIcon = button_td\hIcon
                    EndWith
                    result = Shell_NotifyIcon_(#NIM_DELETE, nid)
                    Break
                  EndIf
                Next
                VirtualFreeEx_(hProc, *lpData, #Null, #MEM_RELEASE)
              EndIf      
              CloseHandle_(hProc)
            EndIf
          EndIf        
        EndIf
      EndIf
    EndIf
  EndIf
  ProcedureReturn result  
EndProcedure
;Test.
  processID = RunProgram("C:\Program Files\Trillian\trillian.exe", "", "", #PB_Program_Open)  
  MessageRequester("", "Click OK when Trillian has loaded!")
  hWnd = FindWindow_("trillian", 0)
  KillProgram(processID)
  If RemoveTrayIcon(hWnd)
    MessageRequester("Heyho!", "RemoveTrayIcon() reports success!")
  Else
    MessageRequester("Heyho!", "RemoveTrayIcon() reports failure!")
  EndIf
I may look like a mule, but I'm not a complete ass.
						Re: How to remove systray icon?
Hi everybody
Hi whertz
You did not inform us after srod last code
Ok here is some code may it help you somehow
Tested with Xp x86 Win 7 x64
 Have fun
			
			
									
									Hi whertz
You did not inform us after srod last code
Ok here is some code may it help you somehow
Tested with Xp x86 Win 7 x64
Code: Select all
  ; Show or Hide System Tray Icons or System Tray Clock Programmatic (Windows)
  ; RASHAD 18/02/2010
    h1 = FindWindow_("Shell_TrayWnd",0)   
    h2 = FindWindowEx_(h1,0,"TrayNotifyWnd",0)
    h3 = FindWindowEx_(h2,0,"SysPager",0)  
    h4 = FindWindowEx_(h3,0,"ToolbarWindow32",0)
    h5 = FindWindowEx_(h2,0,"TrayClockWClass",0)
    
;******************(  Hide System Tray Icons  )**************************
    
    ShowWindow_(h3,#SW_HIDE)
    SHChangeNotify_(134217728,0,0, 0)
    
;******************(  Show System Tray Icons  )**************************
    
    ;ShowWindow_(h3,#SW_SHOW)
    ;SHChangeNotify_(134217728,0,0, 0)    
    
;*********************(  Hide System Clock  )****************************
    
    ;ShowWindow_(h5,#SW_HIDE)
    ;SHChangeNotify_(134217728,0,0, 0)
    
;*********************(  Show System Clock  )****************************
    
    ;ShowWindow_(h5,#SW_SHOW)
    ;SHChangeNotify_(134217728,0,0, 0)
Egypt my love
						- Spaceman Spiff
 - User

 - Posts: 11
 - Joined: Mon Feb 15, 2010 9:13 pm
 
Re: How to remove systray icon?
I played with this rashad! I uncommented all the ; stuff... HEELP... all my windows has disappeared! How do I get it back! This is mean code!  
			
			
									
									
						Re: How to remove systray icon?
@Spaceman Spiff Hi
Uncomment only what you want to do per once
So uncomment only Show System tray icons and run the code once
Then comment Show system Tray icons again and uncomment Show System clock and run the code again
Uncomment only what you want to do and run the code once then comment it again
this one will hide system tray icons:
this one will show system tray icons:
Got it?
			
			
									
									Uncomment only what you want to do per once
So uncomment only Show System tray icons and run the code once
Then comment Show system Tray icons again and uncomment Show System clock and run the code again
Uncomment only what you want to do and run the code once then comment it again
this one will hide system tray icons:
Code: Select all
; Show or Hide System Tray Icons or System Tray Clock Programmatic (Windows)
; RASHAD 18/02/2010
    h1 = FindWindow_("Shell_TrayWnd",0)   
    h2 = FindWindowEx_(h1,0,"TrayNotifyWnd",0)
    h3 = FindWindowEx_(h2,0,"SysPager",0)  
    h4 = FindWindowEx_(h3,0,"ToolbarWindow32",0)
    h5 = FindWindowEx_(h2,0,"TrayClockWClass",0)
    
;******************(  Hide System Tray Icons  )**************************
    
    ShowWindow_(h3,#SW_HIDE)
    SHChangeNotify_(134217728,0,0, 0)
    
;******************(  Show System Tray Icons  )**************************
    
    ;ShowWindow_(h3,#SW_SHOW)
    ;SHChangeNotify_(134217728,0,0, 0)    
    
;*********************(  Hide System Clock  )****************************
    
    ;ShowWindow_(h5,#SW_HIDE)
    ;SHChangeNotify_(134217728,0,0, 0)
    
;*********************(  Show System Clock  )****************************
    
    ;ShowWindow_(h5,#SW_SHOW)
    ;SHChangeNotify_(134217728,0,0, 0)
Code: Select all
; Show or Hide System Tray Icons or System Tray Clock Programmatic (Windows)
; RASHAD 18/02/2010
    h1 = FindWindow_("Shell_TrayWnd",0)   
    h2 = FindWindowEx_(h1,0,"TrayNotifyWnd",0)
    h3 = FindWindowEx_(h2,0,"SysPager",0)  
    h4 = FindWindowEx_(h3,0,"ToolbarWindow32",0)
    h5 = FindWindowEx_(h2,0,"TrayClockWClass",0)
    
;******************(  Hide System Tray Icons  )**************************
    
    ;ShowWindow_(h3,#SW_HIDE)
    ;SHChangeNotify_(134217728,0,0, 0)
    
;******************(  Show System Tray Icons  )**************************
    
    ShowWindow_(h3,#SW_SHOW)
    SHChangeNotify_(134217728,0,0, 0)    
    
;*********************(  Hide System Clock  )****************************
    
    ;ShowWindow_(h5,#SW_HIDE)
    ;SHChangeNotify_(134217728,0,0, 0)
    
;*********************(  Show System Clock  )****************************
    
    ;ShowWindow_(h5,#SW_SHOW)
    ;SHChangeNotify_(134217728,0,0, 0)
Egypt my love
						- Spaceman Spiff
 - User

 - Posts: 11
 - Joined: Mon Feb 15, 2010 9:13 pm
 
Re: How to remove systray icon?
YAY RASHAD! That worked! This could really mess up someones mind! Ha! 
I have the impulse to play a trick on my sister later...
			
			
									
									
						I have the impulse to play a trick on my sister later...
- Michael Vogel
 - Addict

 - Posts: 2821
 - Joined: Thu Feb 09, 2006 11:27 pm
 - Contact:
 
Re: How to remove systray icon?
Cool trick, rashad!
Is there a possibility to remove the empty space, where the icons have been, automatically?
			
			
									
									
						Is there a possibility to remove the empty space, where the icons have been, automatically?
Code: Select all
; Show or Hide System Tray Icons or System Tray Clock Programmatic (Windows)
; RASHAD 18/02/2010
h1 = FindWindow_("Shell_TrayWnd",0)
h2 = FindWindowEx_(h1,0,"TrayNotifyWnd",0)
h3 = FindWindowEx_(h2,0,"SysPager",0)
h4 = FindWindowEx_(h3,0,"ToolbarWindow32",0)
h5 = FindWindowEx_(h2,0,"TrayClockWClass",0)
#Wait=1000
;******************(  Hide System Tray Icons  )**************************
ShowWindow_(h3,#SW_HIDE)
SHChangeNotify_(134217728,0,0, 0)
End
;******************(  Show System Tray Icons  )**************************
Delay(#Wait)
ShowWindow_(h3,#SW_SHOW)
SHChangeNotify_(134217728,0,0, 0)
;*********************(  Hide System Clock  )****************************
Delay(#Wait)
ShowWindow_(h5,#SW_HIDE)
SHChangeNotify_(134217728,0,0, 0)
;*********************(  Show System Clock  )****************************
Delay(#Wait)
ShowWindow_(h5,#SW_SHOW)
SHChangeNotify_(134217728,0,0, 0)
Re: How to remove systray icon?
Hi Michael
Nice talking to you
Give me some details, like What do you want to do?(may be I can help)
I think XP is in your mind not Win 7, right?
			
			
									
									Nice talking to you
Give me some details, like What do you want to do?(may be I can help)
I think XP is in your mind not Win 7, right?
Egypt my love
						
