Alternative for FindWindow ?

Hi,

I hope some here can help me out.

I want to normaly exit an external application. I've found ways to kill it, but that leaves a tray icon available. So i thought to have found a way to use the SendMessage or PostMessage (all listed in the function)

I tried it on the Calculator on the pocketpc and it works great (see below)

The problem:
The application i want to exits lives as a tray icon, and is NOT listed in te "running applications" so (i assume) i can't use the FindWindow.
Is there any other way to find the handle i.e. FindProcess (if this exist, how do i declare the DllImport)



public void quitCalculator()
{
const int WM_QUIT = 0x0012;
const int WM_CLOSE = 0x0010;

IntPtr handle = new IntPtr(FindWindow(null,"Calculator"));

SendMessage(handle,WM_CLOSE,0,0);
SendMessage(handle,WM_QUIT,0,0);
PostMessage(handle,WM_CLOSE,0,0);
PostMessage(handle,WM_QUIT,0,0);
}

[DllImport("coredll.dll")]
public extern static int SendMessage(IntPtr hwnd, uint msg, uint wParam, uint lParam);
[DllImport("coredll.dll")]
public extern static int PostMessage(IntPtr hwnd, uint msg, uint wParam, uint lParam);
[DllImport("coredll.dll",EntryPoint="FindWindow")]
public static extern int FindWindow(string lpClassName,string lpWindowName);

 


maybe there are other ways

i also noticed that there are you can find windows that are not listed.
For example i found you can show / hide taskbar
hwnd = FindWindow("HHTaskBar", null);
Is there a way to show all "hidden" forms

And i was thinking a bit more, there is an Exit menu item if i click the tray icon, any ideas if it's possible to "listen" for messages (i believe i've read that al closing of applications in the background use the postmessage) if that's true and i could listen for that message i could see how to close it or am i off course now

Hope someone can help me,
Greetings,
Jeroen


Answer this question

Alternative for FindWindow ?

  • Russan

    The only way to clear the process from the System tray is for the application you are trying to close to do the clean up itself from within. When you kill an application it doesn't give it a chance to clean up the tray icon, so it remains.

    However, here is an observation, I noticed when Yahoo Massenger sometimes crashes on me, it leaves the smiley icon in the System even though the process has been killed. However, when I move the mouse over the system tray, that automatically spawns the system to clean up the icon automatically. So given that, you make a hack where right after you kill the process, you'd simulate a mouse move near the System Tray region. Give that hack a try...

    If you are working with C#, you can also check this link for how to close another process window directly from .NET without calling the Native WIn32 DLL: http://www.mycsharpcorner.com/Post.aspx postID=32

    Hope this helps,



  • gary-ccl

    i know i can kill it (see my original post), but i don't want to, that leaves a tray icon available. (an empty reserved space in the taskbar well the one below, don't know how you call that)

    But i've also posted in a newsgroup and with some pointers i finally found out how:

    Here is the why i found how for anyone who has the same problem finding his window:

    http://groups.google.nl/group/microsoft.public.pocketpc.developer/browse_thread/thread/9930d4e7e5381a42/b9660752d180d364#b9660752d180d364

  • hailey

    You can also kill the process itself. Take a look at my article on MSDN:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnnetcomp/html/ProcessManager.asp frame=true

  • Alternative for FindWindow ?