News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Open with dialog

Started by Gunner, December 28, 2009, 11:42:27 PM

Previous topic - Next topic

Gunner

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
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

MichaelW

Do you mean GetOpenFileName? MASM32 version 10 includes among the examples several versions of the file filedlgs.asm that contains wrapper procedures for GetOpenFileName and GetSaveFileName.
eschew obfuscation

Ghandi

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

Gunner

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
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com