- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I would like to be able to activate a Win32 program by double clicking on an associated file in Windows Explorer. I don't want to disturb the program's normal menu driven operation, but if a user decides to double click on one of its normal data files I would like the program to open in its graphical mode and deal with the file, etc, etc. I presume this would be achieved through some operation using the WinMain lpCmdLine argument but I am unable to make much progress with the online documentation. Can this be done?
Many thanks for any help or suggestions.
Mike
I would like to be able to activate a Win32 program by double clicking on an associated file in Windows Explorer. I don't want to disturb the program's normal menu driven operation, but if a user decides to double click on one of its normal data files I would like the program to open in its graphical mode and deal with the file, etc, etc. I presume this would be achieved through some operation using the WinMain lpCmdLine argument but I am unable to make much progress with the online documentation. Can this be done?
Many thanks for any help or suggestions.
Mike
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - michaelgreen
Hi All,
I would like to be able to activate a Win32 program by double clicking on an associated file in Windows Explorer. I don't want to disturb the program's normal menu driven operation, but if a user decides to double click on one of its normal data files I would like the program to open in its graphical mode and deal with the file, etc, etc. I presume this would be achieved through some operation using the WinMain lpCmdLine argument but I am unable to make much progress with the online documentation. Can this be done?
Many thanks for any help or suggestions.
Mike
I would like to be able to activate a Win32 program by double clicking on an associated file in Windows Explorer. I don't want to disturb the program's normal menu driven operation, but if a user decides to double click on one of its normal data files I would like the program to open in its graphical mode and deal with the file, etc, etc. I presume this would be achieved through some operation using the WinMain lpCmdLine argument but I am unable to make much progress with the online documentation. Can this be done?
Many thanks for any help or suggestions.
Mike
When you do this does the filename get appended to the program name as an argument? If so, you should be able to check the number of arguments and take action accordingly. I don't have IVF on this machine, so I can't look up the commandline functions.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yep, that's the way. The data file's name will appear on the command line after the name of the executable associated with the file extension, so you should then use the GETARG routine e.g.
USE IFLIB (or DFLIB if using CVF)
character(256) filenamebuffer
integer(2) istat
CALL GETARG(1,filenamebuffer,istat)
to retrieve the filename and put it into the character string buffer filenamebuffer. Check the status using istat.
Drag-and-drop will also work this way. If you drag a datafile from Explorer onto a desk top shortcut to the the application, or if you drag a data file onto the applications execuatble file in Explorer, then Windows will start the application as if started with a command line and it will supply the file name as the first argument on the commandline.
USE IFLIB (or DFLIB if using CVF)
character(256) filenamebuffer
integer(2) istat
CALL GETARG(1,filenamebuffer,istat)
to retrieve the filename and put it into the character string buffer filenamebuffer. Check the status using istat.
Drag-and-drop will also work this way. If you drag a datafile from Explorer onto a desk top shortcut to the the application, or if you drag a data file onto the applications execuatble file in Explorer, then Windows will start the application as if started with a command line and it will supply the file name as the first argument on the commandline.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mike,
If you are using a version of the compiler with the Fortran 2003 command line options then, for portability and standards conformancee you should use them :
GET_COMMAND
GET_COMMAND_ARGUMENT
COMMAND_ARGUMENT_COUNT
here isthe example from the help :
Les
If you are using a version of the compiler with the Fortran 2003 command line options then, for portability and standards conformancee you should use them :
GET_COMMAND
GET_COMMAND_ARGUMENT
COMMAND_ARGUMENT_COUNT
here isthe example from the help :
[cpp]program echo_command_line integer i, cnt, len, status character c*30, b*100 call get_command (b, len, status) if (status .ne. 0) then write (*,*) 'get_command failed with status = ', status stop end if write (*,*) 'command line = ', b (1:len) call get_command_argument (0, c, len, status) if (status .ne. 0) then write (*,*) 'Getting command name failed with status = ', status stop end if write (*,*) 'command name = ', c (1:len) cnt = command_argument_count () write (*,*) 'number of command arguments = ', cnt do i = 1, cnt call get_command_argument (i, c, len, status) if (status .ne. 0) then write (*,*) 'get_command_argument failed: status = ', status, ' arg = ', i stop end if write (*,*) 'command arg ', i, ' = ', c (1:len) end do write (*,*) 'command line processed' end [/cpp]
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - michaelgreen
Hi All,
I would like to be able to activate a Win32 program by double clicking on an associated file in Windows Explorer. I don't want to disturb the program's normal menu driven operation, but if a user decides to double click on one of its normal data files I would like the program to open in its graphical mode and deal with the file, etc, etc. I presume this would be achieved through some operation using the WinMain lpCmdLine argument but I am unable to make much progress with the online documentation. Can this be done?
I would like to be able to activate a Win32 program by double clicking on an associated file in Windows Explorer. I don't want to disturb the program's normal menu driven operation, but if a user decides to double click on one of its normal data files I would like the program to open in its graphical mode and deal with the file, etc, etc. I presume this would be achieved through some operation using the WinMain lpCmdLine argument but I am unable to make much progress with the online documentation. Can this be done?
Few additional data:
- Data that you get through WinMain's lpszCmdLine is the same as through GETARG, which is in turn the same as standard F2003 GET_COMMAND_ARGUMENT (supported since Ifort 9.1 or so). The latter two already do the command line parsing (argument splitting) so they're easier to use.
- Pay attention to file paths containing blanks. Without quotes, such paths will be interpreted as multiple command-line arguments by GETARG/GET_COMMAND_ARGUMENTs. So, ensure that your file association reads like myprogram.exe "%1". In that case (if I recall correctly), you will get the filename quoted (e.g. ' "C:usersMikeMy documentsfoo.dat" ') within the string, so you must strip the quotes using e.g. INDEX intrinsic before you OPEN the file.
- Also consider use case where you have file A already open in the application, but user double-clicks on file B. Do you want to start a new instance (default behavior), or open B in existing instance? In the latter case, what happens if there are unsaved data in A? Etc.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page