This article uses the C language version of GDI + imitation C # text drawn example code:
# Include ".. /.. /samplecode/comcode/application. H "</P> <p> # pragma hdrstop </P> <p> wchar flowedtext1 [] = <br/> L" I went down to the St James infirmary, /n/<br/> saw my baby there,/n/<br/> stretched out on a long white table,/n/<br/> so sweet, so cold, so fair,/n/<br/> let her go, let her go, God bless her,/n/<br/> wherever she may be, /n/<br/> she can look this wide world over,/n/<br/> but she'll never find a sweet man like me, /n/<br/> when I die want you to dress me in straight when shoes,/n/<br/> I wanna a boxback coat and a Stetson hat, /n/<br/> put a twenty dollar gold piece on my watch chain,/n/<br/> so the boys'll know that I died standing up. "; </P> <p> wchar flowedtext2 [] = <br/> L "the sky seems full when you're in the cradle/n/<br/> the rain will fall and wash your dreams/n/<br/> stars are stars and they shine so hard... /n/<br/> now spit out the sky because its empty/n/<br/> and hollow and all your dreams are hanging out to dry/n/<br/> stars are stars and they shine so cold... /n/<br/> once I like crying twice I like laughter/n/<br/> come tell me what I'm after. "; </P> <p> wchar japanesetext [] ={< br/> 31169,123 98, 21517,210 69, 12399,124 63, <br/> 12522,124 73, 12391,123 77, 12290, 0 }; </P> <p> pgpbrush backgroundbrush; <br/> pgpbrush texttexturebrush; <br/> pgpbrush titleshadowbrush; <br/> pgpbrush lineargradbrush; </P> <p> pgpfonttitlefont; <br/> pgpfonttextfont; <br/> Upgrade; <br/> pgpfont japanesefont; </P> <p> void oncreate (void) <br/>{< br/> point PS [] ={{ 0, 0 },{ 0, 45 }}; <br/> pgpfontfamily seriffontfamily = fontfamilygenericserif (); </P> <p> // load the image to be used for the background from the EXE's resource fork <br/> pgpimage image = imagecreate (L ".. //.. // media // colorbars.jpg "); </P> <p> // now create the brush we are going to use to paint the background <br/> backgroundbrush = texturebrushcreate (image ); <br/> imagedelete (image ); </P> <p> // load the image to be used for the textured text from the EXE's resource fork <br/> image = imagecreate (L ".. //.. // media // marble.jpg "); <br/> texttexturebrush = texturebrushcreate (image); <br/> imagedelete (image ); </P> <p> // load the fonts we want to use <br/> thisfont = fontfromfamily (seriffontfamily, 20, 0, unitpoint ); <br/> titlefont = fontfromfamily (seriffontfamily, 60, 0, unitpoint); <br/> textfont = fontfromfamily (seriffontfamily, 11, 0, unitpoint ); </P> <p> // set up shadow brush-make it translucent <br/> titleshadowbrush = solidbrushcreate (setalpha (black, 70 )); </P> <p> // set up fonts and brushes for printing Japanese text <br/> japanesefont = fontcreate (L "Ms mincho", 36, 0 ); <br/> lineargradbrush = linebrushfrompoint (& PS [0], & PS [1], blue, red ); <br/>}</P> <p> void ondestroy (void) <br/>{< br/> brushdelete (texttexturebrush); <br/> brushdelete (backgroundbrush ); <br/> brushdelete (titleshadowbrush); <br/> brushdelete (lineargradbrush); </P> <p> fontdelete (titlefont); <br/> fontdelete (textfont ); <br/> fontdelete (thisfont); <br/> fontdelete (japanesefont); <br/>}</P> <p> void onpainting (HDC) <br/>{< br/> wchar s [40] = l "Hello symetrical world"; <br/> rect clientrect; <br/> rectf R; <br/> real center; <br/> int characters, lines; <br/> pgpstrformat format = strformatcreate (); <br/> pgpsolidbrush sb = solidbrushcreate (setalpha (white, 180); <br/> pgpgraphics G = graphicscreate (DC); </P> <p> graphicssettextrenderinghint (G, textrenderinghintantialias ); </P> <p> // fill the background use the texture brush <br/> // and then apply a white wash <br/> getclientrect (handle, & clientrect ); <br/> graphicsfillrectangle (G, backgroundbrush, clientrect. left, clientrect. top, clientrect. right, clientrect. bottom); <br/> graphicsfillrectangle (G, Sb, clientrect. left, clientrect. top, clientrect. right, clientrect. bottom); </P> <p> // simple draw Hello World <br/> solidbrushsetcolor (SB, black); <br/> graphicsdrawstringxy (G, L "Hello World", thisfont, Sb, 10, 10); </P> <p> // draw a textured string <br/> graphicsdrawstringxy (G, L "graphics samples", titlefont, titleshadowbrush, 15, 25); <br/> graphicsdrawstringxy (G, l "graphics samples", titlefont, texttexturebrush, 10, 20 ); </P> <p> // use measure string to display a string at the center of the window <br/> solidbrushsetcolor (SB, red ); <br/> center = clientrect. right/2.0f; <br/> graphicsmeasurestring (G, S, textfont, & R); <br/> graphicsdrawstringxy (G, S, textfont, Sb, center-R. width/2.0f, 10.0f); </P> <p> // now draw a string flowed into a rectangle <br/> r = makerectf (201_f, 1501_f, 2501_f, 300366f); <br/> solidbrushsetcolor (SB, gainsboro); <br/> graphicsfillrectanglef (G, Sb, R. x, R. y, R. width, R. height); <br/> solidbrushsetcolor (SB, blue); <br/> graphicsdrawstring (G, flowedtext1, textfont, Sb, & R, null ); </P> <p> // draw more flowed text but this time center it <br/> r = makerectf (4200000f, 1500000f, 2500000f, 3000000f ); <br/> solidbrushsetcolor (SB, gainsboro); <br/> graphicsfillrectanglef (G, Sb, R. x, R. y, R. width, R. height); <br/> strformatsetalignment (format, stringalignmentcenter); <br/> solidbrushsetcolor (SB, blue); <br/> graphicsdrawstring (G, flowedtext2, textfont, Sb, & R, format); </P> <p> // work out how many lines and characters we printed just now <br/> characters = lines = 0; <br/> graphicsmeasurestringsize (G, flowedtext2, textfont, <br/> 2500000f, 3000000f, format, & R, & characters, & lines); <br/> wsprintfW (S, L "We printed % d characters and % d lines", characters, lines); <br/> solidbrushsetcolor (SB, black); <br/> graphicsdrawstringxy (G, S, textfont, Sb, 390.0f, 00000000f ); </P> <p> // if we have the Japan Language Pack draw some text in Japan <br/> // rotate it to make life truly exciting <br/> graphicsrotate (g, -30, matrixorderprepend); <br/> graphicstranslate (G,-180,300, callback); <br/> graphicsdrawstringxy (G, japanesetext, japanesefont, lineargradbrush, 175,125 ); <br/> graphicsresettransform (g); </P> <p> strformatdelete (format); <br/> brushdelete (SB); <br/> graphicsdelete (g ); <br/>}</P> <p> winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) <br/>{< br/>/* The Double Buffer painting window is used here. You can change the 3rd parameters to false to compare the effect. */<br/> initapplication (hinstance, ncmdshow, true); <br/> createproc = oncreate; <br/> destroyproc = ondestroy; <br/> paintproc = onpaint; <br/> return runapplication (text ("C language gdiplus demo -- text (similar to C # example)"), 700,500); <br/>}< br/> // example //---------------------------------------------------------------------------
For the window framework code used by the example code and the GDI + C language version, see "using GDI + in C Windows Applications".
Run the following command:
Please send to: mao.maozefa@gmail.com, maozefa@hotmail.com