Open With...

Blitz3D Forums/Blitz3D Programming/Open With...

Fuller(Posted 2007) [#1]
How do you accept files opened with. Like when you click on an image file and it will open in whatever program you have it set on. How do you do this? Whenever I click on a file and open it in one of my Blitz-made programs it only opens the program and not the file.


IPete2(Posted 2007) [#2]
Right mouse click over the type i.e. a jpeg or a bmp file and use open with...

choose a program and tick the box to keep it to always open with that progam.

IPete2


jfk EO-11110(Posted 2007) [#3]
since we're at it: how would you do such an association using blitz code?


b32(Posted 2007) [#4]
I have a program to register filetypes: http://members.home.nl/bramdenhond/aso.zip
----
edit: I thought it used a api call, but it uses a more complex routine. I think I found it on the net somewhere.
Here is the (delphi) source:
procedure FileAssociate(
  cMyExt,
  cMyFileType,
  cMyIcon,
  cMyExeName,
  cMyDesciption : pchar ); stdcall;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    // Set the root key to HKEY_CLASSES_ROOT
    Reg.RootKey := HKEY_CLASSES_ROOT;
    // Now open the key, with the possibility to create
    // the key if it doesn't exist.
    Reg.OpenKey(cMyExt, True);
    // Write my file type to it.
    // This adds HKEY_CLASSES_ROOT\.abc\(Default) = 'Project1.FileType'
    Reg.WriteString('', cMyFileType);
    Reg.CloseKey;
    // Now create an association for that file type
    Reg.OpenKey(cMyFileType, True);
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\(Default)
    //   = 'Project1 File'
    // This is what you see in the file type description for
    // the a file's properties.
    Reg.WriteString('', cMyDesciption);
    Reg.CloseKey;
    // Now write the default icon for my file type
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\DefaultIcon
    //  \(Default) = 'Application Dir\Project1.exe,0'
    Reg.OpenKey(cMyFileType + '\DefaultIcon', True);
    Reg.WriteString('', cMyIcon + ',0');
    Reg.CloseKey;
    // Now write the open action in explorer
    Reg.OpenKey(cMyFileType + '\Shell\Open', True);
    Reg.WriteString('', '&Open');
    Reg.CloseKey;
    // Write what application to open it with
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\Shell\Open\Command
    //  (Default) = '"Application Dir\Project1.exe" "%1"'
    // Your application must scan the command line parameters
    // to see what file was passed to it.
    Reg.OpenKey(cMyFileType + '\Shell\Open\Command', True);
    Reg.WriteString('', '"' + cMyExeName + '" "%1"');
    Reg.CloseKey;
    // Finally, we want the Windows Explorer to realize we added
    // our file type by using the SHChangeNotify API.
    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
  finally
    Reg.Free;
  end;
end;



Fuller(Posted 2007) [#5]
JFK, thats what i meant, sorry I didn't explain well enough. Do you think you can do that in Blitz3d?


jfk EO-11110(Posted 2007) [#6]
Me? you're kiddin right? :o) But this would be a useful extension. Maybe it's easier to write a .REG registration script, then execfile it. I'm pretty sure there are some tutorials about how to write .REG files.


jfk EO-11110(Posted 2007) [#7]
ok I just opened the REG file that was used by the Progmesh installer. It seems to associate the extension .3dp to the progmesh.exe:

(a warning: be careful with reg files!)

REGEDIT

HKEY_CLASSES_ROOT\.3dp = ProgMesh.Document
HKEY_CLASSES_ROOT\ProgMesh.Document\shell\open\command = progmesh.exe %1
HKEY_CLASSES_ROOT\ProgMesh.Document\shell\open\ddeexec = [open("%1")]
HKEY_CLASSES_ROOT\ProgMesh.Document\shell\open\ddeexec\application = ProgMesh
;note application key is optional, default is command key
HKEY_CLASSES_ROOT\ProgMesh.Document = PMesh Document



I'm not sure if this works, if it will use the exes Icon for the associated files,a nd if there's some call neccessary to actualize the system or desktop.

Note, be careful with REG file since they edit the registry! Doublecheck for typos before you run them! (including the code I just posted)


jfk EO-11110(Posted 2007) [#8]
OH, btw you also need to optain the name of the doubleclicked document file in your blitz programm, parsing the Commandline$().


jfk EO-11110(Posted 2007) [#9]
Oh well I just tried the REG file. It will display an alert so the user may decide if the association should be made. Plus: windows needs to know the path to the exe, so it may be a registered app, or maybe you can use the full path in the command key.
BTW it seems the icon must be set manually.

Hmm, kind of smelling of pandorra box. I better get rid of this cs2 filetype I just associated.

EDIT : ouch, I hate the registry. It will not only create a lot of keys that I did not explicitely ask for (eg. cs2_auto_file), I laso don't know for sure what keys can be removed without too much risk...
So I say it again, be careful. Or even better: don't mess with the registry at all.


Fuller(Posted 2007) [#10]
Yeah
Or even better: don't mess with the registry at all.


Maybe I'll heed that advice.