Tip: How to display fonts in a combo box

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Tip: How to display fonts in a combo box

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:51 pm

by allistar >> Tue, 20 Jul 2004 21:29:02 GMT

Hi all,
I recently had the need to allow the user to select a font from a drop down list. Using the CMDFontDlg was not an option. Here is how it is done:

create an external method on the StringArray class with this signature:

populateWithFonts(hwnd: Integer) is enumerateFonts in gtassist;

(gtassist is the name of the dll I put the "enumerateFonts" function in).

The code in that dll is:

BOOL CALLBACK EnumFontProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, DWORD dwType, LPARAM lpData)
{
DskBuffer *pBuffer = (DskBuffer*)lpData;
DskArray self(&pBuffer->oid);

DskParam p1;
paramSetCString(p1, lplf->lfFaceName);
self.sendMsg(TEXT("add"), &p1, 0, __LINE__);

return TRUE;
}

extern "C" int DllExport JOMAPI enumerateFonts(void*, DskBuffer* pBuffer, DskParam* pParam, DskParam*)
{
//get the hwnd passed in
Integer integer;
paramGetInteger(*pParam, integer);
HWND hwnd = (HWND)(int)integer;

HDC dc = GetWindowDC(hwnd);
EnumFonts (dc, 0,(FONTENUMPROC) EnumFontProc,(LPARAM)pBuffer);

return 0;
}

This can be called in JADE to populate a combo box like this:

vars
array: StringArray;
string: String;begin

create array transient;
array.populateWithFonts(cbCombo.hwnd);
foreach string in array do
cbCombo.addItem(string);
endforeach;
epilog
delete array;
end;

This does the trick quite well. I hope someone else can make good use of it.

Regards,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Tip: How to display fonts in a combo box

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:51 pm

by bitsnz >> Wed, 1 Sep 2004 22:35:27 GMT

Cheers Allistar

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Tip: How to display fonts in a combo box

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:51 pm

by bitsnz >> Wed, 1 Sep 2004 22:35:47 GMT

Cheers Allistar

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Tip: How to display fonts in a combo box

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:51 pm

by bitsnz >> Wed, 1 Sep 2004 22:36:55 GMT

Cheers Allistar

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Tip: How to display fonts in a combo box

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:51 pm

by bitsnz >> Wed, 1 Sep 2004 22:39:57 GMT

Cheers Allistar

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Tip: How to display fonts in a combo box

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:51 pm

by bitsnz >> Wed, 1 Sep 2004 22:42:26 GMT

Cheers Allistar

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Tip: How to display fonts in a combo box

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:51 pm

by bitsnz >> Wed, 1 Sep 2004 22:44:21 GMT

Cheers Allistar


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 0 guests