font height & width


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 15 of 15

Thread: font height & width

  1. #1
    Shiva Prasad Guest

    font height & width

    hi,
    how can i calculate the font height & width if i do not have a DC. i
    require this to set the menu item width in WM_MEASUREITEM.

    thanks in advance.


    Bye
    Shiva



  2. #2
    Rob Teixeira Guest

    Re: font height & width



    You MUST have an HDC to get the *real* size of a font.
    In windows, you start the font creation process by filling a LOGFONT structure,
    which is basically the *ideal* picture of the font you want to use. When
    you select a font into an DC, the font mapper creates the real physical font,
    which may have different characteristics than the ones supplied in the LOGFONT
    structure due to what the DC supports and what the actual physical font is
    capable of.

    However, the LOGFONT does have a height and width that is independant of
    the real font in the DC (just remember that the real font may differ). This
    measurement is in logical units (em).

    You can get the menu font structure by calling SystemParametersInfo and requesting
    the non-client metrics. The NONCLIENTMETRICS structure contains a LOGFONT
    structure for the default menu font.

    Having said that, owner-drawn menus sizes are typically affected by other
    factors, such as a bitmap which may be 16x16 pixels and is typically bigger
    than a font character.

    -Rob

    "Shiva Prasad" <mshiva77@yahoo.com> wrote:
    >hi,
    > how can i calculate the font height & width if i do not have a DC. i
    >require this to set the menu item width in WM_MEASUREITEM.
    >
    >thanks in advance.
    >
    >
    >Bye
    >Shiva
    >
    >



  3. #3
    Rob Teixeira Guest

    Re: font height & width



    You MUST have an HDC to get the *real* size of a font.
    In windows, you start the font creation process by filling a LOGFONT structure,
    which is basically the *ideal* picture of the font you want to use. When
    you select a font into an DC, the font mapper creates the real physical font,
    which may have different characteristics than the ones supplied in the LOGFONT
    structure due to what the DC supports and what the actual physical font is
    capable of.

    However, the LOGFONT does have a height and width that is independant of
    the real font in the DC (just remember that the real font may differ). This
    measurement is in logical units (em).

    You can get the menu font structure by calling SystemParametersInfo and requesting
    the non-client metrics. The NONCLIENTMETRICS structure contains a LOGFONT
    structure for the default menu font.

    Having said that, owner-drawn menus sizes are typically affected by other
    factors, such as a bitmap which may be 16x16 pixels and is typically bigger
    than a font character.

    -Rob

    "Shiva Prasad" <mshiva77@yahoo.com> wrote:
    >hi,
    > how can i calculate the font height & width if i do not have a DC. i
    >require this to set the menu item width in WM_MEASUREITEM.
    >
    >thanks in advance.
    >
    >
    >Bye
    >Shiva
    >
    >



  4. #4
    Rob Teixeira Guest

    Re: font height & width



    Be careful! The menu font may not be the same as the form font

    -Rob

    "Roy" <iroy55@hotmail.com> wrote:
    >I believe there are 2 methods: TextHeight and TextWidth that apply to a
    >form, picturebox, printer, etc.
    >You may try this:
    >intFontHeight = Form1.TextHeight(mnuMenu.Caption)
    >
    >Roy
    >
    >"Shiva Prasad" <mshiva77@yahoo.com> wrote in message
    >news:3c3c2ce6@147.208.176.211...
    >> hi,
    >> how can i calculate the font height & width if i do not have a DC.

    i
    >> require this to set the menu item width in WM_MEASUREITEM.
    >>
    >> thanks in advance.
    >>
    >>
    >> Bye
    >> Shiva
    >>
    >>

    >
    >



  5. #5
    Rob Teixeira Guest

    Re: font height & width



    Be careful! The menu font may not be the same as the form font

    -Rob

    "Roy" <iroy55@hotmail.com> wrote:
    >I believe there are 2 methods: TextHeight and TextWidth that apply to a
    >form, picturebox, printer, etc.
    >You may try this:
    >intFontHeight = Form1.TextHeight(mnuMenu.Caption)
    >
    >Roy
    >
    >"Shiva Prasad" <mshiva77@yahoo.com> wrote in message
    >news:3c3c2ce6@147.208.176.211...
    >> hi,
    >> how can i calculate the font height & width if i do not have a DC.

    i
    >> require this to set the menu item width in WM_MEASUREITEM.
    >>
    >> thanks in advance.
    >>
    >>
    >> Bye
    >> Shiva
    >>
    >>

    >
    >



  6. #6
    Roy Guest

    Re: font height & width

    I believe there are 2 methods: TextHeight and TextWidth that apply to a
    form, picturebox, printer, etc.
    You may try this:
    intFontHeight = Form1.TextHeight(mnuMenu.Caption)

    Roy

    "Shiva Prasad" <mshiva77@yahoo.com> wrote in message
    news:3c3c2ce6@147.208.176.211...
    > hi,
    > how can i calculate the font height & width if i do not have a DC. i
    > require this to set the menu item width in WM_MEASUREITEM.
    >
    > thanks in advance.
    >
    >
    > Bye
    > Shiva
    >
    >




  7. #7
    Roy Guest

    Re: font height & width

    I believe there are 2 methods: TextHeight and TextWidth that apply to a
    form, picturebox, printer, etc.
    You may try this:
    intFontHeight = Form1.TextHeight(mnuMenu.Caption)

    Roy

    "Shiva Prasad" <mshiva77@yahoo.com> wrote in message
    news:3c3c2ce6@147.208.176.211...
    > hi,
    > how can i calculate the font height & width if i do not have a DC. i
    > require this to set the menu item width in WM_MEASUREITEM.
    >
    > thanks in advance.
    >
    >
    > Bye
    > Shiva
    >
    >




  8. #8
    dnagel Guest

    Re: font height & width

    In the past I have kept a hidden label control
    on the form. I would set the labels font and
    font.size to the values corresponding to the
    control in question. Then I would use the
    TextWidth and TextHeight functions to retrieve
    the values.

    D.

    "Shiva Prasad" <mshiva77@yahoo.com> wrote in message
    news:3c3c2ce6@147.208.176.211...
    > hi,
    > how can i calculate the font height & width if i do not have a DC. i
    > require this to set the menu item width in WM_MEASUREITEM.
    >
    > thanks in advance.
    >
    >
    > Bye
    > Shiva
    >
    >




  9. #9
    dnagel Guest

    Re: font height & width

    In the past I have kept a hidden label control
    on the form. I would set the labels font and
    font.size to the values corresponding to the
    control in question. Then I would use the
    TextWidth and TextHeight functions to retrieve
    the values.

    D.

    "Shiva Prasad" <mshiva77@yahoo.com> wrote in message
    news:3c3c2ce6@147.208.176.211...
    > hi,
    > how can i calculate the font height & width if i do not have a DC. i
    > require this to set the menu item width in WM_MEASUREITEM.
    >
    > thanks in advance.
    >
    >
    > Bye
    > Shiva
    >
    >




  10. #10
    Karl E. Peterson Guest

    Re: font height & width

    Hi Rob --

    > Be careful! The menu font may not be the same as the form font


    I thought he was doing owner-draw?

    Later... Karl
    --
    [Microsoft Basic: 1976-2001, RIP]




  11. #11
    Karl E. Peterson Guest

    Re: font height & width

    Hi Rob --

    > Be careful! The menu font may not be the same as the form font


    I thought he was doing owner-draw?

    Later... Karl
    --
    [Microsoft Basic: 1976-2001, RIP]




  12. #12
    Monte Hansen Guest

    Re: font height & width


    Ditto what Rob said.

    When calculating, you might keep in mind the height of the glyph, and a bold
    font (which may or may not affect the height). The bold font is to account
    for "default" items.

    sample Code:


    Dim Metrics As NONCLIENTMETRICS
    Dim Success As Boolean

    ' structure version REQUIRED
    Metrics.cbSize = Len(Metrics)

    ' Get system-defined menu font info
    Success = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, _
    Metrics.cbSize, Metrics, 0&)
    If Not Success Then
    ApiRaise Err.LastDllError, Module
    End If

    ' Set the default font
    With Metrics.lfMenuFont
    MyFontName = StrConv(.lfFaceName, vbUnicode)
    MyFontSize = (Abs(.lfHeight) * Screen.TwipsPerPixelY) / 20
    MyFontBold = (.lfWeight > 400)
    MyFontItalic = CBool(.lfItalic)
    MyFontStrikethrough = CBool(.lfStrikeOut)
    End With

    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    Monte Hansen
    http://KillerVB.com
    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+



    "Shiva Prasad" <mshiva77@yahoo.com> wrote:
    >hi,
    > how can i calculate the font height & width if i do not have a DC. i
    >require this to set the menu item width in WM_MEASUREITEM.
    >
    >thanks in advance.
    >
    >
    >Bye
    >Shiva
    >
    >



  13. #13
    Monte Hansen Guest

    Re: font height & width


    Ditto what Rob said.

    When calculating, you might keep in mind the height of the glyph, and a bold
    font (which may or may not affect the height). The bold font is to account
    for "default" items.

    sample Code:


    Dim Metrics As NONCLIENTMETRICS
    Dim Success As Boolean

    ' structure version REQUIRED
    Metrics.cbSize = Len(Metrics)

    ' Get system-defined menu font info
    Success = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, _
    Metrics.cbSize, Metrics, 0&)
    If Not Success Then
    ApiRaise Err.LastDllError, Module
    End If

    ' Set the default font
    With Metrics.lfMenuFont
    MyFontName = StrConv(.lfFaceName, vbUnicode)
    MyFontSize = (Abs(.lfHeight) * Screen.TwipsPerPixelY) / 20
    MyFontBold = (.lfWeight > 400)
    MyFontItalic = CBool(.lfItalic)
    MyFontStrikethrough = CBool(.lfStrikeOut)
    End With

    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    Monte Hansen
    http://KillerVB.com
    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+



    "Shiva Prasad" <mshiva77@yahoo.com> wrote:
    >hi,
    > how can i calculate the font height & width if i do not have a DC. i
    >require this to set the menu item width in WM_MEASUREITEM.
    >
    >thanks in advance.
    >
    >
    >Bye
    >Shiva
    >
    >



  14. #14
    Karl E. Peterson Guest

    Re: font height & width

    Which, if it is the case and a standard looking menu is desired, the NCMetrics.zip
    sample on my site (http://www.mvps.org/vb) will offer all needed clues to insure the
    simplest possible assignment.
    --
    [Microsoft Basic: 1976-2001, RIP]


    "Karl E. Peterson" <karl@mvps.org> wrote in message news:3c3cbc90@147.208.176.211...
    > Hi Rob --
    >
    > > Be careful! The menu font may not be the same as the form font

    >
    > I thought he was doing owner-draw?
    >
    > Later... Karl
    > --
    > [Microsoft Basic: 1976-2001, RIP]
    >
    >
    >



  15. #15
    Karl E. Peterson Guest

    Re: font height & width

    Which, if it is the case and a standard looking menu is desired, the NCMetrics.zip
    sample on my site (http://www.mvps.org/vb) will offer all needed clues to insure the
    simplest possible assignment.
    --
    [Microsoft Basic: 1976-2001, RIP]


    "Karl E. Peterson" <karl@mvps.org> wrote in message news:3c3cbc90@147.208.176.211...
    > Hi Rob --
    >
    > > Be careful! The menu font may not be the same as the form font

    >
    > I thought he was doing owner-draw?
    >
    > Later... Karl
    > --
    > [Microsoft Basic: 1976-2001, RIP]
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center