Sorry, we found 0 results. Please try another query.
Showing max 10 of results

Windows 7: Open a new Form from the Jumplist

With the Windows API Code Pack, Microsoft released a really cool managed wrapper for most of the new Windows 7 features. See here for more details and download.

One thing you can do is to create a .NET app with Jumplist support. Jumplists are these cool menus appearing on right click on an icon in the task bar:

image

But there is something wrong with the jumplist: It can only launch new apps! The demo solution for the Code Pack launches notepad and some other things, but there is no word about how to open the same app but with a new form.

So here is my solution, which is not very nice, but it works like a charm.

Scencario:
AppInstance1 is running –> click on a jumplist item starts a new instance –> appInstance2 now knows, that this is the second instance, so appInstance2 calls appInstance1 through remoting (IPC) and terminates–> appInstance1 receives the remoting call und execute something.

Ok, how to implement this?

First of all, create a new Windows Forms app and go to the Program.cs file. Within this class create a new class which works as your service for the remoting part and also a static reference to your form:

static class Program
    {
        public class RemotingService : MarshalByRefObject
        {
            public RemotingService() { }

            public void ShowText(string text)
            {
                Program.formMain.SetTextToTextBox(text);
            }
        }

        internal static Form1 formMain;

Then you will need some remoting code for the communication. I created two methods “InitRemoting” and “CallRunningInstance”. InitRemoting is called from the main method if this is the first instance. CallRunningInstance is called if the main method detects, that this is the second instance.

For the detection I use a system wide mutex.

I hope you get the idea. Because there are some more lines of code I created a demo project for you to download:

 Download the entire working demo solution here.

 

Leave a comment




Loading...