(what follows is still based on the code presented in the code box.
Is there an updated Zip file somewhere ?)
---------------------------
Bug:
Here's a Control-C copy of the messagebox when attempting to save the resulting image:
Code: Select all
Error
---------------------------
Unable to save to C:\Documents and Settings\ [userName] \My Documents\My Pictures\QuickSnap_001.bmp
---------------------------
OK
Your Procedure LoadPreferences() makes a false assumption at line #4:
Code: Select all
Folder$ = GetEnvironmentVariable("USERPROFILE") + "\My Documents\My Pictures\"
D:\Documents\[userName]\
There's no getting around it: you have to check the registry key [HKCU\...\Explorer\Shell Folders] to get the correct path after all!
---------------------------
Keep up the good work.
---------------------------
possible solution to path bug:
I have used the following to solve the path problem:
.
Code: Select all
Procedure.S Read_stringKey(key$, subKey$)
;; input 1: key = the registry key holding the information we need
;; input 2: subKey = the value we're looking for
;; output: the value of the subkey, or an empty string
Protected r.L, hKey.L, keyType.L
Protected buffer.S, bufSize.L
hKey = 0 ; handle of the registry key
; *** access the requested registry key
r = RegOpenKeyEx_( #HKEY_CURRENT_USER, @key$, 0, #KEY_ALL_ACCESS, @hKey )
If r <> #NO_ERROR
;;Debug "Erreur à l'ouverture de la clé"
ProcedureReturn ""
EndIf
bufSize = 255 ; length of buffer
buffer.s = Space(bufSize) ; buffer for returning data
keyType = #REG_SZ ; type of data we're looking for
; *** read the value of the subKey
r = RegQueryValueEx_( hKey, @subKey$, 0, @keyType, @buffer, @bufSize)
; *** release this resource immediately
RegCloseKey_(hKey)
If r <> #NO_ERROR
;;Debug "ERREUR: Clé vide"
buffer = ""
EndIf
ProcedureReturn buffer
EndProcedure
Code: Select all
Folder$ = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" + Chr(0)
Folder$ = Read_stringKey(folder$, "My Pictures") + "\"
The path obtained from the registry is certainly the correct one, the backslash gets appended properly, and everything looks kosher, until I actually save the image. Then the final backslash evaporates from the end of the path variable.
How ? Where ? When ? Don't know. And it's killing me

Meantime, instead of solving the problem, I went around it.
I've added a check on line 13 of SaveScreenShot(), which looks like this:
Code: Select all
If Right(Folder$,1) <> "\"
folder$ + "\"
EndIf
saveloc.s = Folder$ + "QuickSnap_001" + ext$
Any explanation for this apparently perfectly idiotic behaviour ?
.