小编Zav*_*ael的帖子

打开带有相关应用程序的文

我想请求帮助从c#app打开一个带有相关应用程序的文件.我试过这个:

      ProcessStartInfo pi = new ProcessStartInfo(file);
      pi.Arguments = Path.GetFileName(file);
      pi.UseShellExecute = true;
      pi.WorkingDirectory = Path.GetDirectoryName(file);
      pi.FileName = file;
      pi.Verb = "OPEN";
      Process.Start(pi);
Run Code Online (Sandbox Code Playgroud)

或这个:

      Process.Start(file);
Run Code Online (Sandbox Code Playgroud)

其中file两个示例中的字符串表示尝试打开的文件的完整路径.现在,除了使用ACDSee应用程序(jpg)图像外,一切运行良好.Irfanview协会运作良好,MS办公室文件也是如此.试图打开使用ACDSee相关联的JPG图片后,它只是运行在通知区域中的ACDSEE,不打开该文件.

我发现,在注册表CLASSES_ROOT中为*.jpg图像,有一个ACDSee.JPG值作为关联应用程序,并且在此键下有一个shell- > Open-> Command命令路径:

"C:\Program Files\ACD Systems\ACDSee\ACDSee.exe" /dde
Run Code Online (Sandbox Code Playgroud)

我觉得这个奇怪/dde的原因,为什么我无法打开文件.我意识到在同一个reg key shell-> Open中有一些DDEExec带有值的键入口[open("%1")]

对于Irfan视图或其他已检查的应用程序,没有ddeexec,只有正常的命令

"C:\Program Files (x86)\IrfanView\i_view32.exe" "%1"
Run Code Online (Sandbox Code Playgroud)

可以在交换%1替换文件名后从命令行运行,但我无法从命令行中的acdsee条目运行命令:(

所以我的问题是,我如何设置ProcessStartInfo对象以确保它将运行所有文件,就像它在资源管理器中通过doubleclick,标准和这些DDEExec?还有其他类似的东西DDEExec我应该知道吗?谢谢,对不起我的EN

c# process file-association

58
推荐指数
3
解决办法
8万
查看次数

在Java中使用带有WIA和com4j的COM对象

我是一个新手,我想问你是否可以推荐我一些文章,例子等开始与java应用程序中的扫描仪进行通信
我正在开发一个模块,应该与直接连接或在本地网络中连接的不同扫描仪进行通信.我希望WIA能够和com4j一起开始..
感谢大家的任何建议:)

编辑:我在这个Com4j教程中找到了一些信息,我需要从ocx文件生成一些java类型定义.
如果我理解它,这些生成的类将是我的客户端使用com4j获取扫描程序.但是我用的是什么ocx/dll文件呢?
有人有想法吗?

更新1:所以我设法让库生成包装类,它是wiaaut.dll(Windows Image Acquisition Automation Library)然后通过ClassFactory我创建了一个DeviceManager实例,但是它没有设备.. .
如何让deviceManager在本地网络上查看扫描仪?

更新2:所以我发现,我的HP LaserJet 2840无法通过win7 64位网络扫描...现在这个问题已经回答了,我应该自己发布答案并将其设置为接受,或者关闭此Q其他方式?谢谢

java wia com4j

4
推荐指数
1
解决办法
2994
查看次数

字典作为线程安全的变量

我有一个类(单例),它包含一个静态字典

private static Dictionary<string, RepositoryServiceProvider> repositoryServices = null;
Run Code Online (Sandbox Code Playgroud)

在这个类的实例中我填充字典(可以从多个线程发生).起初我只是

        RepositoryServiceProvider service = null; 
        repositoryServices.TryGetValue(this.Server.Name, out service);
        if (service == null) {
          service = new RepositoryServiceProvider(this.Server);
          repositoryServices.Add(this.Server.Name, service);  
        }
Run Code Online (Sandbox Code Playgroud)

然后我有一些例外,因为Item已添加,所以我将其更改为:

        RepositoryServiceProvider service = null;    
        repositoryServices.TryGetValue(this.Server.Name, out service);
        if (service == null) {
          lock (padlock) {
            repositoryServices.TryGetValue(this.Server.Name, out service);
            if (service == null) {
              service = new RepositoryServiceProvider(this.Server);
              repositoryServices.Add(this.Server.Name, service);  
            }
          }
        }
Run Code Online (Sandbox Code Playgroud)

和挂锁在课堂上:

private static readonly object padlock = new object();
Run Code Online (Sandbox Code Playgroud)

这个线程安全吗?还是过于复杂?或者我应该使用ConcurentDictionary

c# static dictionary thread-safety

3
推荐指数
1
解决办法
3760
查看次数

从通用方法返回对象作为接口

我有一个接口InterfaceBase和一些从它派生的接口Interface1, Interface2.接下来我有实现InterfaceX接口的类,而不是基类.

现在,我是仿制药的初学者,这样的许多新方法在我的头脑中变得非常混乱:(.我想创建工厂(静态类),我称之为类似的东西

Interface1 concrete1 = Factory.Get<Interface1>();
Run Code Online (Sandbox Code Playgroud)

这是我的(示例)工厂实现,不起作用:

  public static class Factory {

    public static T Get<T>() where T: InterfaceBase{

      Type type = typeof(T);

      //return new Concrete1() as T; // type T cannot be used with the as
      //return new Concrete1() as type; //type not found
      //return new Concrete1(); // cannot implicitly convert
      //return new Concrete1() as InterfaceBase; //cannot convert IBase to T
      //return new Concrete1() as Interface1; //cannot convert Interface1 to T
    } …
Run Code Online (Sandbox Code Playgroud)

c# architecture design-patterns interface factory-method

2
推荐指数
1
解决办法
2991
查看次数

自定义标签不显示文本字符串

我需要制作自己的标签以保留一些值,这与显示给用户的值不同

public class LabelBean : Label {
  private string value;

  public LabelBean(string text = "", string value = ""): base() {
    base.Text = text;
    this.value = value;
  }

  public string Value {
    get { return value; }
    set { this.value = value; }
  }
}
Run Code Online (Sandbox Code Playgroud)

但现在在表单构造函数中的id我用我的类替换控件

this.lbAttributeType = new LabelBean();
Run Code Online (Sandbox Code Playgroud)

然后在创建表单之后,但在显示之前,我通过setter设置文本

(this.lbAttributeType as LabelBean).Value = value;
this.lbAttributeType.Text = Transform(value);
Run Code Online (Sandbox Code Playgroud)

但在形式上我总是"label1"文本......它有什么问题?谢谢

UPDATE

我在这里添加了解决方案,以便更容易找到:

public class MyLabel : Label {

    public MyLabel()
      : base() {
    }

    public string Value {
      set { …
Run Code Online (Sandbox Code Playgroud)

c# label winforms

1
推荐指数
2
解决办法
3487
查看次数