Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fonts in Dialog Boxes

yuric
Beginner
951 Views
Hi,

i am building a QuickWin application using Compaq Visual Fortran. The application uses dialog boxes. In such dialog boxes, i need to include text with fonts other than the System font (which appears to be the default). I need for example Symbol (greek) for the labels of some edit fields. I am just interested in choosing the fonts for those labels (static text fields), i don't need to feed special fonts into edit fields.
Is there a way to have a dialog box containig text using various fonts, in a QuickWin application ? Is there a way, at least, to do it in a general Fortran Windows application?

Thanks!

Yuric
0 Kudos
5 Replies
Jugoslav_Dujic
Valued Contributor II
951 Views
DFLOGM is totally independent from QuickWin (although Compaq's documentation doesn't state it explicitly). DFLOGM is convenient wrapper for Windows dialog APIs, but, being a wrapper, it can't do everything.

What you want is possible with some help of Win32 API. First, you should define "dialog-initialization" callback (triggered immediately after DlgModal):
EXTERNAL OnDlgInit
...
i = DlgSetSub(Dlg, IDD_MYDIALOG, OnDlgInit)
iRet = DlgModal(Dlg)
And after that use CreateFont(Indirect) and WM_SETFONT.
...
SUBROUTINE OnDlgInit(Dlg,ID,iEvent)
USE DFWIN
USE DFLOGM
TYPE(Dialog):: Dlg
INTEGER::  ID, iEvent
TYPE(T_LOGFONT):: LF
INTEGER::  i, hFont


LF=T_LOGFONT(-12,0,0,0,0,0_1,0_1,0_1,0_1, &
   0_1,0_1,0_1,0_1,"Symbol"C) !12-point Symbol font
hFont = CreateFontIndirect(LF)
!Repeat for each control ID where you want to set the font
i = SendMessage(GetDlgItem(Dlg%hWnd,IDC_TEXT1), &
    WM_SETFONT, hFont, 0)

END SUBROUTINE OnDlgInit
Note that the sample above, as written, has a memory leak, because hFont must be destroyed explicitly when not used anymore. You should make hFont (if you use more fonts, each one) global and after DlgModal destroy it via DeleteObject(hFont).

HTH
Jugoslav
0 Kudos
gregscvf
Beginner
951 Views
Many Greek symbols are available without any special programming. Simply press Alt+(3-digit code), when NumLock is on. See ASCII Character Codes under Help. Especially useful are Alt+248 for the degrees symbol, and Alt+241 for plus/minus symbol.

Greg
0 Kudos
yuric
Beginner
951 Views
It doesn't seem to be that simple. Inserting ASCII characters (e.g. from the "IBM" set) works totally fine when outputting to the screen, not so when you want to write in a dialog box. For example, if i right-click on a static text field and type Alt+241 in the 'Caption' field, i will correctly see the +/- symbol. This works also for
Alt+248 (to stick with your two examples.) However, if i type Alt+235 (the greek delta) i get a normal "d".
Moreover, if i address the static text field from code
with

retlog = DlgSet(dlg, ID_Static_text, char(235))

i get a "e" with the umlat.
Conversely, if i type

print*,char(235)

i do get a greek delta on the screen.

Just as a reminder, I am using Windows2000 (CVF is version 6.6.0 ).

Thx,


Yuric
0 Kudos
yaodong
Beginner
951 Views
I have also met such problem, which was baffling me.
I have use font of "SYMBOL" on my costom dialog. I use the method of "LOGFONT" to abtain it. But I find the the texts which should be SYMBOL can not displayed nomally on the discreen.
The way I thought out to overwholm it is that I change the properity of the whole dialog, to change the dialog font to SYMBOL. Then change texts which should be SYSTEM(font).
If there any simple way to conqour it.
I mean that I can just change the font of SYMBOL by easy commond in CVF system.
0 Kudos
yuric
Beginner
951 Views
I tried the code snippet suggested by Jugoslav in his reply and it works perfectly in my case.

It should work for you too (unless the problem is elsewhere.) Make sure you follow exactly the right procedure to implement it.
Here's what i've written (the ID of the text that will show greek fonts is "ID_anytext"):

!--------------------- Makes greek_font global
MODULE MyModule
INTEGER greek_font
END MODULE MyModule

!--------------------- Sub to create the dialog box
SUBROUTINE dialog_box

USE DFWIN
USE DFLOGM
USE MyModule

TYPE(dialog) dlg
LOGICAL retlog
INCLUDE 'resource.fd'
EXTERNAL OnDlgInit

IF (.NOT. DlgInit(ID_MyDialog) ) THEN
WRITE (*,*)'Error: dialog not found'
ELSE
retlog = DlgSetSub(dlg, ID_MyDialog, OnDlgInit)
retlog = DlgSet(dlg, ID_anyText, "Some Text")

retlog = DlgModal(dlg)
retlog = DeleteObject(greek_font)

CALL DlgUninit(dlg)

END SUBROUTINE dialog_box

!--------------------------------------- Creates the font
SUBROUTINE OnDlgInit(dlg, ID, iEvent)
USE DFWIN
USE DFLOGM
USE MyModule

TYPE(dialog) dlg
TYPE(T_Logfont) LF
INTEGER ID, iEvent, i
INCLUDE 'resource.fd'

LF = T_Logfont(-18, 0,0,0,0,0_1,0_1,0_1,0_1 &
0_1,0_1,0_1,0_1,0_1, "Symbol"C)

greek_font=CreateFontIndirect(LF)
i=SendMessage(GetDlgItem(Dlg%hWnd,ID_anytext), &
WM_SETFONT,greek_font,0)

END SUBROUTINE OnDlgInit
!-------------------

As i said, it works fine: when i run it, only the ID_anytext field will show the created font. Any other control has system default fonts (or whichever other font I've assigned to it).

Good luck!

yuric
0 Kudos
Reply