Thread: DirectX _8_ - text width

  1. #1
    Registered User
    Join Date
    Aug 2010

    DirectX _8_ - text width

    Hi there,

    Because of some reason, I am forced to use a couple of old DirectX 8 methods. I need to obtain somehow width of a given string in pixels. I'm using ID3DXFont interface, and create my font this way:

                LOGFONT desc;
                desc.lfHeight = _FontHeight;
                desc.lfWidth = 0;
                desc.lfEscapement = 0;
                desc.lfOrientation = 0;
                desc.lfWeight = FT_NORMAL;
                desc.lfItalic = FALSE;
                desc.lfUnderline = FALSE;
                desc.lfStrikeOut = FALSE;
                desc.lfCharSet = ANSI_CHARSET;
                desc.lfOutPrecision = OUT_TT_PRECIS;
                desc.lfClipPrecision = CLIP_DEFAULT_PRECIS;
                desc.lfQuality = ANTIALIASED_QUALITY;
                desc.lfPitchAndFamily = FF_DONTCARE | DEFAULT_PITCH;
                std::strcpy(desc.lfFaceName, "Courier New");
                D3DXCreateFontIndirect(device, &desc, &font);
    In DirectX 9 it's trivial to obtain HDC via GetDC method and then use GetTextExtentPoint32, but in D3D8 there is no such method.

    Is there any way to obtain the text width? Or is there any way to obtain the DC? I know that I can create a GDI font, but such a solution is not good from my point of view (but if noone can come up with a better idea, I will do this).

  2. #2
    Registered User
    Join Date
    Aug 2010
    Ok, problem solved.
    I've found out that in the case of directx 8, D3DXCreateFont accepts a HFONT parameter, thus I don't need to create two separate GDI objects.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unexplained "unhandled exception"
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 04-19-2007, 11:19 AM
  2. ChangeDisplaySettings - Blank?
    By Tonto in forum Windows Programming
    Replies: 13
    Last Post: 12-26-2006, 04:17 PM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  4. Replies: 1
    Last Post: 07-13-2002, 05:45 PM
  5. displaying text with DirectX
    By MechanicX in forum Game Programming
    Replies: 4
    Last Post: 09-24-2001, 06:28 PM