IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: Haim on August 24, 2007, 07:21:39 AM

Title: Printer question
Post by: Haim on August 24, 2007, 07:21:39 AM
Hello,
I have two related questions:
1. is there a way to programmatically select and setup a printer of a known name (non default printer), without displaying the printdialog?
2. I would like to have the printdialog open with the values of the previous selection, and not with the values of the default printer. I think that I need to preserve the values of hdevnames and hdevmode between calls, but I do not know how to handle this.
Any help on those questions and examples    :-[  would be appreciated.

Haim



Title: Re: Printer question
Post by: srod on August 24, 2007, 10:09:58 AM
Hi,

I don't know how useful this will be because I do not know Aurora as yet and I don't know if Aurora's printer classes can do these things directly, but I've certainly done similar things with api. Can't seem to find the code, but my dodgy memory suggsts something like :

1) PrinterDC.l = CreateDC("WINSPOOL", Printername$,0,0)

    From here you can use StartDoc() and StartPage() as normal.

2) This is quite straight forward, only complicated by the fact that Windows insists on you placing the DEVMODE structure within a moveable global memory block. After you use the printdialog function for the first time (and for which you wish to retain the resulting DEVMODE structure) copy the resulting DEVMODE structure by using the following :


    Now when you next call printdialog, you'll need to copy your stored DEVMODE structure to a moveable global memory heap (use GlobalAlloc() with the GMEM_MOVEABLE flag and don't forget to lock and then unlock this memory block etc.) and store the handle (not the address) of this global memory block in the hDevMode field of the PRINTDLG structure.

  Repeating this for hDevNames is a little more complex because of the strings involved, but still very doable.
Title: Re: Printer question
Post by: Haim on August 24, 2007, 10:36:05 AM
Thanks,
I understand the methodology, but could not find a way to actually implement it.
i'll keep trying...


Haim
Title: Re: Printer question
Post by: srod on August 24, 2007, 12:30:10 PM
As I say I am pretty sure I've done this in the past (dodgy memory syndrome!) If not this then something very similar, but whatever it was I do recall that it worked okay.

I remember poking around and changing the orientation of the printed pages in the middle of a job by switching DEVMODE's for the printer dc etc. This involved grabbing a copy of the DEVMODE returned from the PrintDlg() api function etc.

Sorry I can't produce any Aurora code.
Title: Re: Printer question
Post by: Haim on August 24, 2007, 09:33:37 PM
I appreciate your help. It showed me that I was looking in the right direction.
What I need now is a way to save and restore the hdevmode and hdevnames structures.
I understand that what gets returned from printdialog are not pointers but rather handles...??
I have no idea how to proceed with those.

Can anyone come up with an example or functions for saving/restoring those handles?

Haim
Title: Re: Printer question
Post by: sapero on August 25, 2007, 01:27:27 AM
Here is the example - saving and loading HGLOBAL from file, without error checking.
Title: Re: Printer question
Post by: Haim on August 25, 2007, 01:49:10 AM
Thanks sapero,
I'll look into it more carefully later today.
Right now it seems to be just what I've been looking for.

Haim