.net PrinterSettings

Posted by joey eisma on 05-May-2016 16:23

hi,

DEFINE VARIABLE bOK AS LOGICAL NO-UNDO.

SYSTEM-DIALOG PRINTER-SETUP UPDATE bOK.
if not bOk then
    return.

i'm hoping to manage those settings using .Net class.

def var ps as System.Drawing.Printing.PrinterSettings.
ps = new System.Drawing.Printing.PrinterSettings().

ps:SetHdevmode (new System.IntPtr(SESSION:PRINTER-CONTROL-HANDLE)).

MESSAGE ps:Copies
VIEW-AS ALERT-BOX INFO BUTTONS OK.

above does not return the copies i selected. i always get 1. any ideas why?

P.S.

KB 000028234 does not work in some scenario

.Net's PrintDialog takes a minute to load on a citrix session. however, it does give me the information that i need on any scenario.

All Replies

Posted by Matt Gilarde on 05-May-2016 17:48

I'm not sure what calling SetHdevmode will do in this scenario, but SESSION:PRINTER-CONTROL-HANDLE is a handle to a PRINTDLG structure, not the handle to a DEVMODE structure. The PRINTDLG structure does contain a handle to a DEVMODE structure in the hDevMode member. Here's some (untested) code which gets the hDevMode member of the PRINTDLG struct pointed to by SESSION:PRINTER-CONTROL-HANDLE. This is for 32-bit OpenEdge; 64-bit will require modifications.

DEFINE VARIABLE bOK AS LOGICAL.

SYSTEM-DIALOG PRINTER-SETUP UPDATE bOK.

IF bOK = TRUE THEN 
DO:
    DEFINE VARIABLE hDevMode AS INTEGER.
    DEFINE VARIABLE lpPrintDlg AS INTEGER.
    DEFINE VARIABLE PrintDlg AS MEMPTR.
    DEFINE VARIABLE bResult AS INTEGER.

    RUN GlobalLock(SESSION:PRINTER-CONTROL-HANDLE, OUTPUT lpPrintDlg).

    SET-POINTER-VALUE(PrintDlg) = lpPrintDlg.
   
    hDevMode = GET-LONG(PrintDlg, 9).

    RUN GlobalUnlock(SESSION:PRINTER-CONTROL-HANDLE, OUTPUT bResult).
END.

PROCEDURE GlobalLock EXTERNAL "kernel32.dll":
    DEFINE INPUT PARAMETER hMem AS LONG.
    DEFINE RETURN PARAMETER hAddr AS LONG.
END PROCEDURE.

PROCEDURE GlobalUnlock EXTERNAL "kernel32.dll":
    DEFINE INPUT PARAMETER hMem AS LONG.
    DEFINE RETURN PARAMETER bResult AS LONG.
END PROCEDURE.
Posted by joey eisma on 06-May-2016 10:34

hi,

I tried below the DEVMODE structure as well. still no luck.

DEFINE VARIABLE bOK AS LOGICAL NO-UNDO.

SYSTEM-DIALOG PRINTER-SETUP UPDATE bOK.

if not bOk then

  return.

DEFINE VARIABLE lpPrintDlg AS INTEGER NO-UNDO.

RUN GlobalLock(SESSION:PRINTER-CONTROL-HANDLE, OUTPUT lpPrintDlg).

DEFINE VARIABLE PrintDlg AS MEMPTR NO-UNDO.

SET-POINTER-VALUE(PrintDlg) = lpPrintDlg.

DEFINE VARIABLE hDevMode AS INTEGER NO-UNDO.

DEFINE VARIABLE lpDevMode AS INTEGER NO-UNDO.

hDevMode = GET-LONG(PrintDlg, 9).

RUN GlobalLock(hDevMode, OUTPUT lpDevMode).

def var ps2 as System.Drawing.Printing.PrinterSettings.

ps2 = new System.Drawing.Printing.PrinterSettings().

ps2:SetHdevmode (new System.IntPtr(hDevMode)).

 

/* test if pointing to the same structure */ 

MESSAGE ps2:Copies

  VIEW-AS ALERT-BOX INFO BUTTONS OK.

 

however, if i have 2 PrintDialog and do something like pd2:PrinterSettings:SetHdevmode(pd1:PrinterSettings:GetHdevmode), they would be looking at the same devmode structure. this is i essentially trying to do, use .net to manage the structure but, use ABL to bring the printer dialog.

TIA.

Posted by Matt Gilarde on 06-May-2016 11:43

I played with your code a bit and it looks like SetHdevmode works as expected (that is, it copies the dmCopies member from the supplied DEVMODE to the Copies property of the PrinterSettings object). I think the problem is that the DEVMODE doesn't have the right value for dmCopies in the first place. I added a bit of code to modify dmCopies in the DEVMODE before calling SetHdevmode and Copies then returned the number I set.

You can see if you can duplicate my results by inserting the following code before the call to SetHdevmode.

DEFINE VARIABLE DevMode AS MEMPTR.
SET-POINTER-VALUE(DevMode) = lpDevMode.
PUT-SHORT(DevMode, 87) = 13.
Posted by joey eisma on 06-May-2016 15:43

hi,

it does return the value you set. nice one.

but, problem is when you don't set the value first, PrinterSettings:Copies() does not return the value selected.

Posted by joey eisma on 06-May-2016 17:16

interestingly, the code i posted actually works on windows 2003. (where i'm trying to resolve some issue)

here's the situation:

KB 000028234 works on all system's, EXCEPT windows 2003. nCopies is always 1.

so i tried .net's PrintDialog() which works on all systems, BUT takes almost a minute to show the print dialog when run on citrix.

code now has to test that if running on windows 2003, use a different routine to read printer settings.

i can live with that. :-(

This thread is closed