AndyS01 Posted April 18, 2011 Share Posted April 18, 2011 (edited) I'm trying to create a UDF with some printer function calls that are not currently in WinAPI.au3, that are specific to the printer, and I've been successful in all except setting the printer font (name, size)In my function, I tried to use a DLL call to call the GDI21.dll at the SelectFontLocal entry point, but it doesn't seem to do anything (I didn't get an error either).The call looks like this: $aResult = DllCall("GDI32.dll", "long", "SelectFontLocal", "HANDLE", $font, "HANDLE", $font)The bottom line is that I want to set my printer font, and if I have to use a DLL call, I want it to call a generally installed DLL (like GDI32.dll) Because of this restriction, I cannot use the _PrintSetFont() function in the PrintMGv2.au3 UDF file.I have this restriction because I want to compile my .au3 file and send the .exe file to others, but I don't want to have to have them install a special dll.Here's a code snippette:expandcollapse popup; #FUNCTION# ===================================================================== ; Name ..........: _Printer_GetFont ; Description ...: Create a font in the desired family and size. ; Syntax ........: _Printer_GetFont([$sFontName = 'Times New Roman'[, $DESIREDFONTSIZE = 12[, $bBold = False[, $bItalic = False[, $bUnderLine = False[, $bStrikeout = False]]]]]]) ; $sFontName - Font family name ; $DESIREDFONTSIZE - Desired point size. ; $bBold - Bold if true. ; $bItalic - Italicize if true. ; $bUnderLine - Underline if true. ; $bStrikeout - Strikeout if true. ; Return values .: Success - Handle to the font. ; Failure - 0 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: Wrapper around _WinAPI_CreateFont ; Related .......: _WinAPI_CreateFont, _Printer_GetFontIndirect, _Printer_GetFontRotated ; Link ..........: ; Example .......: [yes/no] ; ================================================================================ Func _Printer_GetFont( _ $sFontName = 'Times New Roman', _ $DESIREDFONTSIZE = 12, _ $bBold = False, _ $bItalic = False, _ $bUnderLine = False, _ $bStrikeout = False) Local $iFontWeight, $iWidth, $hFontHandle If $bBold = True Then $iFontWeight = $FW_BOLD Else $iFontWeight = $FW_NORMAL EndIf ConsoleWrite("+++: $iFontWeight = " & $iFontWeight & @CRLF) ConsoleWrite("+++: $g__TwipsPerPixelY = " & $g__TwipsPerPixelY & @CRLF) $iWidth = (($DESIREDFONTSIZE * 16) / $g__TwipsPerPixelY) ConsoleWrite("+++: $iWidth = " & $iWidth & @CRLF) $iWidth = 18 ConsoleWrite("+++: $iWidth = " & $iWidth & @CRLF) $hFontHandle = _WinAPI_CreateFont( _ $iWidth, _ ;~ height of font 0, _ ;~ average character width 0, _ ;~ angle of escapement 0, _ ;~ base-line orientation angle 0, _ ;~ font weight $bItalic, _ ;~ italic attribute option $bUnderLine, _ ;~ underline attribute option $bStrikeout, _ ;~ strikeout attribute option $DEFAULT_CHARSET, _ ;~ character set $OUT_DEFAULT_PRECIS, _ ;~ output precision $CLIP_DEFAULT_PRECIS, _ ;~ clipping precision $DEFAULT_QUALITY, _ ;~ output quality $DEFAULT_PITCH, _ ;~ pitch and family of the font $sFontName _ ;~ typeface name ) ConsoleWrite("+++: 0x" & Hex($hFontHandle) & " returned from call to _WinAPI_CreateFont()" & @CRLF) Return ($hFontHandle) ; Return the handle to the created font (or 0) EndFunc ;==>_Printer_GetFont ; #FUNCTION# ===================================================================== ; Name ..........: _Printer_SetFontNameAndSize ; Description ...: Create a font in the desired family and size. ; Syntax ........: __Printer_SetFontNameAndSize($name = "Times New Roman", $size = 12) ; Parameters ....: ; $sFontName - Font family name ; $DESIREDFONTSIZE - Desired point size. ; Return values .: Success - Handle to the font. ; Failure - 0 ; Author ........: Andy Scharmer (AndyS01) ; ================================================================================ Func _Printer_SetFontNameAndSize($name = "Times New Roman", $size = 12) ConsoleWrite("+++: _Printer_SetFontNameAndSize(" & $name & ", " & $size & ") entered" & @CRLF) Local $font, $aResult, $err if ($name == Default) or ($name == "") Then $name = "Times New Roman" $font = _Printer_GetFont($name, $size) ; Create a font context to use ConsoleWrite("+++: $font = 0x" & Hex($font) & @CRLF) ; Call SelectFontLocal() in the GDI32.dll DLL to set the cprinter to this font #cs ; (this doesn't work right now) SelectFontLocal(HFONT Currenthfnt, HFONT newhfnt) #ce $aResult = DllCall( _ "GDI32.dll", _ "long", "SelectFontLocal", _ ;~ ??? not sure about the 'long' param "HANDLE", $font, _ ;~ ??? not sure about the 'HANDLE' param "HANDLE", $font _ ;~ ??? not sure about the 'HANDLE' param ) $err = @error ConsoleWrite("+++: " & $err & " returned from a call to SelectFontLocal in GDI32.dll" & @CRLF) ; Debugging only: _ArrayDisplay($aResult, "$aResult") EndFunc ;==>_Printer_SetFontNameAndSize Edited April 19, 2011 by AndyS01 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now