cablehead

I have a couple of tray icons that refuse to dispose/disapper reliably.

I can find the tray handle using:

public static extern int FindWindow(

string lpClassName, // class name

string lpWindowName // window name

);

[DllImport("user32", EntryPoint = "FindWindowEx")]

public static extern int FindWindowExA(int hWnd1, int hWnd2, string lpsz1, string lpsz2);

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam);

int shelltraywnd = FindWindow("shell_traywnd", null);

int traynotifywnd = FindWindowExA(shelltraywnd, 0, "traynotifywnd", null);

int trayclockwclass = FindWindowExA(traynotifywnd, 0, "trayclockwclass", null);

Console.WriteLine(trayclockwclass.ToString());

Is there any message I can send to Refresh it




Re: Windows Forms General Refresh System Tray

Muhammad_Afzaal

//Include following code with yours to refresh System Tray.

public const int WM_PAINT = 0xF;
[DllImport("USER32.DLL")]
public static extern int SendMessage(IntPtr hwnd, int msg, int character, IntPtr lpsText);


//Send WM_PAINT Message to paint System Tray which will refresh it.
SendMessage(traynotifywnd,WM_PAINT,0,IntPtr.Zero);


Regards,
Muhammad Afzaal




Re: Windows Forms General Refresh System Tray

Jayasingh Dharmaseelan

if the process is started by you, then use ProcessName.CloseMainWindow() method instead of ProcessName.Kill() method.

I hope this will help.





Re: Windows Forms General Refresh System Tray

nobugz

This is a bug in the NotifyIcon class, documented in this Product Feedback article. The workaround is simple enough, set its Visible property to False in the FormClosing event.





Re: Windows Forms General Refresh System Tray

Saresh Naroji

I wanted to know is there any way to display the applications in system tray on a windows form with the same functionality. in a way i want to shift system tray on the Form.

do reply with any suggestion or any specific method.

Regards,

Saresh






Re: Windows Forms General Refresh System Tray

bill_csharper

I tried this, but it doesn't work. That is, sending the WM_PAINT message to the traynotifywnd window doesn't make the icon (whose associated app was killed) go away. Could someone post a full code listing of a working sample app here

Also I think there are some confusions about the real requirement of this issue:


Scenario 1. I just want to remove all icons "whose associated apps died" from the sys tray; i have no control over the source code of these apps, so i can't modify them to add some code to the dispose method.

Scenario 2. I do have control over these systray apps


It is Scenario 1. that i'm most interested here. I guess "sending WM_PAINT to traynotifywnd" might work on certain platforms/configurations, but not mine, which is:

Windows Server 2003 Standard Edition with SP1, desktop configured to use the "Windows Classic" Theme.





Re: Windows Forms General Refresh System Tray

rnbguy

did you find out how to do this