Article View: comp.os.ms-windows.programmer.misc
Article #1862Two fonts in a dialog - summary (long)
From: Anne Foxworthy
Date: Wed, 16 Dec 1992 03:10
Date: Wed, 16 Dec 1992 03:10
167 lines
6916 bytes
6916 bytes
Thank you to all those people who took the time to reply to my
request for help in displaying two fonts in a dialogue box.
The replies fell into two broad categories. The first is great if
you want to use a different font for one whole control: pass the
control a WM_SETFONT message.
The other category of replies basically summarises as "use up
lots of time doing it all yourself". I have included excerpts
from some of the replies I received, so that those people who
e-mailed me expressing interest in the solution can decide for
themselves the "best" way of solving the problem.
I have not yet implemented any solution to the problem. Once I
realised there wasn't a simple (i.e. reasonably quick) solution
(I need mixed fonts in one control), we had a meeting here about
it and decided that, as time had not been allowed for this, we
would do the best we could with the standard font. If there is
time at the end of the project (surely you jest!), I will try
something then.
Why does it take so long for computer software to support
math/scientific symbols? I waited years for a mainstream word
processor that would do equations. I naively thought Microsoft
had finally learned that science exists, and would have provided
support within Windows.
Enough blabbing, on to the excerpts.
Several people suggested the same (or similar) idea. Where this
happened, I am only including excerpts from one person. This "one
person" happens to be the first one I came across while putting
this summary together.
The following excerpts are not in any particular order.
From gwydion@gnu.ai.mit.edu:
You could consider defining your own font - just copy a
standard Courier or whatever font, and put in some
mathematical symbols at the 128+ slots. Then select this font
for the dialog box and proceed from there.
>It would be nice if I could also display super- and
>subscripts in a dialog.
Actually, it is fairly easy to do this - use TextOut at the
appropriate x and y co-ords for the ordinary characters. Then
increase the y co-ord for the characters that you want sub-
or super- scripted, and also optionally select a smaller font.
However, this is just for display - you are going to have a
problem if your user needs to WYSIWIG edit this expression.
From jagrant@emr.ca (John Grant): (who had tried supers/subs at
various angles, but not Greek)
Here is some code that I roughed out a while ago and stuffed
in a file call subsuper.doc. Note - it is just some rough
pseudo-code and ideas.
I decided to use special characters to indicate that the next
character was a subscript or superscript, so that you could
use the following text strings: "H~2SO~4" and "U^2^3^8"
#define SUPERSCRIPT '^'
#define SUBSCRIPT '~'
if(strchr(text,SUBSCRIPT)==NULL && strchr(text,SUPERSCRIPT)==NULL){
TextOut(hdc,pt.x,pt.y,text,strlen(text));
}else{
LOGFONT lf;
HFONT hfont_main,hfont_subsuper,hfont;
int i;
POINT s;
//I don't know what the current font is, but I can get
//it by selecting anything else to get the current hfont and
//then restore the 'anything else' font I selected
hfont_main=SelectObject(hdc,SYSTEM_FONT); //retrieve current hfont
SelectObject(hdc,hfont_main); //put it back
GetObject(hfont_main,sizeof(LOGFONT),&lf);
//make the subscript/superscript height= 1/3 of the font height
//and create a new font with everything else the same as the
//current font.
lf.lfHeight*=(1.0/3.0);
hfont_subsuper=CreateFontIndirect(&lf);
hfont=NULL;
//loop through all characters, switching fonts back & forth
//between normal and subscript/superscript font as required
for(i=0;i<strlen(text);i++){
p=pt;
if(text[i]==SUPERSCRIPT){
hfont=SelectObject(hdc,hfont_subsuper);
i++;
p.x=
p.y=
}else if(text[i]==SUBSCRIPT){
hfont=SelectObject(hdc,hfont_subsuper);
i++;
p.y=
p.y=
}
TextOut(hdc,p.x,p.y,&text[i],1);
if(hfont!=NULL){
SelectObject(hdc,hfont_main);
}
//for the rest, ignore (x,y) & keep track of (x,y) internally
if(i==0) SetTextAlign(hdc,old_align | TA_UPDATECP);
}
From: patrick@shamrck.ersys.edmonton.ab.ca (Patrick Arial):
Probably the easiest way to do this (and many other nifty
things) is to create a custom dialog control, and simply
have it process WM_PAINT messages. It will only see a child
window that happens to be in your dialog box. If you just
want static text, only process WM_CREATE, WM_PAINT, and
WM_DESTROY.
From: "Pablo Ahumada M." <pam@vandi.ars.cl>
You can handle the WM_CTLCOLOR message. This message is sent
by the controls to his parent, the dialog box window.
case WM_CTLCOLOR: {
HWND hControl = LOWORD(lParam);
WORD ControlId = GetWindowWord( hControl, GWW_ID );
if( ControlID == MY_MATH_OBJECT )
SelectObject( wParam, hMySpecialFont );
break;
}
From: James A. O'Brien <obrien@pressure.eng.yale.edu>
I think I know how it can be done, but it's not pretty. I did
subscripts for permanent static text controls by using a
separate static for each subscript!!! You could probably do
greek letters the same way, by having several controls, and
sending WM_SETFONT to each when the dialog is started. I
think that, to do a general solution (e.g. where you'd use a
TeX-like syntax), , you may have to do without a dialog, and
use a regular window with separate controls in it, and
subclass them to get the desired effects.
From: Glenn Wallace <g.wallace@trl.oz.au>
Probably the most generic way to do it is to create your own
static text class, based on the Windows one (superclassed?)
with your own painting management, so you can set various
fonts for portions of the text.
Does it have to be a dialog box? You could always do it as a
window and create the child windows (controls) manuaaly and
have your custom paint routines for them which are aware of
the fonts and stuff.
--
------------------------------------------------------------------------
E-mail: annef@dmp.csiro.au (preferred) | If my opinions and those
CIS : 100033,3365 (infrequently read) | of CSIRO coincide, it is
Snail : CSIRO Division of Mineral Products | pure accident. I am not
Technical Details
Message-ID:
<1992Dec16.031008.17460@dmp.csiro.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!mel.dit.csiro.au!dmp.csiro.au!annefShow Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc,comp.windows.ms.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!mel.dit.csiro.au!dmp.csiro.au!annef From: annef@dmp.csiro.au (Anne Foxworthy) Subject: Two fonts in a dialog - summary (long) Message-ID: <1992Dec16.031008.17460@dmp.csiro.au> Organization: CSIRO Division of Mineral Products, Melbourne, AUSTRALIA Date: Wed, 16 Dec 1992 03:10:08 GMT Lines: 167