Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>textwidth() get a string's width in pixels</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 textwidth()             Get a String's Width in Pixels

 #include   <graphics.h>

 int far    textwidth(tstring);
 char far   *tstring;

    textwidth() gets the width of 'tstring' in pixels by using the length
    of 'tstring', the current text font size and multiplication factor.
    textheight() and textwidth() are used for sizing strings that need to
    be fit into existing spaces.

    Returns:     The text width in pixels.

   -------------------------------- Example ---------------------------------

    The following statements size the word "squeeze" and print it in a
    small box.

           #include <graphics.h>
           #include <conio.h>

           main()
           {
               int gdriver = DETECT;
               int gmode;
               char *txt = "Squeeze";

               initgraph(&gdriver,&gmode,"");
               settextjustify(CENTER_TEXT,CENTER_TEXT);
               settextstyle(SANS_SERIF_FONT,HORIZ_DIR,USER_CHAR_SIZE);
               setusercharsize(60,textwidth(txt),50,textheight(txt));
               settextstyle(SANS_SERIF_FONT,HORIZ_DIR,USER_CHAR_SIZE);
               rectangle(290,125,350,175);
               outtextxy(320,150,txt);
               getch();
               closegraph();
           }


See Also: gettextsettings() outtext() textheight()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson