LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Receive a file from the 'send to' menu in Windows Explorer

I created a little LabWindows program to decode an encoded file. The only thing it does is reading data from a file and writing a conversion of this data to another file. To receive the input file, I am now using the FileSelectPopup function. Because this little conversion program is used frequently, I'm trying to get the input file in another way: I put the executable (or a shortcut) in the 'Send To' menu, which appears if you right-click a file in the Windows Explorer. Is there any way my Labwindows executable can get the filename of the right-clicked file, so the FileSelectPopup Window is not needed anymore.
Note: I still would like the FileSelectPopup function to be available when the user runs by executable by clicking the icon on the desktop...
 
Thanks for all help,
Wim
0 Kudos
Message 1 of 11
(4,664 Views)
I believe when you open a file in that way, the path to the file will be passed as the argument to your main function, so you just need to process it there.  If main does not receive any arguments, then you can pop up your FileSelectPopup.

Mert A.
National Instruments
0 Kudos
Message 2 of 11
(4,649 Views)

It seems like the Windows shell sends the full path of the item as a commandline parameter to the target of the Send To action. For example, if the following program is the target of the Send To action, it will print the path of the file you send on the standard output window. So, basically you can use argv[1] to get the path of the item sent, but make sure you first check argc to make sure the commandline argument is present.

#include <stdio.h>

int main (int argc, char *argv[])
{
 if (argc > 1)
  puts(argv[1]);
 getchar();
 
 return 0;
}

- Mohan

Message 3 of 11
(4,651 Views)
This seems to work perfectly. Thanks a lot...
0 Kudos
Message 4 of 11
(4,648 Views)

New question:

 

How can I register a filetype, so I just have to doubleclick a file of that type and it is automatically opened by my LabWindows program?

0 Kudos
Message 5 of 11
(4,644 Views)
Wim,

The easiest way to register a file type is to go to the "Tools>Folder Options..." menu item in any explorer window.  From there, click on the "File Types" tab which contains all the registered file types. You can either browse to an existing file extention to change its association (click the "Change..." button where it says "Opens with:") or create a new type and associated viewer (via the "New" button).

Hope this helps.

Mert A.
National Instruments
0 Kudos
Message 6 of 11
(4,642 Views)
Is there any way I can include this in my installation kit, so the filetype gets registered automatically when the software is installed?
0 Kudos
Message 7 of 11
(4,640 Views)
Wim,

Unfortunately, the answer is "not easily".  File type associations are handled through the Windows registry, and currently the LabWindows/CVI distribution kit builder does not provide any options to add registry keys/values.  You will be happy to know that the next release of CVI will allow you to modify the registry.

Just to give you an example of what it entails, let's say we wanted to open files with the extension ".ext" using "path\MyProgram.exe".  We would need to create the registry key "HKEY_CLASSES_ROOT\.ext" and set the "(Default)" value to be some string like "MyFileType".  Then we would need to create the key "HKEY_CLASSES_ROOT\MyFileType" and also create the keys "shell\open\command" underneath it.  Then we would set the "(Default)" value for the "command" key to "path\MyProgram.exe %1" (the %1 will be replaced by the path of the opened file).

If you want your installer to set up these registry keys, you will have to use a third-party installer editor like Wise for Windows Installer or Orca to do some post-processing on the distribution kit you build in CVI.  Wise provides a nice UI specifically for adding file associations that hides some of the details from you, but it is not free for download.  Orca, on the other hand, is freely distributed with the Windows Platform SDK, but it is a much more basic (and therefore difficult) database editor.  You can use either of these tools to add items to the Registry table in your Windows Installer file.

I hope this gives you some ideas.  Good luck!

Mert A.
National Instruments

Message Edited by Mert A. on 10-27-2005 12:49 PM

Message 8 of 11
(4,632 Views)

The application itself could provide instructions to update the registry: at program start check the registry and if the corresponding key does not appears in it, create necessary key and values.

In case you want to automate the process, you could write a simple program to execute after installation in the Application builder (Create Distribution Kit >> Advanced options).

Maybe you can run the application itself in "silent mode" only to check and update the registry: pass in the command line argument an option that will instruct the program not to show any panel and proceed to registry check.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 9 of 11
(4,614 Views)
Thanks for all information. It's obviously not that easy, but I'll try to figure it out.
0 Kudos
Message 10 of 11
(4,613 Views)