Jump to content

GDI UDFs


ProgAndy
 Share

Recommended Posts

GDI UDFs - Alpha release

This is a collection of the GDI functions listed in MSDN. From time to time I will add new functions and add descriptions to the undocumented functions.

Some of the functions already exist in WinAPI.au3, but I want to include all functions listed on MSDN as GDI.

The functions are written by Greenhorn, me and some copied from WinAPI.au3 (Gary Frost, Paul Campbell (PaulIA), Zedna) or the forum.

The donwload is located here:

GDI UDFs Downloads:Posted Image

To inlcude the UDFs you have 2 possibilities:

-just include GDI.au3 and all functions are accesible

-or inlcude GDIBase.au3, the GDIConstants.au3, GDIStructures.au3 and the Scripts from the GDI-subfolder as you need them (less overhead).

thanks to all helping me with these UDfs and merry x-mas Posted Image

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Here is an example to print a Textfile / text in a EditBox:

#include<GDI\GDI.au3>
#include<Memory.au3>
#include<Misc.au3>

;-------------------------------------
; GUI to get text
GUICreate("Your text to print",400,440)
$Edit = GUICtrlCreateEdit("",0,0,400,400)
$BTN = GUICtrlCreateButton("OK",10,405,80,30)
$Select = GUICtrlCreateButton("... Choose File",100,405,80,30)
GUISetState()

While 1
    $nMSG = GUIGetMsg()
    Switch $nMSG
        Case -3 ; $GUI_EVENT_CLOSE
            Exit ; exit
        Case $BTN
            ExitLoop ; Exit GUI loop and start to print
        Case $Select
            ; choose a textfile
            $Path = FileOpenDialog("Open Textfile",@MyDocumentsDir,"Text (*.txt)|All (*.*)","",3)
            If Not @error Then GUICtrlSetData($Edit,FileRead($Path))
        EndSwitch
WEnd
GUISetState(@SW_HIDE)
; End GUI ---------------------------------------

; Get text to print
Global Const $PRINTTEXT = GUICtrlRead($Edit)

; Printing
SplashTextOn("Printing...","Printing text",200,50,10,10,16,"",12,1000)

; show Printer dialog
$PrinterStruct = _GDI_PrintDlg()
If @error Then
; on error free all memory possibly allocated by _GDI_PrintDlg
        If DllStructGetData($PrinterStruct, "hDC") Then _GDI_DeleteDC(DllStructGetData($PrinterStruct, "hDC"))
        _MemGlobalFree(DllStructGetData($PrinterStruct, 3))
        _MemGlobalFree(DllStructGetData($PrinterStruct, 4))
        Exit ; then Exit
EndIf
    
; get the DC handle for Printer DC  
Local $pDC = DllStructGetData($PrinterStruct, "hDC")
If $pDC Then
    ; If it is a valid DC then print
    
    $TotalHeight = _GDI_GetDeviceCaps($pDC, $PHYSICALHEIGHT)   ; the total height of the page in pixels
    $TotalWidth = _GDI_GetDeviceCaps($pDC, $PHYSICALWIDTH)     ; the total wodth in pixels
    $PrintOffsetX = _GDI_GetDeviceCaps($pDC, $PHYSICALOFFSETX) ; x-offset of printable area
    $PrintOffsetY = _GDI_GetDeviceCaps($pDC, $PHYSICALOFFSETY) ; y-offset of printable area
    $PrintableWidth = _GDI_GetDeviceCaps($pDC, $HORZRES)       ; the printable width
    $PrintableHeight = _GDI_GetDeviceCaps($pDC, $VERTRES)      ; the printable height
    If $PrintOffsetX = 0 Then ; at least 50 px border
        $PrintOffsetX = 50
        $PrintableWidth -= 50
    EndIf
    If $PrintOffsetY = 0 Then ; at least 50 px border
        $PrintOffsetY = 50
        $PrintableHeight -= 50
    EndIf
    
    ; set Info for Document (title shown in Print Spooler)
    $DocumentInfo = DllStructCreate($tagDOCINFO)
    DllStructSetData($DocumentInfo, 1, DllStructGetSize($DocumentInfo))
    $DocName = _PrintUDF_CreateTextStruct("Test Doc") ; we need an extra struct for the text
    DllStructSetData($DocumentInfo, "lpszDocName", DllStructGetPtr($DocName)) ; set the text-pointer to the Infostruct
    
    ; Structure for printing of multiple pages
    $DRAWTEXTPARAMS = DllStructCreate($tagDRAWTEXTPARAMS)
    DllStructSetData($DRAWTEXTPARAMS,1,DllStructGetSize($DRAWTEXTPARAMS)) ; initialise ParamStruct
    DllStructSetData($DRAWTEXTPARAMS,2,4) ; set size of tabstob to 4 characters
    
    ; rectangel in wich to print text
    $RECT = DllStructCreate($tagRECT)
    DllStructSetData($RECT,1,$PrintOffsetX)   ; left border: x-offset
    DllStructSetData($RECT,2,$PrintOffsetY)   ; top border: y-offset
    DllStructSetData($RECT,3,$PrintableWidth) ; width: printable width
    DllStructSetData($RECT,4,$PrintableHeight); width: printable height
    
    ; start printing
    _GDI_StartDoc($pDC, $DocumentInfo)
    
    ; Choose a font
    $Font = _ChooseFont("Arial",12)
    ;If no font chosen (Cancel), set default values:
    If Not IsArray($Font) Then Dim $Font[8] = [7,0,"Arial",11,400,0,"000000","000000"]
    
    ; set font color
    _GDI_SetTextColor($pDC,$Font[5])
    ; create font and set it as default in printer DC
    $hFont = _GDI_CreateFont(_FonSizePT($pDC,$Font[3]),0,0,0,$Font[4],BitAND($Font[1],2)=2,BitAND($Font[1],4)=4,BitAND($Font[1],8)=8,1, $OUT_TT_PRECIS, $CLIP_DEFAULT_PRECIS, $ANTIALIASED_QUALITY, $DEFAULT_PITCH, $Font[2])
    $hOldFont = _GDI_SelectObject($pDC,$hFont)
    
    ; Get Text to print
    $Text = $PRINTTEXT
    ; chack, if text is empty
    If $Text="" Then
        If MsgBox(36, 'Warning', "No text to print. Abort?")=6 Then
            ; if Printing should be aborted, abort it ;)
            _GDI_AbortDoc($pDC)
        Else
            $Text = " "; space, so it will print
        EndIf
    EndIf
    
    While $Text
        ; while text is not empty, print a new page
        _GDI_StartPage($pDC)
            ; draw the text on the page
            _GDI_DrawTextEx($pDC,$Text,$RECT,BitOR($DT_WORDBREAK,$DT_NOPREFIX,$DT_TABSTOP,$DT_EDITCONTROL),$DRAWTEXTPARAMS,StringLen($Text))
        _GDI_EndPage($pDC)
        ; remove the drawn text from buffer
        $Text = StringTrimLeft($Text,DllStructGetData($DRAWTEXTPARAMS,"uiLengthDrawn"))
    WEnd

    ; delete font -> clean up resources
    _GDI_SelectObject($pDC,$hOldFont)
    _GDI_DeleteObject($hFont)
    
    ; end printing, printer can now print your Doc
    _GDI_EndDoc($pDC)
    
EndIf
; free memory allocated by _GDI_PrintDlg
_MemGlobalFree(DllStructGetData($PrinterStruct, 3))
_MemGlobalFree(DllStructGetData($PrinterStruct, 4)) 

; calcualte font size for printer (from MSDN)
; by Prog@ndy
Func _FonSizePT($pDC, $Pt)
    Return -_MulDiv($Pt, _GDI_GetDeviceCaps($pDC, $LOGPIXELSY), 72)
EndFunc   ;==>_FonSizePT
; Function to muliply and divide in ine step, from MSDN
; by Prog@ndy
Func _MulDiv($nNumber, $nNumerator, $nDenominator)
    Local $res = DllCall("Kernel32.dll", "int", "MulDiv", "int", $nNumber, "int", $nNumerator, "int", $nDenominator)
    If @error Then Return SetError(1, 0, 0)
    Return $res[0]
EndFunc   ;==>_MulDiv
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Well, i saw multiple posts asking for a way to print long text documents on multiple pages. But you are right is is a bit complicated, so i added some comments :)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Link to comment
Share on other sites

no, this should be abortdoc, but this func is new and not yet included in the download. Will update it in a few minutes.

//Edit: updated.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

very nice, thank you. very good work.

i'm still waiting for someone to write a gdi tutorial. i think progandy is one of the few qualified members here.

another idea of mine is to make an UDF for easy creation of basic gdi structures. for example, a _GDI_GUICtrlCreateButton function that includes and combines all the necessary processes. of course, all parameters like text, color, font, background.... must be passed in one command (this might afford a completely new syntax, but why not ?).

maybe anyone feels like starting something like that ?

cheers j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

  • 10 months later...

I'm trying to download but I can only download 31 KB of 104.11 KB

:)

Thanks for information. I reuploaded it and now it works for me. Sorry for the corrupted file, I didn't check all downloads after the relaunch of my site.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 2 years later...

ProgAndy, please re-upload the UDF. The page displays a 404 error.

Thanx again

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

Another

ProgAndy, please re-upload the UDF. The page displays a 404 error.

Thanx again

Another link I forgot to update. I'll get my old domain back :oops:

And on my computer ESET blocked that URL as it's web on list of webs with potentialy dangerous content.

Strange, i don't know why.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 6 years later...

Hi there ProgAndy,

I know this is an old thread, but I'm trying to print something to a label printer and wanted to use your GDI UDF. Your site seems down or may have changed.

Is this UDF still available, useable?

Thank you

Nicdev

Life is too short to worry about the things you don't have or cannot do ... So if you don't know how to do it - Learn it! Don't be afraid to ask for help ...

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...