Jump to content
martin

printing using UDF and a dll

Recommended Posts

Hi, Martin!

How you know, I use your DLL with a Python's class, who wrapp PrintMG.dll.

In the header of the (Python's class) source, I quoted, only, "Martin from autoit's forums". Because I have no others infos.

Is it OK for you ?

** sorry for my bad english **

That's fine with me. You could give a link to this thread as well.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@progAndy

Is this not OK for you

; #FUNCTION# ====================================================================================================

; Name...........: _WinAPI_CreateDC
; Description ...: Creates a device context (DC) for a device using the specified name.
; Syntax.........: _WinAPI_CreateDC($sDriver, $sDevice)
; Parameters ....: $sDriver - Specifies driver name, "winspool" for printing, "display" for screen
; $sDevice - Specifies device name
; Return values .: Success - handle to a DC for the specified device
; ====================================================================================================

Func _WinAPI_CreateDC($sDriver, $sDevice)
Local $aResult
$aResult = DllCall("GDI32.dll", "hwnd", "CreateDC", "str", $sDriver, "str", $sDevice, "long", 0, "long", 0)
Return $aResult[0]
EndFunc ;==>_WinAPI_CreateDC

regards,

ptrex


Share this post


Link to post
Share on other sites

@progAndy

Is this not OK for you

; #FUNCTION# ====================================================================================================

; Name...........: _WinAPI_CreateDC
; Description ...: Creates a device context (DC) for a device using the specified name.
; Syntax.........: _WinAPI_CreateDC($sDriver, $sDevice)
; Parameters ....: $sDriver - Specifies driver name, "winspool" for printing, "display" for screen
; $sDevice - Specifies device name
; Return values .: Success - handle to a DC for the specified device
; ====================================================================================================

Func _WinAPI_CreateDC($sDriver, $sDevice)
Local $aResult
$aResult = DllCall("GDI32.dll", "hwnd", "CreateDC", "str", $sDriver, "str", $sDevice, "long", 0, "long", 0)
Return $aResult[0]
EndFunc ;==>_WinAPI_CreateDC

regards,

ptrex


Share this post


Link to post
Share on other sites

No, this is not enough :P I'd like to draw directly to the document with GDI-functions. This is not possible with this UDF. Now I'm trying to create one which uses the API directly, without a DLL. The problem is now, how to get the Page size :P


*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

Share this post


Link to post
Share on other sites

No, this is not enough :P I'd like to draw directly to the document with GDI-functions. This is not possible with this UDF. Now I'm trying to create one which uses the API directly, without a DLL. The problem is now, how to get the Page size :P

Can't you get that with GetDeviceCaps as done in GRS's UDF?

You can use the GDI functions with GRS's UDF. I've tried printing text and a curve and a screenshot using GDI with GRS's udf and it works fine. It would be better to use that than get the printer DC from my dll. The aim should be to get an AutoIt UDF which makes my dll redundant.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@martin

Would you be so kind to share these examples. It would save me the time to troubleshout this on my side.

@ProgAndy

A shortcut to the DC is using COM for the moment.

$commdlg1=ObjCreate("mscomdlg.commondialog") 
If Not IsObj($commdlg1) then Exit

$cdlPDReturnDC=256 
$cdlPDNoPageNums=8 
$cdlPDSelection=1 
$cdlPDAllPages=0 


$CommDlg1.Flags = $cdlPDReturnDC + $cdlPDNoPageNums 


If $CommDlg1.hdc < 0 Then Exit
$CommDlg1.ShowPrinter

So maybe it would be OK to combine COM and WinAPI to get it going.

regards,

ptrex


Share this post


Link to post
Share on other sites

The HDC from COM, that's possible with DLLcall, too :P

To GRS's UDF: I din't find that function, thats graet ! I'll use these functions to create a bigger Printing UDF :P


*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

Share this post


Link to post
Share on other sites

@martin

Would you be so kind to share these examples. It would save me the time to troubleshout this on my side.

ptrex

I posted an example in GRS's thread here.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@ProgAndy

The HDC from COM, that's possible with DLLcall, too

To GRS's UDF: I din't find that function, thats graet ! I'll use these functions to create a bigger Printing UDF

I was planning to start working on this. But since you guys are much more expierienced in this area, I will leave it to you.

I am sure you come up with a total replacement of Martin's DLL and the COM approach I showed. :P

@martin

Very nice. Thanks again.

regards,

ptrex


Share this post


Link to post
Share on other sites

Martin.. I have encountered a little issue with your dll file.

If I use _PrintSetPrinter($hp) and manaully choose the printer from the Windows Printer Selector then all of the printer settings are obeyed, eg the size and to show me a preview before it prints (epson driver prefference)

but if I use _PrintSelectPrinter($hp,"24x16") 24x16 is the name of the printer it ignores the settings and prints an A4 without showing me the preview (epson driver prefference)

#include 'printMGv2.au3';the print UDF
Global $hp
Local $mmssgg,$marginx,$marginy
$hp = _PrintDllStart($mmssgg);this must always be called first
if $hp = 0 then
    consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
    Exit
endif

;choose the printer if you don't want the default printer
;If _PrintSetPrinter($hp) = 0 then Exit Msgbox(0,"","Action Cancled");see also _PrinterSelectPrinter

_PrintSelectPrinter($hp,"24x16");Automatically choose the printer 24x16

_PrintPageOrientation($hp,1);set landscape printing
_PrintSetDocTitle($hp,"24x16")
_PrintStartPrint($hp)
$pght = _PrintGetpageheight($hp) - _PrintGetYOffset($hp)
$pgwd = _PrintGetpageWidth($hp) - _PrintGetXOffset($hp)

_PrintImage($hp,"24x16.jpg",_PrintGetXOffset($hp),_PrintGetYOffset($hp),$pgwd,$pght)
_PrintEndPrint($hp)
_PrintNewPage($hp);Not really needed if no more pages to be printed
_printDllClose($hp)

Any ideas.

Thanks

Chris

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Ahhh I have sussed out what is happening, when choosing manually the printer it uses the printing prefferences. When selecting automatically it is using the Printing defaults!

Yes. You could change the defaults of course but I don't think I know how to do that programmatically. I'll think about it, but don't be too hopeful :)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Yes. You could change the defaults of course but I don't think I know how to do that programmatically. I'll think about it, but don't be too hopeful :)

Rather than changing the defaults is it possible to use the printing preferences when _PrintSelectPrinter($hp,"24x16") or do you have to use defaults?

Something seems a bit wierd with the defaults, even though there (manaually) set the same as the preferences it prints slightly different.

Share this post


Link to post
Share on other sites

Rather than changing the defaults is it possible to use the printing preferences when _PrintSelectPrinter($hp,"24x16") or do you have to use defaults?

Something seems a bit wierd with the defaults, even though there (manaually) set the same as the preferences it prints slightly different.

I can set the various aspects of a printer and I can have a new function or extend the setprinter function.

I prefer not to try and set everything so I suggest I set only these properties

Orientation; (although there is already a function for this)

PaperSize; to predifined format eg A4, Letter Small etc,

PaperLength: overrides PaperSize

PaperWidth:overrides PaperSize

Scale:

Copies:

Colour or monochrome:

Bin Source?

Print quality?

Yuk, it goes on forever.

What do you think?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I can set the various aspects of a printer and I can have a new function or extend the setprinter function.

I prefer not to try and set everything so I suggest I set only these properties

Orientation; (although there is already a function for this)

PaperSize; to predifined format eg A4, Letter Small etc,

PaperLength: overrides PaperSize

PaperWidth:overrides PaperSize

Scale:

Copies:

Colour or monochrome:

Bin Source?

Print quality?

Yuk, it goes on forever.

What do you think?

I'm sure it could go on and on but it sounds good to me what your proposing.

The issue I have is that when using the printer preferences it obeys the Scale to Fill with no border (it's a large format Epson) when using the Defaults even though I tell it to fill the page it seems to refuse. I can tweak it by manually setting the offset value to 0 rather than using the function in the dll but it still leaves a slight border.

It would be great and very kind of you if you do get time to add these functions.

Chris

Share this post


Link to post
Share on other sites

I'm sure it could go on and on but it sounds good to me what your proposing.

The issue I have is that when using the printer preferences it obeys the Scale to Fill with no border (it's a large format Epson) when using the Defaults even though I tell it to fill the page it seems to refuse. I can tweak it by manually setting the offset value to 0 rather than using the function in the dll but it still leaves a slight border.

It would be great and very kind of you if you do get time to add these functions.

Chris

I don't really understand the problem I don't think. Why do you need scale to fit? Is your layout to a fixed format and size regardless of the printer paper?

If that is the case you would need to say "design width and height related to the paper width and height means I need a scaling factor of X%", and then you set that in the scaling parameter of this (fictitious at the moment) function. Is that correct?

I am not going to be able to have a scale-to-fit option. I have no idea how to do that and I don't intend to try to find out, although I'll listen to any suggestions.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I don't really understand the problem I don't think. Why do you need scale to fit? Is your layout to a fixed format and size regardless of the printer paper?

If that is the case you would need to say "design width and height related to the paper width and height means I need a scaling factor of X%", and then you set that in the scaling parameter of this (fictitious at the moment) function. Is that correct?

I am not going to be able to have a scale-to-fit option. I have no idea how to do that and I don't intend to try to find out, although I'll listen to any suggestions.

I can scale the image prior to printing it to make sure it is the right dimensions, your fictitious solution could help. It's hard to explain without seeing it. I don't have the printer here but I'll get a couple of screen shots next week of the preview.

When Manually selecting the printer from the dropdown box it uses the preferences and

$pght = _PrintGetpageheight($hp) - _PrintGetYOffset($hp)

$pgwd = _PrintGetpageWidth($hp) - _PrintGetXOffset($hp)

gives a different result to using the Defaults even though defaults and preferences are set the same. I guess this could be something strange with the printer driver?? I do some grabs and post them next week. Thanks

Share this post


Link to post
Share on other sites

Hi Martin, I have some screen grabs now.

post-7154-1222076607_thumb.jpg

Picture A is using the Printing Preferences and manually choosing the printer _PrintSetPrinter($hp)

Picture B is Setting the printer in the Code which seems to use the Defaults. _PrintSelectPrinter($hp,"24x36")

Picture C is Setting the printer in the Code which seems to use the Defaults but not asking the DLL for the Width and height and offset but manually setting the sizes.

You can see that the preferences and the Defaults are setup the same so I don't really understand why there is a difference.

This is the Code

#include 'printMGv2.au3';the print UDF
Global $hp
Local $mmssgg,$marginx,$marginy
$hp = _PrintDllStart($mmssgg);this must always be called first
if $hp = 0 then
    consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
    Exit
endif

;choose the printer if you don't want the default printer
;If _PrintSetPrinter($hp) = 0 then Exit Msgbox(0,"","Action Cancled");see also _PrinterSelectPrinter

_PrintSelectPrinter($hp,"24x36");Automatically choose the printer 24x36

_PrintPageOrientation($hp,1);set landscape printing
_PrintSetDocTitle($hp,"24x36")
_PrintStartPrint($hp)
$pght = _PrintGetpageheight($hp) - _PrintGetYOffset($hp)
$pgwd = _PrintGetpageWidth($hp) - _PrintGetXOffset($hp)
;Msgbox(0,"",$pgwd & "x" & $pght)
_PrintImage($hp,"24x36.jpg",_PrintGetXOffset($hp),_PrintGetYOffset($hp),$pgwd,$pght);0,0,2160,2790); << Manual settings
_PrintEndPrint($hp)
_PrintNewPage($hp);Not really needed if no more pages to be printed
_printDllClose($hp)

This was why I was asking if it is possible to set the printer in the code but get it to use the preferences method rather than the defaults.

Cheers

Chris

Share this post


Link to post
Share on other sites

Hi Martin, I have some screen grabs now.

post-7154-1222076607_thumb.jpg

Picture A is using the Printing Preferences and manually choosing the printer _PrintSetPrinter($hp)

Picture B is Setting the printer in the Code which seems to use the Defaults. _PrintSelectPrinter($hp,"24x36")

Picture C is Setting the printer in the Code which seems to use the Defaults but not asking the DLL for the Width and height and offset but manually setting the sizes.

You can see that the preferences and the Defaults are setup the same so I don't really understand why there is a difference.

This is the Code

#include 'printMGv2.au3';the print UDF
Global $hp
Local $mmssgg,$marginx,$marginy
$hp = _PrintDllStart($mmssgg);this must always be called first
if $hp = 0 then
    consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
    Exit
endif

;choose the printer if you don't want the default printer
;If _PrintSetPrinter($hp) = 0 then Exit Msgbox(0,"","Action Cancled");see also _PrinterSelectPrinter

_PrintSelectPrinter($hp,"24x36");Automatically choose the printer 24x36

_PrintPageOrientation($hp,1);set landscape printing
_PrintSetDocTitle($hp,"24x36")
_PrintStartPrint($hp)
$pght = _PrintGetpageheight($hp) - _PrintGetYOffset($hp)
$pgwd = _PrintGetpageWidth($hp) - _PrintGetXOffset($hp)
;Msgbox(0,"",$pgwd & "x" & $pght)
_PrintImage($hp,"24x36.jpg",_PrintGetXOffset($hp),_PrintGetYOffset($hp),$pgwd,$pght);0,0,2160,2790); << Manual settings
_PrintEndPrint($hp)
_PrintNewPage($hp);Not really needed if no more pages to be printed
_printDllClose($hp)

This was why I was asking if it is possible to set the printer in the code but get it to use the preferences method rather than the defaults.

Cheers

Chris

Is there a difference in the page layout between prefences and defaults?

At the moment I have no idea how to find the preferences but I'll try to find out.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Is there a difference in the page layout between prefences and defaults?

At the moment I have no idea how to find the preferences but I'll try to find out.

No unfortunately there isn't I've been through it loads of times to check, all I can see is _PrintSetPrinter($hp) uses printing preferences and _PrintSelectPrinter($hp,"24x36") uses printing defaults.

The only other thing I was thinking was can you send the paper size to it?

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...