I have a C++ Win DLL with some functions that I'm calling from VBA. One of
the functions creates BMP with a text that I send from VBA. Now, I can find
the width and height (in pixels or inches) of a string in MS Word (get hDC
of a screen, create a specific font, get a font in hDC with SelectObject and
find what I need with GetTextExtentPoint32), but how to do the same thing
for a string that will be part of a BMP?
This is the function that needs to be changed.
Private Function DimText(Text As String, fontName As String, _
fontSize As Double, Optional Bold As Boolean, _
Optional Italic As Boolean) As SDimText
Dim hFont As Long, hdc As Long
Dim PixpInch As Double
On Error GoTo LocalError
hdc = GetDC(0)
PixpInch = GetDeviceCaps(hdc, 90) / 72
DimText.PixInch = PixpInch
hFont = CreateFontA(-fontSize * PixpInch, 0, 0, 0, _
400 - 300 * Bold, -Italic, 0, 0, 1, 0, 0, 0, 0, fontName)
If hFont Then
SelectObject hdc, hFont
GetTextExtentPoint32A hdc, Text, Len(Text), DimText
Release o, hdc
MsgBox Err.Description, vbExclamation, "DimText"
SDimText = 0
I think that I should get the BMP in hDC and create a font in there but I
just can't figure out how. I have BMP ready on the disk but I would prefer
not to use "LoadImage" or "LoadPicture" if that is possible.