Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

wake up the tray

Posted on 1998-12-12
27
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 6
  • +4
27 Comments
 

Expert Comment

by:plsbctv
ID: 1417159
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
ID: 1417160
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
ID: 1417161
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 2

Expert Comment

by:trillo
ID: 1417162
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
ID: 1417163
May I ask for what purpose? Because very often there is an alternative.
0
 
LVL 27

Expert Comment

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

Expert Comment

by:dsch
ID: 1417165
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
ID: 1417166
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
ID: 1417167
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
ID: 1417168
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
ID: 1417169
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
ID: 1417170
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
ID: 1417171
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
 
LVL 2

Expert Comment

by:trillo
ID: 1417172
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
ID: 1417173
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 400 total points
ID: 1417174
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
ID: 1417175
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
ID: 1417176
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
ID: 1417177
That's nice...  :-)
0
 
LVL 1

Expert Comment

by:dsch
ID: 1417178
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
ID: 1417179
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
ID: 1417180
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
ID: 1417181
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
ID: 1417182
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
ID: 1417183
Thankyou, please collect your points
0
 
LVL 1

Expert Comment

by:dsch
ID: 1417184
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
ID: 1417185
Thanx! That helped...   :-)
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

610 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