File Associations

G

Guest

I would like my application to be able to open a file whose extension is associated with it when the user clicks on it in File Explorer. I would like for this to work when the application is already open (I already have it working when the application is closed).

In the non-compact world, I know that Windows Explorer uses DDE to pass the filename in a DDE message to the already open application. It is also my understnading that the .NET framework does not support DDE. Does this mean that I cannot implement this feature in .NET for my Pocket PC application? Does someone know of a way to do it?

Thanks,

Bob Reader
 
P

Paul G. Tobey [eMVP]

Sorry, it *does not* use DDE (which doesn't exist in Windows CE, whether for
managed or unmanaged code). What you'd have to do is something like:

1. Create the association in the registry to trigger your application and
pass the filename on the command line.

2. Create your application so that a custom message can be sent to it,
telling it to open a new document. You'll want to use
RegisterWindowMessage() to create the message value. The easiest way I can
think of to do this is to use OpenNETCF's ApplicationEx class and to trap
the special message when it appears. When you see it, look at the string
pointed to by the lParam parameter and interpret that as the filename to be
opened.

3. When your application starts, attempt to create a named mutex. If the
creation is successful, you are the only instance running. If the creation
is unsuccessful because the mutex already exists, you are *not* the first
instance and you need to pass a custom message to the first instance. Since
you can't easily find that instance, you'll probably want to use SendMessage
and post the message to all top-level windows in the system. Set the lParam
parameter to SendMessage to a pointer to the name of the file to be opened
(you'll have to fix it in place, so that the managed environment doesn't
move it until SendMessage returns).

Given the list of things that you need to do, I wouldn't even try this in
VB.NET. Use C# and I think it should all be quite possible. Note, however,
that there is a fair amount of P/Invoking required and you really need to
know how the Windows messaging system works and how to use SendMessage, etc.

Paul T.

Bob Reader said:
I would like my application to be able to open a file whose extension is
associated with it when the user clicks on it in File Explorer. I would
like for this to work when the application is already open (I already have
it working when the application is closed).
In the non-compact world, I know that Windows Explorer uses DDE to pass
the filename in a DDE message to the already open application. It is also
my understnading that the .NET framework does not support DDE. Does this
mean that I cannot implement this feature in .NET for my Pocket PC
application? Does someone know of a way to do it?
 
G

Guest

Thanks for the info. I may give it a try. Just one question: I noticed that unlike the Windows XP operating system, the Pocket PC system refuses to open multiple instances of an application. With my application it simply appears to activate the already open instance. Would the operating system even give me a chance to implement your suggestion? At what point in the process of starting to open the second instance is the second instance forceably shut down by the operating system?

Thanks,
Bob Reader
 
P

Paul G. Tobey [eMVP]

Pocket PC does that, yes. Windows CE itself will allow you to open multiple
instances, but the PPC specification prevents that. I'm afraid that I don't
know the answer to your question and don't have a PPC device to try. You
should be able to try something relatively quickly, though, maybe playing a
sound at the top of main() or something...

Paul T.

Bob Reader said:
Thanks for the info. I may give it a try. Just one question: I noticed
that unlike the Windows XP operating system, the Pocket PC system refuses to
open multiple instances of an application. With my application it simply
appears to activate the already open instance. Would the operating system
even give me a chance to implement your suggestion? At what point in the
process of starting to open the second instance is the second instance
forceably shut down by the operating system?
 
P

pwong

Hi Bob,
Were you able to get a file to open when your application is already
opened? I'm having the same problem and this seems to be the only post
on the Internet regarding this issue.

Thanks
Peter
 
A

AshleyF

I am seeing the same behavior. With a .NET app already running on a
Pocket PC, tapping an associated file in File Explorer simply activates
the already running app without passing command line args (e.g. I get
an activate event but main() is, of course, not called and I can find
nowhere else to get the args).

Does anyone know how one is supposed to get the file path argument when
an app is activated (not launched) by a document file tap in the shell?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top