Good evening, everyone.
I am, as usual, doing something strange and completely unexpected.
I'm creating my own dialog to set the current font in my program.
I know that there's a standard font dialog, which is usually
called in these situations, but I'd rather use my own as I
personally find its layout less confusing. Anyway, my problem is
getting a list of all available fonts on a paticular PC. I found
the list in the registry, under
HKEY_Local_Machine\Software\Microsoft\Windows\CurrentVersion\Fonts.
My job now is to retrieve all the values under this key, Right? If
I'm right on that, the RegEnumValue function has got to be the
answer. Or so I thought.
I put together the below program, but it just returns error code
234, which is %ERROR_MORE_DATA. I've puzzled over that one for a
while, but can't figure out what that could possibly mean. Anyway,
I'm hoping I've done something obviously wrong in the below
program.
#COMPILE EXE
#INCLUDE "WIN32API.INC"
GLOBAL hKey AS LONG, Ended AS LONG, Dud AS LONG, Ti AS INTEGER
FUNCTION RegOpenSection (BYVAL Key AS LONG, Section AS ASCIIZ) AS LONG
IF RegCreateKeyEx(Key, Section, 0, "", %REG_OPTION_NON_VOLATILE, _
%KEY_ALL_ACCESS, BYVAL %NULL, hKey, Dud) <> %ERROR_SUCCESS THEN
'Failed
END IF
END FUNCTION
FUNCTION RegClose() AS LONG
RegCloseKey hKey
END FUNCTION
FUNCTION RegGetValues(Key AS LONG, Txt AS ASCIIZ, mAray() AS STRING) EXPORT AS INTEGER
LOCAL zBuffer AS ASCIIZ*300
CALL RegOpenKey(Key, Txt, hKey)
IF ISFALSE(hKey) THEN EXIT FUNCTION
FOR Dud=0 TO 1001
Ended=RegENumValue(hKey, Dud, zBuffer, SIZEOF(zBuffer)-1, %NULL, 0, 0, 0)
IF Ended=%ERROR_Success THEN
mAray(Dud+1)=zBuffer
ELSEIF Ended=%ERROR_NO_MORE_ITEMS THEN
EXIT
ELSE
MSGBOX "Error code" & STR$(Ended)
EXIT
END IF
NEXT
RegClose
FUNCTION=Dud
END FUNCTION
FUNCTION PBMAIN
DIM tAray(1:1000) AS STRING
Ti=RegGetValues(%HKLM, "Software\Microsoft\Windows\CurrentVersion\Fonts", tAray())
MSGBOX "Retrieved" & STR$(Ti) & " fonts:" & $CRLF & _
"First font is " & tAray(1) & $CRLF & _
"Second font is " & tAray(2) & $CRLF & _
"Third font is " & tAray(3)
END FUNCTION
Thank you so much for your help. All this registry stuff has a
disterbing way of getting me really confused really fast.
Danny.
I am, as usual, doing something strange and completely unexpected.
I'm creating my own dialog to set the current font in my program.
I know that there's a standard font dialog, which is usually
called in these situations, but I'd rather use my own as I
personally find its layout less confusing. Anyway, my problem is
getting a list of all available fonts on a paticular PC. I found
the list in the registry, under
HKEY_Local_Machine\Software\Microsoft\Windows\CurrentVersion\Fonts.
My job now is to retrieve all the values under this key, Right? If
I'm right on that, the RegEnumValue function has got to be the
answer. Or so I thought.
I put together the below program, but it just returns error code
234, which is %ERROR_MORE_DATA. I've puzzled over that one for a
while, but can't figure out what that could possibly mean. Anyway,
I'm hoping I've done something obviously wrong in the below
program.
#COMPILE EXE
#INCLUDE "WIN32API.INC"
GLOBAL hKey AS LONG, Ended AS LONG, Dud AS LONG, Ti AS INTEGER
FUNCTION RegOpenSection (BYVAL Key AS LONG, Section AS ASCIIZ) AS LONG
IF RegCreateKeyEx(Key, Section, 0, "", %REG_OPTION_NON_VOLATILE, _
%KEY_ALL_ACCESS, BYVAL %NULL, hKey, Dud) <> %ERROR_SUCCESS THEN
'Failed
END IF
END FUNCTION
FUNCTION RegClose() AS LONG
RegCloseKey hKey
END FUNCTION
FUNCTION RegGetValues(Key AS LONG, Txt AS ASCIIZ, mAray() AS STRING) EXPORT AS INTEGER
LOCAL zBuffer AS ASCIIZ*300
CALL RegOpenKey(Key, Txt, hKey)
IF ISFALSE(hKey) THEN EXIT FUNCTION
FOR Dud=0 TO 1001
Ended=RegENumValue(hKey, Dud, zBuffer, SIZEOF(zBuffer)-1, %NULL, 0, 0, 0)
IF Ended=%ERROR_Success THEN
mAray(Dud+1)=zBuffer
ELSEIF Ended=%ERROR_NO_MORE_ITEMS THEN
EXIT
ELSE
MSGBOX "Error code" & STR$(Ended)
EXIT
END IF
NEXT
RegClose
FUNCTION=Dud
END FUNCTION
FUNCTION PBMAIN
DIM tAray(1:1000) AS STRING
Ti=RegGetValues(%HKLM, "Software\Microsoft\Windows\CurrentVersion\Fonts", tAray())
MSGBOX "Retrieved" & STR$(Ti) & " fonts:" & $CRLF & _
"First font is " & tAray(1) & $CRLF & _
"Second font is " & tAray(2) & $CRLF & _
"Third font is " & tAray(3)
END FUNCTION
Thank you so much for your help. All this registry stuff has a
disterbing way of getting me really confused really fast.
Danny.
Comment