Nadav and the wonders of the web


Posts Tagged ‘wm6’

How To: Bring your program to the foreground on WM6

Sunday, January 13th, 2008

This topic is one I have been spending some time studying.
How do you get your program to the foreground when a certain event accurse ?

The answer is quite simple actually, you just need to call a UI component. like:

MessageBox.Show("Show Me");

And it will show the top most form in your application. Another thing you can do is call a form with Show().

Now, for a little bonus I have for you the…

How to send it back to the background!

What we need to do here is to call Hide() on all the visible forms in our application, this will essentially cause all our UI to go to the background and will bring back the last active application.

A little hint, you might want to use what you learned, and combine it with the previous post ;].

Nadav

How to: Using the State and Notification broker on WM6

Sunday, January 13th, 2008

Sometimes we want to be notified of different events that happen in the operating system, even when we are not “looking”. the State and Notification broker is built especially for this.

I will give an example of how to be notified when the current active application changes and how to handle it.

First create the correct SystemState member:

SystemState _activeProgram = new SystemState(SystemProperty.ActiveApplication);

Now set the event handler on your program initiation:

_activeProgram.Changed += new ChangeEventHandler(_activeProgram_Changed);

Now handle it ;]:

void _activeProgram_Changed(object sender, ChangeEventArgs args)
{
    MessageBox.Show(((string)args.NewValue));
}

You would want to know a few interesting things:

  1. The NewValue string is formatted in this way:

    PreviousActiveProgramNameCurrentActiveProgramName

    So, you might want to use StartsWith\EndsWith methods in order to check them ;].

  2. It seams that every UI involved action(MessageBox, Form, etc.) causes your own application to come back from the background(if it was there) and show itself ;]. while other non-UI related actions does not cause this. This only a major “feeling” i got from my little workings with this so far, i checked this with a Thread.Sleep that did not cause my application to come to the foreground.

Hope this helps.

Nadav

Jajah is the VoIP player that brought you web-activated telephony.