Ok,
Here's the bare bones check font directory filenames. It only returns the files in there, does check to make sure they are only fonts, and it doesn't look in the files for their names, but it gives you an idea of the method that you could expand on:
rem bares bones get font directory listing
sys$=windir$()+"\fonts\"
cd sys$
perform checklist for files
total=checklist quantity()
dim fontfiles$(total)
count=-1
for n=1 to total
if len(checklist string$(n)) > 3
if mid$(right$(checklist string$(n),4),1)="."
inc count
fontfiles$(count)=checklist string$(n)
endif
endif
next n
empty checklist
print "TOTAL FONT FILES: ";count
for n=0 to count
print fontfiles$(n);" ";
next n
Here's the ChooseFont method:
I went ahead and created another "bare bones" example DLL that uses the ChooseFile() function from the win32 api. Here is the main function in C of the DLL:
DLLIMPORT void dbcFontDialog(HWND hwnd, char *selection)
{
CHOOSEFONT cf;
LOGFONT lf;
LPTSTR style[32];
// initialize choosefont structure
cf.lStructSize=sizeof(cf);
cf.hwndOwner=hwnd;
cf.lpLogFont=&lf;
cf.Flags=CF_SCREENFONTS;
cf.lpszStyle=*style;
ChooseFont(&cf);
//copy the typeface from LOGFONT structure
//to the string pointer from DBC
strcpy(selection,lf.lfFaceName);
}
If you look up the ChooseFont function, you'll see that there are two structures (If you are familiar with types, a structure is basically a type - a block of memory of a series of named data types) CHOOSEFONT and LOGFONT. By setting the different members of CHOOSEFONT, I can tell the font dialog box basically how to behave. I use the LOGFONT structure to get the return values as a result of selecting an item from the font dialog box.
The parameters for my function
dbcFontDialog(HWND hwnd, char *selection) are the parameters that DBC is going to pass to the DLL.
hwnd is the handle of the DBC window. This can be NULL (or zero in DBC) in which case the Font Dialog box won't have an owner. The parameter
char *selection is a string variable that will be passed from DBC. In C, it's a pointer to an area of memory. DBC automagically creates a pointer when it creates a string and this is really what I'm passing to the DLL: the pointer to the string information.
Once the user has selected a font in the dialog box, the command
strcpy(selection,lf.lfFaceName);
copies the string information from the member lfFaceName of my LOGFONT structure to the
selection pointer (the string variable in DBC). This is returned to DBC.
I'll attach a copy of the actual DLL.
Here is the code to run from DBC when using the DLL:
set window on
fontdlg=1
user32=2
load dll "font_dialog.dll",fontdlg
load dll "user32.dll",user32
hwnd=call dll(user32,"GetActiveWindow")
rem set the size of the return string buffer to DBC's max
for n=1 to 255
a$=a$+chr$(65)
next n
call dll fontdlg,"dbcFontDialog",hwnd, a$
wait 0
print a$
It works best in windowed mode. If you don't use windowed mode, I think you'll have to naviaget the font box without the mouse useing TAB and arrow keys.
There are options for the choosefont dialog box. This example just gets it running and returning a font name. If you have access to a C/C++ compiler and some time if you are not too familiar with C, you may be able to play with and modify the code to your liking.
You can also recreate this in DBC alone without creating your own DLL by using memblocks to create the necessary structures. You'll have to make them the correct size however which can be tricky. You call ChooseFont() from comdlg32.dll:
assuming choosptr is a memblock pointer to CHOOSEFONT structure and
comdlg32 is the loaded dll number:
call dll comdlg32,"ChooseFontA",chooseptr
I haven't tried enumerating the fonts yet... It's a little more complicated... I'll see how I feel about giving that a go.
Enjoy your day.