Solved

wake up the tray

Posted on 1998-12-12
27
250 Views
Last Modified: 2013-12-03
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
Comment
Question by:nyoman
  • 8
  • 6
  • 6
  • +4
27 Comments
 

Expert Comment

by:plsbctv
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 
LVL 2

Expert Comment

by:trillo
Comment Utility
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
 
LVL 2

Expert Comment

by:trillo
Comment Utility
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
 
LVL 27

Expert Comment

by:BigRat
Comment Utility
May I ask for what purpose? Because very often there is an alternative.
0
 
LVL 27

Expert Comment

by:BigRat
Comment Utility
May I ask for what purpose? Because very often there is an alternative.
0
 
LVL 1

Expert Comment

by:dsch
Comment Utility
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
 
LVL 1

Expert Comment

by:dsch
Comment Utility
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
 
LVL 3

Expert Comment

by:BudVVeezer
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 

Author Comment

by:nyoman
Comment Utility
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
 
LVL 1

Expert Comment

by:dsch
Comment Utility
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
 

Author Comment

by:nyoman
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:trillo
Comment Utility
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
 

Author Comment

by:nyoman
Comment Utility
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
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 

Author Comment

by:nyoman
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
That's nice...  :-)
0
 
LVL 1

Expert Comment

by:dsch
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 
LVL 1

Expert Comment

by:dsch
Comment Utility
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
 

Author Comment

by:nyoman
Comment Utility
I final comment what exactly is class "#32770": and will this class be the same on all machines
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 

Author Comment

by:nyoman
Comment Utility
Thankyou, please collect your points
0
 
LVL 1

Expert Comment

by:dsch
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Thanx! That helped...   :-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now