-
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
-
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
>
>
-
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
>
>
-
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
>>
>>
>
>
-
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
>
>
-
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]
-
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]
>
>
>
-
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
>
>
-
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
>
>
-
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
>
>
-
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
>>
>>
>
>
-
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
>
>
-
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]
-
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]
>
>
>
-
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
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks