Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set font to window

23 views
Skip to first unread message

Marco Filippini

unread,
Oct 20, 1999, 3:00:00 AM10/20/99
to
I've developed a StatusBar control in VB using the UserControl.
The UserControl is the parent for the newly created window based on the
windows common controls.
The user of the control can select a font using the standard dialog box
provided by the common dialog control and the font informations are returned
with an StdFont object.
It seems that the selected font is assigned to the UserControl window
instead of his child window (the status bar) and this is not a great
surprise to me.
How could I set the choosen font to the child window ?
Following is a code snippet that doesn't work, what's wrong ?

Private Sub SetFont(ByVal objFont As Font)
Dim lngHDC As Long
Dim lngFont As Long
Dim lngInd1 As Long
Dim typLogFont As LOGFONT

lngHDC = GetDC(lngHandle)

For lngInd1 = 1 To Len(objFont.Name)
typLogFont.lfFaceName(lngInd1) = Asc(Mid$(objFont.Name, lngInd1, 1))
Next lngInd1
' typLogFont.lfFaceName = StrConv(objFont.Name, vbFromUnicode)
typLogFont.lfWeight = objFont.Weight
typLogFont.lfItalic = objFont.Italic
typLogFont.lfUnderline = objFont.Underline
typLogFont.lfStrikeOut = objFont.Strikethrough
typLogFont.lfCharSet = objFont.Charset
lngFont = CreateFontIndirect(typLogFont)
lngReturnValue = SelectObject(lngHDC, lngFont)
lngReturnValue = DeleteObject(lngFont)

lngReturnValue = ReleaseDC(lngHandle, lngHDC)
End Sub

Thank U in advance, Marco


Jim Deutch

unread,
Oct 20, 1999, 3:00:00 AM10/20/99
to
Marco, please don't post to so many newsgroups. In particular,
"general.discussion" is for topics that don't fit into any other category,
so if you're posting to any specific group, the general group is not
appropriate....

You've posted some code, here, from which I infer that you are primarily a C
programmer. But you've left out the one critical bit: lngHandle must have
larger scope than we see here, and we have no idea where it is assigned.
Just put the right window handle into it and it should work fine. Creating
your own windows in VB is somewhat fraught, but whatever floats your boat...

Jim Deutch
MS Dev MVP

Marco Filippini wrote in message
<#UnV9RxG$GA....@cppssbbsa02.microsoft.com>...

0 new messages