Click to See Complete Forum and Search --> : Problem with API GetDC


mpbalshetwar
July 4th, 2001, 12:57 AM
Hi All,
Actually i am trying to send the form name to this procedure, but i am geting error saying Type mismatch.

Public Function GetFontDialogUnits() As Long

Dim hFont As Long
Dim hFontOld As Long
Dim r As Long
Dim avgWidth As Long
Dim hDc As Long
Dim tmp As String
Dim sz As SIZE

'get the hdc to the main window
hDc = GetDC(Form1.hwnd)

'with the current font attributes, select the font
hFont = GetStockObject(ANSI_VAR_FONT)
hFontOld = SelectObject(hDc, hFont&)

'get its length, then calculate the average character width
tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
GetTextExtentPoint32(hDc, tmp, 52, sz)
avgWidth = (sz.cx \ 52)

're-select the previous font & delete the hDc
SelectObject(hDc, hFontOld)
DeleteObject(hFont)
ReleaseDC(Form1.hwnd, hDc)

'return the average character width
GetFontDialogUnits = avgWidth

End Function


Please help is needed.

Mahesh

Clearcode
July 4th, 2001, 03:23 AM
public Function GetFontDialogUnits(byval frmIn as Form) as Long

Dim hFont as Long
Dim hFontOld as Long
Dim r as Long
Dim avgWidth as Long
Dim hDc as Long
Dim tmp as string
Dim sz as SIZE

'get the hdc to the main window
hDc = GetDC(frmIn.hwnd)

'with the current font attributes, select the font
hFont = GetStockObject(ANSI_VAR_FONT)
hFontOld = SelectObject(hDc, hFont&)

'get its length, then calculate the average character width
tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
GetTextExtentPoint32(hDc, tmp, 52, sz)
avgWidth = (sz.cx \ 52)

're-select the previous font & delete the hDc
SelectObject(hDc, hFontOld)
DeleteObject(hFont)
ReleaseDC(frmIn.hwnd, hDc)

'return the average character width
GetFontDialogUnits = avgWidth

End Function




To use:

Debug.print GetFontDialogUnits(Form1)




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

mpbalshetwar
July 4th, 2001, 03:45 AM
Hi Duncan,
Any thanx since my code is working fine, in don't know what was the problem with that.

Regards,
Mahesh

mpbalshetwar
July 4th, 2001, 03:46 AM
Hi Duncan,
Anyway thanx since my code is working fine, I don't know what was the problem with that.

Regards,
Mahesh