与相关的锉纹开孔有关的问题 [英] Problem with an associated fileype opening

查看:100
本文介绍了与相关的锉纹开孔有关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我已经开发了一个C#win应用程序,它可以处理某些文件类型.我已经通过installshield安装项目关联了指定的文件类型.一切正常:设置后,文件类型将与应用程序关联,并且用户可以通过双击关联的文件来运行该应用程序.另外,我已经开发了与拖放"文件兼容的应用程序,该文件效果很好.
但是:
...当我双击一个关联的文件时,该应用程序成功运行,并且我希望该文件将在应用程序中打开,但是不会自动打开任何文件.似乎一个事件必须处理这个,但是哪个事件呢?有人遇到过这个问题吗?

谢谢.
------------------------------------
谢谢两位JF2015& SAKryukov给出了答案.
让我解释更多:
我的应用程序以中间父级形式``MainForm''开始,并且将``AllowDrop''属性切换为true.

第一:拖放定义:

Hi people, I''ve developed a C# win application which works with some filetypes. I''ve associated a specified filetype through an installshield setup project. Everything is OK: After setup, the filetype becomes associated with the application and user can run the application with double-clicking an associated file. Also, I''ve developed my application compatible with "Drag & Drop" file which works nice.
But:
...When I double click an associated file, the application runs successfully, and I expect that the file will be opened in the application, but no file is opened automatically. Seems that an Event must handle this, but which Event? Have anyone faced this problem?

Thx.
------------------------------------
Thanks you two JF2015 & SAKryukov for the answer.
Let me explain more:
My application starts with a mdi-parent form ''MainForm'', with ''AllowDrop'' property switched to true.

First: Drag Drop Definition:

private void MainForm_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        e.Effect = DragDropEffects.Copy;

    }
    else
    {
        e.Effect = DragDropEffects.None;
    }
}

private void MainForm_DragDrop(object sender, DragEventArgs e)
{
    Array a = (Array)e.Data.GetData(DataFormats.FileDrop);
    string fn = a.GetValue(0).ToString();
    if (fn.IndexOfAny(new char[]{''.''}) == -1)
    {
        RadMessageBox.Show("Cannot open " + fn + ". Make sure it''s a supported file.", "Error", MessageBoxButtons.OK,RadMessageIcon.Error);
        return;
    }
    if (fn.Substring(fn.LastIndexOf(''.''), 4).ToUpper() != ".MGP")
    {
        RadMessageBox.Show("Cannot open " + fn + ". Make sure it''s a supported file.", "Error", MessageBoxButtons.OK, RadMessageIcon.Error);
        return;
    }
    OpenFile(fn);
}

private bool OpenFile(string fn)
{
    //Some Code to open the file
}



成功将文件拖放到mainform中后,它会以mdichild的形式打开.

问题是双击该文件时如何以mdichild格式打开该文件?



After a successful drag-drop a file in mainform, it''s opened as a mdichild.

The question is How could I open this file as an mdichild when I double-click it?

推荐答案

我怀疑您未处理命令行. > (对于健壮的命令行实用程序,您可能需要看一下我的工作:基于枚举的命令行实用程序 [ ^ ].)

如果这不是答案,请原谅我:您没有完整说明问题.
这是我所怀疑的原因,这是:您将拖放功能开发为某些控制功能,当您的用户界面已经显示时,该功能就可以使用.您没有确切解释,因为命令行管理程序还具有其拖放功能.您可以在安装中注册应用程序.缺少的链接是什么?命令行,我不知道还有什么.你从没说过要处理它.

不涉及任何事件,这比这更简单.


OP确认后,我知道问题出在命令行.
考虑该应用程序的入口程序集在文件application.exe中具有一个主(启动)模块,并且系统注册表具有文件扩展名注册记录,这些记录显示系统Shell使用该应用程序,并具有该文件的完整路径名. .假设这是扩展名".myext".在这种情况下,当使用命令行管理程序在任何文件管理器上单击文件(例如"mydata.myext")时,它将使用以下命令行创建进程:

I suspect you don''t process command line.
(for a robust command line utility, you may want to see my work: Enumeration-based Command Line Utility[^].)

Please forgive me if this is not an answer: you did not explain your problem in full.
Here is what I suspected and why: you develop drag-and-drop as some control feature, which works when your UI is already shown. You did not explain this exactly, because the Shell also has its drag-and-drop functionality. You put registration of your application in your installation. What''s the missing link? Command line, I don''t know what else. You never said you processed it.

No events involved, this is simpler than that.


After OP confirmation, I know the problem is command line.
Consider the application''s entry assembly has a main (start-up) module in the file application.exe, and the system Registry has the file extension registration records which show system Shell to use this application, with full path name of this file. Let''s assume this is an extension ".myext". In this case, when a file, for example "mydata.myext" is clicked on any file manager using the Shell, it created a process using the following command line:

application.exe mydata.myext

(完整路径名为оfapplication.exe.)

在运行时,此命令行将作为参数传递给应用程序入口点,例如函数main,也可以使用属性System.Environment.CommandLine进行检索.应用程序应负责查找文件(如果参数是文件,例如您的情况)并进行处理.

如果应用程序已经在运行,则更加困难,并且您需要在第一个实例中加载文件.这都是关于单实例行为的,只能由应用程序本身实现.对所需机器的解释可能只是一篇文章,可能是一篇大文章.这是示意图说明:

1)您的应用程序#1的实例正在运行;
2)单击带有注册扩展名的文件-实例2已启动;
3)#2实例检测到实例#1正在运行;
4)#2实例将其命令行数据发送到实例#1;
5)传输命令行数据时,实例2自身终止;
6)传输命令行数据时,实例1执行命令行处理(查找并加载文件等)
在.NET中,实例之间进行通讯的最佳方式是远程处理(基于命名管道,因为实例始终位于同一台计算机上.最好使用相同的方法来检测已在运行的实例:如果实例#1不接受连接,表示它没有运行.

就是这样,一个完整的答案.如果您需要更多详细信息,请提出具体问题,否则在新页面上单独提出一个问题.

祝你好运.

—SA

(with full path name оf application.exe.)

During run-time, this command line will be passed as a parameter to applications entry point, such as function main, it also can be retrieved using the property System.Environment.CommandLine. The application should be responsible for finding the file (if a parameter is a file, like in your case) and processing it.

Much more difficult case if the application is already running, and you need to load a file in first instance. This is all about single-instance behavior, which can only be implemented by the application itself. The explanation of the required machinery could be a matter of a while article, may be a big article. Here is the schematic description:

1) Instance of your application #1 is running;
2) You click in your file with registered extension — instance #2 is started;
3) instance #2 detected that instance #1 is running;
4) instance #2 sends it command line data to instance #1;
5) when command line data is transmitted, instance #2 terminate itself;
6) when command line data is transmitted, instance #1 peforms processing of the command line (locate and load the file(s), etc.)
The best way to communicate between instances in .NET is remoting (based on named pipes, because the instances are always on the same computer. The detection of the already running instance is best implemented using the same thing: if instance #1 does not accept connection, it means it is not running.

That''s it, a complete answer. If you need more detail, please ask concrete questions, otherwise formulate a separate question on a new page.

Good luck.

—SA


这篇关于与相关的锉纹开孔有关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆