Thread: How to know the name of the font face of an edit control?

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310

    How to know the name of the font face of an edit control?

    How do I know the name of the font face of an edit control (not richedit) ?

    Thanks!
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    GetTextFace - you can get the edit control's device context with GetDC but don't forget to ReleaseDC when done with it.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I don't think that will work as the edit control uses a common (shared) device context. GetDC documentation says:
    For class and private DCs, GetDC leaves the previously assigned attributes unchanged. However, for common DCs, GetDC assigns default attributes to the DC each time it is retrieved. For example, the default font is System, which is a bitmap font. Because of this, the handle for a common DC returned by GetDC does not tell you what font, color, or brush was used when the window was drawn.
    I learnt this the hard way when coding this.

    Another approach that may work would be:
    - Call WM_GETFONT to get a font handle.
    - If that returns NULL, call GetStockObject with SYSTEM_FONT to get a font handle.
    - Call GetObject to get the LOGFONT data for the font, which includes the font name.

  4. #4
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    ok:
    Code:
    font = (HFONT)SendMessage(hEdit, WM_GETFONT, 0, 0);
    GetObject(font, sizeof(LOGFONT), &lf);
    wsprintf(x, "Tamaño: %i\nTipo: %s", lf.lfHeight, lf.lfFaceName);
    MessageBox(hWnd, x, "Tetas", 64);
    Working! Thanks
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing from a Rich Edit control
    By JustMax in forum Windows Programming
    Replies: 10
    Last Post: 02-14-2009, 07:12 PM
  2. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 05:36 PM
  3. Get Notified of ENTER in single line EDIT control
    By Morpheus in forum Windows Programming
    Replies: 1
    Last Post: 06-29-2002, 07:07 PM
  4. Controlling an edit control
    By master5001 in forum Windows Programming
    Replies: 2
    Last Post: 10-16-2001, 03:08 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 02:12 AM