|
-
July 4th, 2001, 12:57 AM
#1
Problem with API GetDC
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
-
July 4th, 2001, 03:23 AM
#2
Re: Problem with API GetDC
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
-
July 4th, 2001, 03:45 AM
#3
Re: Problem with API GetDC
Hi Duncan,
Any thanx since my code is working fine, in don't know what was the problem with that.
Regards,
Mahesh
-
July 4th, 2001, 03:46 AM
#4
Re: Problem with API GetDC
Hi Duncan,
Anyway thanx since my code is working fine, I don't know what was the problem with that.
Regards,
Mahesh
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
|
Click Here to Expand Forum to Full Width
|