News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

code for selection by user of printer parms

Started by shankle, December 24, 2009, 10:34:49 PM

Previous topic - Next topic

shankle

Thanks for any help.
Program is know where near finished. Am stuck at Print Dialog box to come up.
Have included a partial program with the code pertaining to the PRINTDLGEX API.
This is the error I am getting at "PrintDlgEx  STRUCT:  Fatal error A1016: Internal
assembly error.
See the attachment for the code.
The greatest crime in my country is our Congress

jj2007

It seems that certain elements for successful assembly are missing altogether. For example, .code and start:

shankle

Thanks for answering JJ. It is not a working program as I cut it down to
keep it small but the code for printer manipulation is there but not
working.
The greatest crime in my country is our Congress

MichaelW

I apparently have never used PrintDlgEx, so as a start I coded a minimal console app that simply opens the dialog and displays its return value.

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================

;------------------------------------------
; The MASM32 windows.inc contains a error:
; START_PAGE_GENERAL equ ffffffffh
;------------------------------------------

_START_PAGE_GENERAL  equ 0ffffffffh

PRINTPAGERANGE struct
    nFromPage DWORD ?
    nToPage   DWORD ?
PRINTPAGERANGE ends

PRINTDLGEX struct
    lStructSize         DWORD ?
    hwndOwner           DWORD ?
    hDevMode            DWORD ?
    hDevNames           DWORD ?
    hDC                 DWORD ?
    Flags               DWORD ?
    Flags2              DWORD ?
    ExclusionFlags      DWORD ?
    nPageRanges         DWORD ?
    nMaxPageRanges      DWORD ?
    lpPageRanges        DWORD ?
    nMinPage            DWORD ?
    nMaxPage            DWORD ?
    nCopies             DWORD ?
    hInstance           DWORD ?
    lpPrintTemplateName DWORD ?
    lpCallback          DWORD ?
    nPropertyPages      DWORD ?
    lphPropertyPages    DWORD ?
    nStartPage          DWORD ?
    dwResultAction      DWORD ?
PRINTDLGEX ends

;==============================================================================
    .data
        ppd PRINTDLGEX <>
    .code
;==============================================================================

;==============================================================================
start:
;==============================================================================
    invoke RtlZeroMemory, addr ppd, sizeof ppd
    push sizeof ppd
    pop ppd.lStructSize
    invoke GetDesktopWindow
    mov ppd.hwndOwner, eax
    mov ppd.Flags, PD_RETURNDC or PD_NOPAGENUMS
    mov ppd.nStartPage, _START_PAGE_GENERAL
    invoke PrintDlgEx, addr ppd
    print str$(eax),13,10
    SWITCH ppd.dwResultAction
        CASE PD_RESULT_APPLY
            print "PD_RESULT_APPLY",13,10
        CASE PD_RESULT_CANCEL
            print "PD_RESULT_CANCEL",13,10
        CASE PD_RESULT_PRINT
            print "PD_RESULT_PRINT",13,10
        DEFAULT
            print str$(ppd.dwResultAction),13,10
    ENDSW

    inkey "Press any key to exit..."
    exit
;==============================================================================
end start

eschew obfuscation

shankle

Thank you MichaelW and Merry Christmas.
That is a nice Xmas present.
I think with your help I will be able to get it working.
Cheers
The greatest crime in my country is our Congress

z941998

Micheal, How do you get the Print Properties sheets for Layout and Paper/Quality to show up (display) as the other two tabs in a printdlgex, versus just the general tab?  The platform sdk indicates that all three should be there.  Steve


dedndave

Steve - Jochen and others did some recent work with printers on another thread
i would guess it was about a month ago - try the search tool
if you use advanced search and limit responses to jj2007, it may thin out the list for you

shankle

Thank you MichaelW for the sample code.
I have included some code in a zip format that can be assembled to
show the errors that I am getting. There is an list of the errors at
the top of the program.
The greatest crime in my country is our Congress

MichaelW

Quote from: z941998 on December 25, 2009, 02:47:47 PM
How do you get the Print Properties sheets for Layout and Paper/Quality to show up (display) as the other two tabs in a printdlgex, versus just the general tab?  The platform sdk indicates that all three should be there.

On my Windows 2000 system all three tabs are there. Because the code does not specify a printer, I think the tabs depend on your default printer setting. If my HP DeskJet is set as the default printer then I get General, Layout, and Paper/Quality tabs. If my default printer is the Windows NT Fax Driver, then I get only General and Fax Options tabs.
eschew obfuscation

MichaelW

I encountered much more than two errors before I eliminated them all. For the code that initializes the PRINTDLGEX members I just commented most of the code without trying to identify the exact problem because I don't know what you are trying to do.

BTW, the batch file is set to build a console app so in addition to the window I get a console that the print macro can use.

eschew obfuscation

jj2007

Quote from: dedndave on December 25, 2009, 03:24:21 PM
Steve - Jochen and others did some recent work with printers on another thread
i would guess it was about a month ago - try the search tool
if you use advanced search and limit responses to jj2007, it may thin out the list for you

Here it is. Open Tiny_rtf.asm in the attachment, and look for the PrintRTF proc.

shankle

I want to thanks you all for helping with this problem.
It is now working.
I feel that the "Printdlgex Flags are a royal pain.
One place for ex: says to code PD_RETURNDC or PD_USEDEVMODECOPIESCOLLATE.
This causes no end of problems.
What works is:  PD_ RETURNDC or PD_NOPAGENUMS.
I have no idea why.
Nothing is ever easy.
Happy New Year.
The greatest crime in my country is our Congress

shankle

#12
There is also a problem with default printers. It seems that if there is a fax printer listed this becomes the
default printer. Vista and XP Pro seems to have lots of problems with this. Lots of comments on this
problem on the web. Didn't see any solutions to it.
My solution is to delete a 2nd printer or fax. Then things work. Other people don't want
to delete other printers for various reasons and "PrintDlgEx" then points to the wrong printer.
In one case I know it pointed to the fax printer.

How about this for a solution:
  Don't send the "Print" window just do the following,
     invoke RtlZeroMemory, addr ppd, sizeof ppd
    push sizeof ppd
    pop ppd.lStructSize
    mov ppd.hwndOwner, hWnd
    mov ppd.Flags, PD_RETURNDC or PD_RETURNDEFAULT
    invoke PrintDlgEx, addr ppd
    etc. etc.
  This works with only one printer in "Control Panel/Printers
  Don't have a way to check if there was a Fax printer or another printer listed.
The greatest crime in my country is our Congress