May 23, 2019, 07:36:30 am

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Printer question

Started by Haim, August 24, 2007, 07:21:39 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

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




srod

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 :


  • Use GlobalLock() on the hDevMode field of the PRINTDLG structure variable which you passed to PrintDialog().

  • Copy the resulting memory buffer to a DEVMODE structure

  • Use GlobalUnLock() on the hDevMode field of the PRINTDLG structure variable which you passed to PrintDialog().



    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.

Haim

Thanks,
I understand the methodology, but could not find a way to actually implement it.
i'll keep trying...


Haim

srod

August 24, 2007, 12:30:10 pm #3 Last Edit: August 24, 2007, 12:31:44 pm by srod
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.

Haim

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

sapero

August 25, 2007, 01:27:27 am #5 Last Edit: August 25, 2007, 01:32:11 am by sapero
Here is the example - saving and loading HGLOBAL from file, without error checking.

Haim

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