关联exe名称以及文件名和lpVerb =使用ShellExecuteEx进行打印 [英] Associate exe name along with the file name and lpVerb = Print with ShellExecuteEx

查看:149
本文介绍了关联exe名称以及文件名和lpVerb =使用ShellExecuteEx进行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我们有一个VC ++应用程序,它以指定的格式显示文档内容.并打印相同.此应用程序的文档类型是特殊的.文件扩展名为.SCE.让它成为app2.

我正在尝试在另一个应用程序中调用此exe的打印功能.设为app1.
为此,我正在尝试下面的代码片段

Hi All,

We have a VC++ application that displays document contents in a specified format. And prints the same. The document type of this applcation is a special one. That has file extension .SCE. Let this be app2.

I am trying to invoke the print functionality of this exe inside another application. Let this be app1.
For that I am trying the below code snippet

SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = _T("Print");
ShExecInfo.lpFile = FileName;  // file name to be printed
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = ExeDir;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
BOOL bProc = ShellExecuteEx(&ShExecInfo);
if(ShExecInfo.hProcess !=NULL)
{
 ::WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
 ::CloseHandle(ShExecInfo.hProcess);
}


可执行文件存在于共享驱动器中.我正在尝试从不知道我的打印应用程序(app2)任何详细信息的机器上访问这些文件.

当我第一次尝试从app1-调用打印功能时,将显示打开方式"对话框.

这是因为文件类型与应用程序不相关.此错误仅在第一次出现.要通过
调用app2进行打印预览 shellexecute().从现在开始,打印功能开始起作用.

我希望打印功能第一次成功.有什么方法可以将exe以及文件名和PrintDDE关联起来.在此先感谢

谢谢,
Sengottian E


The executables are present in shared drive. I m trying to access those from a machine that doesnt knows any details of my print application(app2).

When I tried to invoke the print functionality for the first time from app1- The "Open With" dialog gets displayed .

This is because the file type is not associated with the application.This error occurs only for the first time. For print preview i m invoking app2 with
shellexecute(). From now on print functionality starts works.

I want print functionality to be succesful for the first time. Is there any means I can associate exe along with the file name and PrintDDE. Thanks in advance

Thanks,
Sengottian E

推荐答案

注册表项的名称取决于您的文件扩展名.对于* .txt,键名称为:

HKEY_CLASSES_ROOT \ .txt

该键的值为txtfile,它指示处理程序的内容在该键中:

HKEY_CLASSES_ROOT \ txtfile

看一下shell子键,您将看到各种操作,打开,打印等键:

HKEY_CLASSES_ROOT \ txtfile \ shell
HKEY_CLASSES_ROOT \ txtfile \ shell \ open
HKEY_CLASSES_ROOT \ txtfile \ shell \ open \ command
HKEY_CLASSES_ROOT \ txtfile \ shell \ print
HKEY_CLASSES_ROOT \ txtfile \ shell \ print \ command
HKEY_CLASSES_ROOT \ txtfile \ shell \ printto
HKEY_CLASSES_ROOT \ txtfile \ shell \ printto \ command

HKEY_CLASSES_ROOT \ txtfile \ shell \ print \ command的值类似于:

%SystemRoot%\ system32 \ NOTEPAD.EXE/p%1

这是打印的命令行,可以使用环境变量,并且%1是选择的第一个文件名.

因此,如果扩展名为* .bob,则应该可以添加注册表项:

HKEY_CLASSES_ROOT \ .bob

然后将密钥设置为myfilehandler,然后创建密钥:

HKEY_CLASSES_ROOT \ myfilehandler \ shell \ print \ command

的值为:

C:\ the \ path \至\ my \ app.exe/myprint命令行开关%1

应当这样做.
The name of teh registry key depends on your file extension. For *.txt the key name is:

HKEY_CLASSES_ROOT\.txt

The value of that key is txtfile which indicates the meat of the handler is in this key:

HKEY_CLASSES_ROOT\txtfile

Taking a look at the shell sub key you will see keys for various actions, open, print, etc:

HKEY_CLASSES_ROOT\txtfile\shell
HKEY_CLASSES_ROOT\txtfile\shell\open
HKEY_CLASSES_ROOT\txtfile\shell\open\command
HKEY_CLASSES_ROOT\txtfile\shell\print
HKEY_CLASSES_ROOT\txtfile\shell\print\command
HKEY_CLASSES_ROOT\txtfile\shell\printto
HKEY_CLASSES_ROOT\txtfile\shell\printto\command

The value of the HKEY_CLASSES_ROOT\txtfile\shell\print\command is something like:

%SystemRoot%\system32\NOTEPAD.EXE /p %1

This is the command line for printing, environment variables can be used, and %1 is the first file name selected.

So if your extension is *.bob you should be able to add a registry key:

HKEY_CLASSES_ROOT\.bob

Then set the key to myfilehandler then create the key:

HKEY_CLASSES_ROOT\myfilehandler \shell\print\command

with the value of:

C:\the\path\to\my\app.exe /myprintcommandlineswitch %1

That should do it.


将特定文件类型与特定应用程序相关联,就像Blake所说的那样,是通过注册表手动完成的.

也可以通过编程和 [ ^ ]线程有一些示例.我本来会更具体,但是您不说您需要使用哪个操作系统.
Associating a particular file type with a particular application is, as Blake said, done via the registry manually.

It can also be done programatically and this[^] thread on MSDN has some examples. I would have been more specific but you do not say which OS you need it for.


这篇关于关联exe名称以及文件名和lpVerb =使用ShellExecuteEx进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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