Page 1 of 2
How to open or show a running application from the Traybar
Posted: Tue Mar 11, 2008 5:14 pm
by Philippe-felixer76-2
Hi There,
Does anyone know if there's a way or a API command that will
open or show the actual window (main program) of a icon on the traybar?
I have tried lot's of code found on PB form and google, but i can't seem
to get the right 'mainwindowhandle' of a app.
I also tried to sendmessage() some double clicks to the tray but it always
opens the first app found.
I tried to sendmessage() to the windowID i get from my tray enum
procedure, without any luck..
Is there a way i can send a message to the process of the app or such?
Found this, helped me a bit..
http://www.purebasic.fr/english/viewtop ... 140#142140
This might be the solution, but not for PB

:
http://msdn2.microsoft.com/en-us/librar ... andle.aspx
Bye,
Phil.
Posted: Tue Mar 11, 2008 5:43 pm
by AND51
Get the window handle of the target window and try ShowWindow_(). There are different flags that lets you restore, minimize, maximize, hide, etc. the window.
Edit:
Use #SW_RESTORE.
Posted: Tue Mar 11, 2008 5:44 pm
by Fluid Byte
How do you specify wich item/application of the taskbar should be activated? Do you want to pass the index of a given button in the taskbar to some custom procedure and set the focus to the program?
Help me..
Posted: Tue Mar 11, 2008 6:41 pm
by Philippe-felixer76-2
Fluid Byte wrote:How do you specify wich item/application of the taskbar should be activated? Do you want to pass the index of a given button in the taskbar to some custom procedure and set the focus to the program?
Now i enumerate all programs in the tray, and i get the
handle via *dwi.DWDATAINFO, hWindow.l = *dwi\hwnd.
I just want to simulate a double click on the trayicon item i enum and
want.
If you have a solution any way, i take it.
Posted: Tue Mar 11, 2008 6:42 pm
by Philippe-felixer76-2
AND51 wrote:Get the window handle of the target window and try ShowWindow_(). There are different flags that lets you restore, minimize, maximize, hide, etc. the window.
Edit:
Use #SW_RESTORE.
'Get the Window handle'
There's the problem, i get a non MAINWINDOW handle
from my systray enum function.
Posted: Tue Mar 11, 2008 6:50 pm
by srod
Surely the handle you get is for the window to which the trayicon is attached?
Anyhow, what about GetParent_() etc?
Posted: Tue Mar 11, 2008 6:52 pm
by Fluid Byte
I just want to simulate a double click on the trayicon item i enum and
want.
That's not really elegant. Just retrieve the handle you want and activate the window with SetForegroundWindow_() (ShowWindow() won't work on this).
Posted: Tue Mar 11, 2008 6:54 pm
by Philippe-felixer76-2
Fluid Byte wrote:I just want to simulate a double click on the trayicon item i enum and
want.
That's not really elegant. Just retrieve the handle you want and activate the window with SetForegroundWindow_() (ShowWindow() won't work on this).
No realy, doesn't work for this program, i already tried,
it opens some hidden buttonless sub window.
How does windows handle/open it when a user double clicks
on the icon?
Posted: Tue Mar 11, 2008 6:57 pm
by Philippe-felixer76-2
srod wrote:Surely the handle you get is for the window to which the trayicon is attached?
Anyhow, what about GetParent_() etc?
The program has many many windows opend when started,
most are hidden, about 52 windows i remember. The window
i get from the enumeration, the SUPPOSE to be the window
to SHOW, hasn't got a parent and isn't the window i want.
I already found a way to get the REAL window, so i solved
the problem already, but this is a very vague way to get
the handle, i just want to open it like when a user double
clicks on the tray icon.
There must be a way to send a message to the process with
a flag telling the user has doubleclicked the traybar icon, right??!
Posted: Thu Mar 13, 2008 5:07 pm
by Philippe-felixer76-2
Philippe-felixer76-2 wrote:srod wrote:Surely the handle you get is for the window to which the trayicon is attached?
Anyhow, what about GetParent_() etc?
The program has many many windows opend when started,
most are hidden, about 52 windows i remember. The window
i get from the enumeration, the SUPPOSE to be the window
to SHOW, hasn't got a parent and isn't the window i want.
I already found a way to get the REAL window, so i solved
the problem already, but this is a very vague way to get
the handle, i just want to open it like when a user double
clicks on the tray icon.
There must be a way to send a message to the process with
a flag telling the user has doubleclicked the traybar icon, right??!
Finaly i found someone with the same problem..
http://www.thescripts.com/forum/thread451180.html
And offcourse still no solution .. ;(
Gr,
Phil.
Posted: Thu Mar 13, 2008 5:28 pm
by Fluid Byte
Wich program you want to activate anyway?
Posted: Thu Mar 13, 2008 6:19 pm
by Philippe-felixer76-2
Fluid Byte wrote:Wich program you want to activate anyway?
Can't comment on that for now..
But anyway, i found out the messageflag for a app to respond
to a doubleclick on the tray can be or is custom. So my app can
never find out what value the programmer used for his prog.
Something thats seems so simple can be very tricky i quess..
The Anwser..
Posted: Thu Mar 13, 2008 8:26 pm
by Philippe-felixer76-2
I quess i found the real anwser here:
http://msdn2.microsoft.com/en-us/magazine/cc301495.aspx
A Which main window do you mean? A process can have more than one. Microsoft® Outlook® is a good example. If you start Outlook, you get a window listing your Inbox and other folders. If you open e-mail, you get another window that displays the message. Both are main windows in the sense that they have no parent or owner. If you whip out your trusty Spy tool, you can see they even have the same class name: rctrl_renwnd32. In general there's no way to tell (say, from the style flags or class name) which window is the "real" main window.
That said, finding the (possibly multiple) main windows is easy. You can use EnumWindows and GetWindowThreadProcessId to find all top-level windows with a process ID that matches the one you're looking for.
Been there, tried that, done that..
If you're using .NET, you can get the main window handle of a Process object from the property Process.MainWindowHandle. For example, in C#:
Snif.. i know ..
Apparently, somewhere deep inside itself, Windows® does in fact know which window is "the" main window. Alas, I was unable to discover any way of obtaining this window through C/C++.
Just what i thought. ;-(
Posted: Thu Mar 13, 2008 8:42 pm
by Fluid Byte
Ok, now this is turning into an endless loop! You have a question, we try to help you and then you say you solved it yourself again. Please make up your mind.
Do you have a single, specific question now wich you can't solve on your own?
Posted: Thu Mar 13, 2008 8:57 pm
by Philippe-felixer76-2
Fluid Byte wrote:Ok, now this is turning into an endless loop! You have a question, we try to help you and then you say you solved it yourself again. Please make up your mind.
Do you have a single, specific question now wich you can't solve on your own?
Look, i realy like some help, and i already have some kind
of solution that fixes the problem for now.
But i do want a definitive universal solution, and by reading
this article, i understand it's only possible using windows NET
code. And even then it's impossible because MainWindowHandle
returns 0 when in minimized state, so i read..
So to make it short, i defenitly want help, but i have no
faith it's impossible ..
Gr,
Phil.