开发者

How do programs handle file "opened with..." them?

I am wondering if someone could point me in the right direction. You know how for example, in most IDEs, if you open a source file with "open with", it runs the program and opens it up? and then if you open another one, it opens it in a new tab in the same process?

My 开发者_开发问答question is NOT how to add a program to the shell commands, but rather:

  1. How would a C# application "receive" a PDF file for example?

  2. How would the application open the file in the same process when another file is run with it (not having to instances of the program)?


When the second program instance starts up, before loading any interface components, it checks to see if another program instance is already running. If so, it communicates to it in some fashion (program specific: this can be sockets, inter process interrupts, shared memory, etc..) that it should open this new file.

After communicating this to the first instance, the second program instance will just terminate since it's no longer needed.


Your program would have to be able to talk to other instances of itself, and say "hey, I'm already open, what are you trying to do, let me do it for you."


Here is a nicely detailed post that explains the proper implementation:

http://www.iridescence.no/post/CreatingaSingleInstanceApplicationinC.aspx

This thread contains a discussion and sample for handling the command line arguments (this is how files are "passed to" your application): http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic62109.aspx


Microsoft programs usually have a ddeexec key in the shell configuration; this will cause the shell to send a DDE command to the already running app, if it exists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜