How to remove systray icon?

Just starting out? Need help? Post your questions and find answers here.
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Re: How to remove systray icon?

Post by whertz »

SROD YOU ARE A GENIUS!!!

You code didn't work at first, findwindow kept returning 0, until I changed from this: FindWindow_("Windowname", 0) to this: FindWindow_(0,"Windowname")

I always thought the string you are searching for with findwindow is the second parameter. Anyway, it works, thank you so much.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: How to remove systray icon?

Post by srod »

Okay, just keep in mind that FindWindow_(0,"Windowname") can be unsafe/unreliable because window titles can change. Take a look at IE for example, the window title changes to reflect whichever page I am currently viewing. Also, the window title could be language dependent etc.

You are better off using the window class name. Use the following code to determine the classname (using the hWnd value you have found) :

Code: Select all

a$ = space(256)
GetClassName_(hWnd, @a$, 256)
debug a$
Once you have the classname, modify your FindWindow_() to :

Code: Select all

FindWindow_("Insert Classname here", 0)
With my Trillian example, I used the classname "trillian" which the application had registered etc.
I may look like a mule, but I'm not a complete ass.
infratec
Always Here
Always Here
Posts: 7580
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to remove systray icon?

Post by infratec »

Hi,

here is my small try for a solution

Code: Select all

Procedure Refresh(hTray.l)
 
 Result = #False
 
 If hTray
  rRect.RECT
  ;get the size of the window
  If GetClientRect_(hTray, rRect)
   ;loop through each line
;   For z.l = 0 To rRect\bottom
z = rRect\bottom / 2
    ; send a MouseMove to each position
    For x = 0 To rRect\right Step 4
     SendMessage_(hTray, #WM_MOUSEMOVE, 0, (z << 16) | x)
    Next x
;   Next z
   
   Result = #True
  EndIf
 EndIf

 ProcedureReturn Result

EndProcedure


Procedure.l FindSysTray()
 
 hWnd.l = FindWindow_("Shell_TrayWnd", #Null)
 If hWnd
  hWnd = FindWindowEx_(hWnd, 0, "TrayNotifyWnd", #Null)
  If hWnd
   hWnd = FindWindowEx_(hWnd, 0, "SysPager", #Null)
   If hWnd
    hWnd = FindWindowEx_(hWnd, 0, "ToolbarWindow32", #Null)
   EndIf
  EndIf
 EndIf
 
 ProcedureReturn hWnd
 
EndProcedure


Procedure SysTrayRefresh() 
 Result = #False
 
 ;get handle of Systray
 hSystray.l = FindSysTray()
 ;refresh Systray
 If Refresh(hSystray) : Result = #True : EndIf
 
 ProcedureReturn Result
 
EndProcedure

SysTrayRefresh()
Please test it.

Bernd
Last edited by infratec on Fri Feb 19, 2010 12:18 pm, edited 3 times in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: How to remove systray icon?

Post by srod »

Yep that works here. :)

Nice solution.
I may look like a mule, but I'm not a complete ass.
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Re: How to remove systray icon?

Post by whertz »

Thanks infratec, another good solution.
infratec
Always Here
Always Here
Posts: 7580
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to remove systray icon?

Post by infratec »

Hi,

it is not neccessary to send a MouseMove to each line,
so I reduced it to the middle line.
I also 'move' now only every 4th pixel.
Since I still hit every icon, it works.

Bernd
Last edited by infratec on Fri Feb 19, 2010 12:19 pm, edited 1 time in total.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: How to remove systray icon?

Post by Michael Vogel »

RASHAD wrote: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?
Right !
infratec
Always Here
Always Here
Posts: 7580
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to remove systray icon?

Post by infratec »

Hi Michael,

my solution 'refreshes' the systray complete.
Like you move the mouse above it :)

Bernd
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to remove systray icon?

Post by RASHAD »

Hi Berned
Sorry it does not work here not with XP nor with Windows 7
It seems to me it will work with some special cases
I created a prog. it is only a process no windows it create a system tray icon and using Esc key to quit
When I kill the process the icon stayes in the system tray and no way up to now to clean it specially with 7
It is a kind of a f**** task somehow

Hi Micharl
Ok I will try (may be .... who knows)
Egypt my love
infratec
Always Here
Always Here
Posts: 7580
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to remove systray icon?

Post by infratec »

Hi Rashad,

I use XP 32 bit and the 'notepad' example.
It works without any problems.

The only thing what it does, is to simulate a mousemove across the whole stuff.
So if your icon removes when you use your real mouse, it should also remove with my program.

Please try the latest version.

Bernd
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to remove systray icon?

Post by RASHAD »

Hi Berned
I know that you are testing some special case
Keep tring will you?
whertz just opened the hell



Michael
BTW:Your marvel code for ejecting the USB flash works for me in XP only
But nobody complain about that so I kept quiet check that please.
Egypt my love
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: How to remove systray icon?

Post by Michael Vogel »

Wrote some words like "Thanks Bernd and Rashad" but it seems that I forgot to click on "send" :evil:

Your code snippets work fine here, I'm sure, one of my next programs will use some lines of them :wink:

Michael
RASHAD wrote:Michael
BTW:Your marvel code for ejecting the USB flash works for me in XP only
But nobody complain about that so I kept quiet check that please.
Hm - I'm using the eject routines in a small tool called "Runner", which is something like a swiss knife on my USB stick. I also have included the routine to eject USB devices, which worked fine on all PCs for now (2000, XP, Vista and 7) -- the only difference is, that the LED doesn't get off on Vista :|

The only thing in the eject procedure lines I had to change for Vista was the following (I fear, that has nothing to do with your problems)
Global LocalDrive;=FirstChar(PeekS(GetCommandLine_()))
GetModuleFileName_(0,@LocalDrive,2); <--- 1 works for XP but not for Vista !
LocalDrive&$df;
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to remove systray icon?

Post by RASHAD »

OK Michael
I will give the code another look
Now see next if it will suit you

Sorry if we are hijacking this thread

Code: Select all


    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)
;********************************( Show Desktop Windows 7 )************************
    
    ;h6 = FindWindowEx_(h2,0,"TrayShowDesktopButtonWClass",0)
    
    
;******************(  Maximize Clock  )**************************

    ShowWindow_(h3,#SW_HIDE)
    ShowWindow_(h5,#SW_MAXIMIZE)
    SHChangeNotify_(134217728,0,0, 0)
    
    
;******************(  Restore Previous  )**************************

;     ShowWindow_(h5,#SW_RESTORE	)
;     ShowWindow_(h3,#SW_SHOW)
;     SHChangeNotify_(134217728,0,0, 0)

Egypt my love
Post Reply