home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / misc / 4263 < prev    next >
Encoding:
Text File  |  1992-12-15  |  6.6 KB  |  177 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc,comp.windows.ms.programmer
  2. Path: sparky!uunet!munnari.oz.au!mel.dit.csiro.au!dmp.csiro.au!annef
  3. From: annef@dmp.csiro.au (Anne Foxworthy)
  4. Subject: Two fonts in a dialog - summary (long)
  5. Message-ID: <1992Dec16.031008.17460@dmp.csiro.au>
  6. Organization: CSIRO Division of Mineral Products, Melbourne, AUSTRALIA
  7. Date: Wed, 16 Dec 1992 03:10:08 GMT
  8. Lines: 167
  9.  
  10.  
  11. Thank you to all those people who took the time to reply to my
  12. request for help in displaying two fonts in a dialogue box.
  13.  
  14. The replies fell into two broad categories. The first is great if
  15. you want to use a different font for one whole control: pass the
  16. control a WM_SETFONT message. 
  17.  
  18. The other category of replies basically summarises as "use up
  19. lots of time doing it all yourself". I have included excerpts
  20. from some of the replies I received, so that those people who
  21. e-mailed me expressing interest in the solution can decide for
  22. themselves the "best" way of solving the problem.
  23.  
  24. I have not yet implemented any solution to the problem. Once I
  25. realised there wasn't a simple (i.e. reasonably quick) solution
  26. (I need mixed fonts in one control), we had a meeting here about
  27. it and decided that, as time had not been allowed for this, we
  28. would do the best we could with the standard font. If there is
  29. time at the end of the project (surely you jest!), I will try
  30. something then.
  31.  
  32. Why does it take so long for computer software to support
  33. math/scientific symbols? I waited years for a mainstream word
  34. processor that would do equations. I naively thought Microsoft
  35. had finally learned that science exists, and would have provided
  36. support within Windows.
  37.  
  38. Enough blabbing, on to the excerpts.
  39.  
  40. Several people suggested the same (or similar) idea. Where this
  41. happened, I am only including excerpts from one person. This "one
  42. person" happens to be the first one I came across while putting
  43. this summary together.
  44.  
  45. The following excerpts are not in any particular order.
  46.  
  47. From gwydion@gnu.ai.mit.edu:
  48.    You could consider defining your own font - just copy a
  49.    standard Courier or whatever font, and put in some
  50.    mathematical symbols at the 128+ slots.  Then select this font
  51.    for the dialog box and proceed from there.
  52.  
  53.    >It would be nice if I could also display super- and
  54.    >subscripts in a dialog.
  55.  
  56.    Actually, it is fairly easy to do this - use TextOut at the
  57.    appropriate x and y co-ords for the ordinary characters.  Then
  58.    increase the y co-ord for the characters that you want sub-
  59.    or super- scripted, and also optionally select a smaller font.
  60.  
  61.    However, this is just for display - you are going to have a
  62.    problem if your user needs to WYSIWIG edit this expression.
  63.    
  64.    
  65. From jagrant@emr.ca (John Grant): (who had tried supers/subs at
  66. various angles, but not Greek) 
  67.    Here is some code that I roughed out a while ago and stuffed
  68.    in a file call subsuper.doc.  Note - it is just some rough
  69.    pseudo-code and ideas.
  70.  
  71.    I decided to use special characters to indicate that the next
  72.    character was a subscript or superscript, so that you could
  73.    use the following text strings: "H~2SO~4"    and "U^2^3^8"
  74.  
  75. #define SUPERSCRIPT '^'
  76. #define SUBSCRIPT   '~'
  77.     if(strchr(text,SUBSCRIPT)==NULL && strchr(text,SUPERSCRIPT)==NULL){
  78.       TextOut(hdc,pt.x,pt.y,text,strlen(text));
  79.     }else{
  80.       LOGFONT lf;
  81.       HFONT hfont_main,hfont_subsuper,hfont;
  82.       int i;
  83.       POINT s;
  84.  
  85.       //I don't know what the current font is, but I can get
  86.       //it by selecting anything else to get the current hfont and
  87.       //then restore the 'anything else' font I selected
  88.       hfont_main=SelectObject(hdc,SYSTEM_FONT);     //retrieve current hfont
  89.       SelectObject(hdc,hfont_main);                 //put it back
  90.       GetObject(hfont_main,sizeof(LOGFONT),&lf);
  91.  
  92.       //make the subscript/superscript height= 1/3 of the font height
  93.       //and create a new font with everything else the same as the
  94.       //current font.
  95.       lf.lfHeight*=(1.0/3.0);
  96.       hfont_subsuper=CreateFontIndirect(&lf);
  97.       hfont=NULL;
  98.  
  99.       //loop through all characters, switching fonts back & forth
  100.       //between normal and subscript/superscript font as required
  101.       for(i=0;i<strlen(text);i++){
  102.         p=pt;
  103.         if(text[i]==SUPERSCRIPT){
  104.         hfont=SelectObject(hdc,hfont_subsuper);
  105.         i++;
  106.         p.x=
  107.         p.y=
  108.         }else if(text[i]==SUBSCRIPT){
  109.         hfont=SelectObject(hdc,hfont_subsuper);
  110.         i++;
  111.         p.y=
  112.         p.y=
  113.         }
  114.         TextOut(hdc,p.x,p.y,&text[i],1);
  115.  
  116.         if(hfont!=NULL){
  117.           SelectObject(hdc,hfont_main);
  118.         }
  119.  
  120.         //for the rest, ignore (x,y) & keep track of (x,y) internally
  121.         if(i==0) SetTextAlign(hdc,old_align | TA_UPDATECP);
  122.     }
  123.  
  124.  
  125.  
  126. From: patrick@shamrck.ersys.edmonton.ab.ca (Patrick Arial):
  127.     Probably the easiest way to do this (and many other nifty
  128.     things) is to create a custom dialog control, and simply
  129.     have it process WM_PAINT messages.  It will only see a child
  130.     window that happens to be in your dialog box.  If you just
  131.     want static text, only process WM_CREATE, WM_PAINT, and
  132.     WM_DESTROY.
  133.  
  134.  
  135. From: "Pablo Ahumada M." <pam@vandi.ars.cl>
  136.    You can handle the WM_CTLCOLOR message. This message is sent
  137.    by the controls to his parent, the dialog box window.
  138.  
  139.       case WM_CTLCOLOR: {
  140.      HWND hControl = LOWORD(lParam);
  141.      WORD ControlId = GetWindowWord( hControl, GWW_ID );
  142.  
  143.      if( ControlID == MY_MATH_OBJECT )
  144.         SelectObject( wParam, hMySpecialFont );
  145.  
  146.      break;
  147.       }
  148.  
  149.  
  150. From: James A. O'Brien <obrien@pressure.eng.yale.edu>
  151.    I think I know how it can be done, but it's not pretty.  I did
  152.    subscripts for permanent static text controls by using a
  153.    separate static for each subscript!!!  You could probably do
  154.    greek letters the same way, by having several controls, and
  155.    sending WM_SETFONT to each when the dialog is started.  I
  156.    think that, to do a general solution (e.g. where you'd use a
  157.    TeX-like syntax), , you may have to do without a dialog, and
  158.    use a regular window with separate controls in it, and
  159.    subclass them to get the desired effects.
  160.    
  161.  
  162. From: Glenn Wallace <g.wallace@trl.oz.au>
  163.    Probably the most generic way to do it is to create your own
  164.    static text class, based on the Windows one (superclassed?)
  165.    with your own painting management, so you can set various
  166.    fonts for portions of the text.
  167.    
  168.    Does it have to be a dialog box? You could always do it as a
  169.    window and create the child windows (controls) manuaaly and
  170.    have your custom paint routines for them which are aware of
  171.    the fonts and stuff.
  172. -- 
  173. ------------------------------------------------------------------------
  174. E-mail: annef@dmp.csiro.au (preferred)     | If my opinions and those
  175. CIS   : 100033,3365 (infrequently read)    | of CSIRO coincide, it is
  176. Snail : CSIRO Division of Mineral Products | pure accident. I am not
  177.