• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

wake up the tray

Win32 API C language question:

I wish to have my program when started to inspect the programs that lie idle in the tray, and then if the target exists there, invoke that program as would a users double click.

Can anybody help with some brief step by step code example .
 
0
nyoman
Asked:
nyoman
  • 8
  • 6
  • 6
  • +4
1 Solution
 
plsbctvCommented:
Is this looking for another instance of your program, or looking for something else entirely? If the latter, how would you identify the other program?

    ++PLS
0
 
MadshiCommented:
I guess you mean the little icons next to the clock?
You can't enumerate the processes that display these icons. You COULD simulate mouse double clicks on the tray area, but you won't be able to ask windows at what positions you have to click and how many icons are displayed.
What you COULD do, is start your program BEFORE the other processes are started (e.g. as a service program). Then you could inject every newly started process with a little dll that hooks all API calls that have to do with these icons. But I guess, that is NOT the way you like it to do...  :-(

Regards, Madshi.
0
 
trilloCommented:
Looking for a program in the SysTray is not the correct way (and I don't know if it's possible). You should look at a previous instance of your program, that's elegant, more robust, easier and faster.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
trilloCommented:
Looking for a program in the SysTray is not the correct way (and I don't know if it's possible). You should look at a previous instance of your program, that's elegant, more robust, easier and faster.
0
 
BigRatCommented:
May I ask for what purpose? Because very often there is an alternative.
0
 
BigRatCommented:
May I ask for what purpose? Because very often there is an alternative.
0
 
dschCommented:
trillo
In win32 Can you look for a previous instance easily. In the help it says:
HINSTANCE hPrevInstance;

Description

Contains the handle of the previously executing instance of the Windows application. If hPrevInstance is 0, there was no previously executing instance when this instance began execution. Under Win32, this value is always 0.

As this question is win32 does this mean "hPrevInstance" is useless? If so would the only other way to do this be FindWindow()?
Regards
dsch
0
 
dschCommented:
trillo
In win32 Can you look for a previous instance easily. In the help it says:
HINSTANCE hPrevInstance;

Description

Contains the handle of the previously executing instance of the Windows application. If hPrevInstance is 0, there was no previously executing instance when this instance began execution. Under Win32, this value is always 0.

As this question is win32 does this mean "hPrevInstance" is useless? If so would the only other way to do this be FindWindow()?
Regards
dsch
0
 
BudVVeezerCommented:
Yes, the hPrevInst is useless.  I use FindWindow.  YOu already know the class name, and the window name, so it's not a big pain.  It works...

~Aaron
0
 
MadshiCommented:
Hey girls,

I think nyoman doesn't want to look at a previous started instance of his own application. I think he wants to show ALL the context menus and popup windows of the processes that are shown in the tray area.
But nyoman, the question is, for what do you need it? As BigRat (wow, what a name) said, perhaps you can achieve what you want by other means.

Regards, Madshi.
0
 
nyomanAuthor Commented:
Ok this is what I want to do, there is a program called ICQ from mirabilis - Heard of it!!! it sits in the tray as an icon. Now I am not talking about their NetDetect agent, I am talking about their main program proper.

Now my program when launched wants to find out if ICQ is in the tray and if so wants to invoke it just like what would happen if I double clicked on the tray icon.

Thats it!!!!!


0
 
dschCommented:
OK, I looked in wintop and noticed that When "NetDetect Agent" is active ICQDETECT.EXE is running.
When connected to a DUN connection, this prcess closes just after it launches ICQ.EXE. When the DUN finishes ICQ.EXE launches ICQDETECT.EXE before closing.
What you wnat to do is use CreateProcess() to attempt to launch ICQ.EXE when you know it is running. A warning box will first of all come up saying something like "ICQ is already running, double click on the icon in the system tray" but also has a nice check box for "do not show this message again", click it, and when you attempt to start ICQ.EXE it will display your connection list.
Hope this answers your question :)
Dsch
0
 
nyomanAuthor Commented:
dsch,
You have gone part way to anwsering my question, I know how to use CreateProcess() but my question is bit more specific, how do I detect the handles of programs in the tray and then invoke them ??????
0
 
trilloCommented:
That's not the best solution, because it works only with ICQ and some other programs that don't support multiple instances... I suggest you to use the FindWindow function and if it returns that the window exists the you activate it.

Trillo
0
 
nyomanAuthor Commented:
OK trillo if you can give me some very very brief code to try this I will award you the points if successful.
thankx
0
 
MadshiCommented:
nyoman,

FindWindow won't work, because the title of the ICQ window is your ICQ number (so if you would look for that, your program would only work on your computer) and the class in not unique. So the task is a little bit more complicated. If you have Delphi 4 you can download the unit "enumStuff.pas" from my homepage "http://beam.to/madshi" and then use this function:

function ActivateICQ : boolean;
var pl    : TProcessList;
    wl    : TWindowList;
    i1,i2 : integer;
begin
  result:=false;
  pl:=GetProcessList; wl:=nil;
  for i1:=0 to high(pl) do
    if Pos('\icq.exe',lowerCase(pl[i1].name))>0 then begin
      wl:=GetWindowList(pl[i1].pid);
      for i2:=0 to high(wl) do
        if wl[i2].className='#32770' then begin
          result:=true;
          ShowWindow(wl[i2].window,SW_SHOW);
          exit;
        end;
      break;
    end;
end;

If you don't have Delphi 4, say something and I will see if I can convert the sources for Delphi 2/3.

If the program needs to run only on your computer, you don't need the enumStuff unit. Then you can use something like that:

function ActivateICQ;
var h1 : HWND;
begin
  h1:=FindWindow('#32770','XXXXXXXXX');  // Where XXXXXXXXX is your ICQ number
  result:=h1<>0;
  if result then ShowWindow(h1,SW_SHOW);
end;

Regards, Madshi.
0
 
MadshiCommented:
Hmmm. I see, I'm in the "windows programming forum". Most guys here use C(++). So if don't have Delphi and you can't convert my sources to C(++) yourself, then you'll have to reject my answer.  :-((
However, you should be able to learn from it, how to solve your problem...

Regards... Madshi.
0
 
nyomanAuthor Commented:
Madshi, it has been many a long year since I have used Pascal but I have converted what you have suggested in plain old C and it works,

thanx nyoman
0
 
MadshiCommented:
That's nice...  :-)
0
 
dschCommented:
Good answer, but if you set the second param to NULL then it will react to ANY ICQ UIN number. I have modified Madshi's answer as shown below: I have tesed it using C++, it's OK

HWND h1 =NULL;
h1=FindWindow("#32770",NULL);  //
if (h1)
{
ShowWindow(h1,SW_SHOW);
}
Bye for now
Dsch
0
 
MadshiCommented:
Sorry Dsch,

I've looked at all the windows that I've currently open. And I found the following 5 (!!!) windows with the class "#32770":

(1) ICQ
(2) Babylon Translator
(3) System Information
(4) Connected with T-Online
(5) Outlook Express

So, as I said in my answer, the class "#32770" in NOT UNIQUE. That means other programs use this class string, too. So your sources will sometimes show the ICQ window, sometimes another window.

Regards, Madshi.
0
 
dschCommented:
Yep Madshi, Your right, I've just looked at it in winsight, I found even more!
I've learnt quite a bit for paricipating here, thanks
Regards to you all
dsch
0
 
nyomanAuthor Commented:
I final comment what exactly is class "#32770": and will this class be the same on all machines
0
 
MadshiCommented:
It was the same on my computer and on Dsch's computer. So it will be the same on all machines. I guess it's no real class NAME but somehow a combination of flags. The "System Information" program I use writes this "#32770 (Dialog)" as class string. So I guess, it's the flag combination for a dialog box.

Regards, Madshi.
0
 
nyomanAuthor Commented:
Thankyou, please collect your points
0
 
dschCommented:
Hi, done a bit of homework, #32770 IS a system class for a diaolog box, Check out these sites from Microsoft.
Regards
dsch

http://www.microsoft.com/win32dev/ui/classy32.htm
http://premium.microsoft.com/msdn/library/sdkdoc/winui/winclass_1kfn.htm

0
 
MadshiCommented:
Thanx! That helped...   :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 6
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now