The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => Miscellaneous Projects => Windows Projects => Topic started by: Gunner on December 28, 2009, 11:42:27 PM

Title: Open with dialog
Post by: Gunner on December 28, 2009, 11:42:27 PM
Searched the board and MSDN, maybe I am searching wrong, but is there an API call to show the "Open with" application dialog?  Or is there a style to pass to the regular open dialog?  You know the dialog I mean...... Click on a file that doesn't have a program associated with it and a dialog with applications appear for you to choose from.  If not, will make one and parse a key in the registry, just thought it would be easier to use windows functions instead of me :-)

[edit]
Eh, think I would have to use COM... not ready to dive into COM, a little confusing
Title: Re: Open with dialog
Post by: MichaelW on December 29, 2009, 01:51:08 AM
Do you mean  GetOpenFileName (http://msdn.microsoft.com/en-us/library/ms646927(VS.85).aspx)? MASM32 version 10 includes among the examples several versions of the file filedlgs.asm that contains wrapper procedures for GetOpenFileName and GetSaveFileName.
Title: Re: Open with dialog
Post by: Ghandi on December 29, 2009, 05:28:53 AM
Using rundll32, we can pass shell32.dll as a parameter, along with the command to show the dialog (OpenAs_RunDLL) and the file name/extension. Make sure to include shell32.inc and shell32.lib so you can link against the dll unless you want to import it yourself. I've assembled the code below and it does bring up the dialog and launch the chosen program, if any.

See in the Params string, there is a leading space, this is in all the examples i found but leaving it out seems to work. There must be a way to enable/disable the "Always use the selected program blah blah blah", because its selected but disabled, so i'd imagine that selecting a program will set it as the default application in the registry.


.data
szOpen db "open",0
szRunDll db "%s\system32\rundll32.exe",0
ParamFmt db " %s\system32\shell32.dll, OpenAs_RunDLL test.exe",0
szPath db 256 dup (?)
szWinDir db 256 dup (?)
szCommand db 256 dup (?)
szParam db 256 dup (?)

.code
start:
invoke GetWindowsDirectory,offset szWinDir,sizeof szWinDir ;Get windows directory

invoke wsprintf,offset szCommand,offset szRunDll,offset szWinDir ;Make absolute paths to files used
invoke wsprintf,offset szParam,offset ParamFmt,offset szWinDir ;Make absolute paths to files used

invoke GetCurrentDirectory,sizeof szPath,offset szPath ;Not necessary, but i'll get the current directory also

invoke ShellExecute,HWND_DESKTOP,offset szOpen,offset szCommand,offset szParam,offset szPath,SW_SHOWNORMAL ;Display OpenWith
invoke ExitProcess,ERROR_SUCCESS ;Finally, exit process (dialog will still be on screen)
end start
Title: Re: Open with dialog
Post by: Gunner on December 29, 2009, 05:54:34 PM
Thanks  works!  what is the lowest os it will work on?

[edit]
Just found this page with many commands for rundll  :bg
http://chagdali.free.fr/dcs/RunDll.htm