News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Setting Printer Color Mode

Started by Biterider, February 20, 2023, 03:12:44 AM

Previous topic - Next topic

Biterider

Hi
This code posted here is for reference.
I spent some time searching the internet for how to set up my printer to switch from monochrome to color and vice versa from within my application, and I found nothing useful. Finally, I put some pieces together and came up with this code. Maybe there are better ways, but this one works  :biggrin:
; ——————————————————————————————————————————————————————————————————————————————————————————————————
; Procedure:  SetPrinterColorMode
; Purpose:    Function to set the color mode of a printer.
; Arguments:  Arg1: -> Printer name.
;             Arg2: TRUE for color, FALSE for monochrome.
; Return:     eax = 0 if succeeded.

SetPrinterColorMode proc pPrinterName:PSTRING, dUseColor:DWORD
  local dResult:DWORD, hPrinter:HANDLE, pPrinterData:ptr PRINTER_INFO_9, dPrinterReqDataSize:DWORD

  mov dResult, -1
  invoke OpenPrinter, pPrinterName, addr hPrinter, NULL
  .if eax != 0
    mov dPrinterReqDataSize, 0
    invoke GetPrinter, hPrinter, 9, pPrinterData, 0, addr dPrinterReqDataSize
    .if eax == 0 && dPrinterReqDataSize != 0
      MemAlloc dPrinterReqDataSize
      .if xax != NULL
        mov pPrinterData, xax
        invoke GetPrinter, hPrinter, 9, pPrinterData, dPrinterReqDataSize, addr dPrinterReqDataSize
        .if dUseColor == FALSE
          mov dx, DMCOLOR_MONOCHROME
        .else
          mov dx, DMCOLOR_COLOR
        .endif
        mov xax, pPrinterData
        mov xcx, [xax].PRINTER_INFO_9.pDevMode
        mov [xcx].DEVMODE.dmColor, dx
        invoke SetPrinter, hPrinter, 9, pPrinterData, 0
        .if eax != 0
          mov dResult, 0
        .endif
        MemFree pPrinterData
      .endif
    .endif
    invoke ClosePrinter, hPrinter
  .endif
  mov eax, dResult
  ret
SetPrinterColorMode endp


Biterider