For Programmers: Free Programming Magazines  


Home > Archive > Smartphone Developer Forum > January 2006 > How do I monitor for the presence of a particuar window?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How do I monitor for the presence of a particuar window?
Joseph Geretz

2006-01-15, 7:16 pm

As I mentioned above on a previous thread, I'm getting pretty sick and tired
of the lame dialog whch pops up at the most inconvenient times to inform me
that my speed-dial, which was broken has now been repaired (hooray -
yippeeeee!). Here's what I propose to do to address this:

1. Write a program which launches on Startup
2. This program runs in the background, waiting for the presence of a
specific window (the speed-dial repair dialog).
3. When this dialog is detected, the monitor program sends the 'OK' message
to the window to dispose the dialog.

If this is impossible, tell me now. Otherwise, if you can help me with three
specific operations, your help will be much appreciated.

I'll be using Visual Studio 2005 / C# to write this app. Framework
operations will be more convenient, but I'm quite capable of using the API
functions if necessary.

1. How do I launch a process on Startup?
2. How can I monitor for the presence of a specific window?
3. How can I send the window a message to close it?

Thanks immensely for any help which you can provide!

- Joe Geretz -


Scott Yost [MSFT]

2006-01-16, 7:11 pm

1) You can put it in the startup folder.
2) You can poll the window list using EnumWindows and look for a window with
the title that matches.This is sort of slow so you should consider carefully
the interval at which you do this. (there might be a better way for this -
it's not my area of expertise)
3) SendMessage with WM_OK should do the trick here. You will probably have
to p/invoke it. It's not a difficult p/invoke.

--
Scott Yost
Software Development Engineer/Test
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.

"Joseph Geretz" <jgeretz@nospam.com> wrote in message
news:O2LshofGGHA.2040@TK2MSFTNGP14.phx.gbl...
> As I mentioned above on a previous thread, I'm getting pretty sick and
> tired of the lame dialog whch pops up at the most inconvenient times to
> inform me that my speed-dial, which was broken has now been repaired
> (hooray - yippeeeee!). Here's what I propose to do to address this:
>
> 1. Write a program which launches on Startup
> 2. This program runs in the background, waiting for the presence of a
> specific window (the speed-dial repair dialog).
> 3. When this dialog is detected, the monitor program sends the 'OK'
> message to the window to dispose the dialog.
>
> If this is impossible, tell me now. Otherwise, if you can help me with
> three specific operations, your help will be much appreciated.
>
> I'll be using Visual Studio 2005 / C# to write this app. Framework
> operations will be more convenient, but I'm quite capable of using the API
> functions if necessary.
>
> 1. How do I launch a process on Startup?
> 2. How can I monitor for the presence of a specific window?
> 3. How can I send the window a message to close it?
>
> Thanks immensely for any help which you can provide!
>
> - Joe Geretz -
>


Joseph Geretz

2006-01-16, 7:11 pm

Thanks Scott,

This is enough to get me started.

> 2) You can poll the window list using EnumWindows and look for a window
> with the title that matches.This is sort of slow so you should consider
> carefully the interval at which you do this. (there might be a better way
> for this - it's not my area of expertise)


As an optimization, how about only looking at the foreground window? When
this dialog comes up it is modal to the foreground so I really am only
interested in the foreground window. Is there a way to do this? I guess this
should be substantially quicker than enumerating all the windows.

Also, perhaps I can hook into some message pipeline to be informed when a
new window is created? That way my process would only grab processor time in
the event that a new window is created. Otherwise, it could remain idle in
the background. I've done enough hooking / subclassing using VB6 in a Win32
environment but I've never attempted this with SmartPhone. Is this possible
on this platform?

Thanks for your help!

- Joe Geretz -

"Scott Yost [MSFT]" <scyost@online.microsoft.com> wrote in message
news:%23ZUymTtGGHA.3120@TK2MSFTNGP10.phx.gbl...
> 1) You can put it in the startup folder.
> 2) You can poll the window list using EnumWindows and look for a window
> with the title that matches.This is sort of slow so you should consider
> carefully the interval at which you do this. (there might be a better way
> for this - it's not my area of expertise)
> 3) SendMessage with WM_OK should do the trick here. You will probably have
> to p/invoke it. It's not a difficult p/invoke.
>
> --
> Scott Yost
> Software Development Engineer/Test
> Microsoft Corp.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "Joseph Geretz" <jgeretz@nospam.com> wrote in message
> news:O2LshofGGHA.2040@TK2MSFTNGP14.phx.gbl...
>



Danny Baumann

2006-01-17, 8:03 am

Hi,

> As an optimization, how about only looking at the foreground window? When
> this dialog comes up it is modal to the foreground so I really am only
> interested in the foreground window. Is there a way to do this? I guess this
> should be substantially quicker than enumerating all the windows.


GetForegroundWindow() should be your friend.

> Also, perhaps I can hook into some message pipeline to be informed when a
> new window is created? That way my process would only grab processor time in
> the event that a new window is created. Otherwise, it could remain idle in
> the background. I've done enough hooking / subclassing using VB6 in a Win32
> environment but I've never attempted this with SmartPhone. Is this possible
> on this platform?


Not to my knowledge. The only hook possibility on the Smartphone
platform I am aware of is the low level keyboard hook.

Regards,

Danny
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com