Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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);
}

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
Posted
Updated 28-Feb-11 4:43am
v2

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.
 
Share this answer
 
Comments
sengottian 3-Mar-11 3:10am    
Hi,
Thanks for your suggestions. These entries are already there in the problamatic machine. I am trying a code snippet as below as a solution

CRegKey keyRoot;
LONG lRes = keyRoot.Open(HKEY_CLASSES_ROOT, _T(".sce"), KEY_READ);
if (lRes != ERROR_SUCCESS)
ShellExecute(..., ModuleName, _T("/register"), ExeDir, SW_SHOWMINIMIZED);
else
keyRoot.Close();

The problamatic machine has this(the above) entry too. So my registeration of application is skipped and the same problem persists.
I am using ::OnDDECommand(LPTSTR lpszCommand)in my print application (app2) so that print fuctionality of this app2 is available from app1. Please referto the SHELLEXECUTEINFO structure from previous thread.
Regards,
Sengottian E
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900