Posts: 1,000
Threads: 253
Joined: Feb 2008
The Project:
Using XML format to store data in a text file for a program designed in QM, but the file extension is not .xml, instead would be a custom file extension.
Example:
File extension: (.VIG)
Pogram: The Vig Music
Icon: vig.ico
Windows would display the files using the vig.ico
When files open, The Vig Music program would be triggered and data would be executed.
Save and Save As would write data only with the (.VIG) extension.
Open dialogs would only display (.VIG) files
Pretty much the idea is developing something just like how the .qml files work with Quick Macros.
Combining this idea with file menus will allow create programs that look and feel professional.
Thanks,
Jimmy Vig
P.S. QM is the best!
Posts: 12,049
Threads: 140
Joined: Dec 2002
Function
FileExtRegister
;/
function $ext $cls $description $icon [$cmd] [$content_type]
;Adds new file extension.
;QM must be running as administrator.
;Error if fails.
;ext - extension.
;cls - class. Can be any string but must not begin with ".".
;description - eg "Vig File".
;icon - eg "c:\program files\x\x.exe,3".
;cmd - command line, eg "c:\program files\x\x.exe ''%1''". Will be registered as "Open" verb. If you don't use it here, then later you should use FileExtAddVerb.
;content_type - content type, eg "text/xml". Optional.
;EXAMPLE
;FileExtRegister "vig" "vigfile" "Vig File" "shell32.dll,20" "notepad.exe ''%1''"
;
;str s="test"
;s.setfile("$desktop$\test.vig")
;run "$desktop$\test.vig"
int h=HKEY_CLASSES_ROOT
str s
if(ext[0]='.') ext+1
if(!rset(cls "" s.from("." ext) h)) end ES_FAILED
if(!empty(content_type)) rset content_type "Content Type" s h
if(!rset(description "" cls h)) end ES_FAILED
if(!empty(icon)) rset icon "" s.from(cls "\DefaultIcon") h iif(icon[0]='%' REG_EXPAND_SZ REG_SZ)
if(!empty(cmd)) FileExtAddVerb ext "Open" cmd 1; err end _error
SHChangeNotify SHCNE_ASSOCCHANGED 0 0 0
Function
FileExtUnregister
;/
function $ext
;Removes a file extension. Also removes all its verbs.
;QM must be running as administrator.
;Error if fails.
;ext - extension, eg "vig".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
rset "" s h 0 -2
rset "" cls h 0 -2
SHChangeNotify SHCNE_ASSOCCHANGED 0 0 0
Function
FileExtAddVerb
;/
function $ext $verb $cmd [flags] ;;flags: 1 make default
;Adds a verb (context menu command) to a file extension.
;QM must be running as administrator.
;Error if fails.
;ext - extension, eg "vig".
;verb - verb name, eg "Play".
;cmd - command line, eg "c:\program files\x\x.exe /p ''%1''".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
if(flags&1) rset verb "" s.from(cls "\Shell") h
s.from(cls "\Shell\" verb "\Command")
if(!rset(cmd "" s h iif(cmd[0]='%' REG_EXPAND_SZ REG_SZ))) end ES_FAILED
Function
FileExtRemoveVerb
;/
function $ext $verb
;Removes a verb (context menu command) from a file extension.
;QM must be running as administrator.
;Error if fails or the extension does not exist. Not error if the werb does not exist.
;If you remove default verb, later use FileExtSetDefaultVerb to set another default verb.
;ext - extension, eg "vig".
;verb - verb name, eg "Play".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
rset "" verb s.from(cls "\Shell") h -2
Function
FileExtSetDefaultVerb
;/
function $ext $verb
;Sets default verb of a file extension.
;QM must be running as administrator.
;Error if fails.
;ext - extension, eg "vig".
;verb - verb name, eg "Play".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
if(!rset(verb "" s.from(cls "\Shell") h)) end ES_FAILED
Posts: 1,000
Threads: 253
Joined: Feb 2008
Holy cow!
That's about the best thing I've seen. Someday I hope to have about 1/100th the mad skill that Gintaras possesses!
This is going to be so cool to use in programs.
Thanks so much,
Jimmy Vig
Posts: 1,000
Threads: 253
Joined: Feb 2008
Could you give an example of how an executable would use the text stored in a file with a registered extension.
Thanks,
jimmy Vig
Posts: 1,000
Threads: 253
Joined: Feb 2008
Better yet...encrypt the data in the file...then use it in an executable.
I've always wondered about doing this but haven't gotten around to it.
Thanks!
Posts: 1,000
Threads: 253
Joined: Feb 2008
So this is pretty simple. Program just loads up with str.getfile() and then work with that.
The encrypting part, I'll figure out.
Thanks,
Jimmy Vig