News:

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

Main Menu

Printing operation

Started by xandaz, December 18, 2020, 06:12:07 AM

Previous topic - Next topic

xandaz

i took this code from a siteHANDLE hdl;
DEVMODE* devmode;
OpenPrinter(L"HP Deskjet F4400 series", &hdl, NULL);
int size = DocumentProperties(NULL, hdl, L"HP Deskjet F4400 series", NULL, NULL, 0);
devmode = (DEVMODE*)malloc(size);
DocumentProperties(NULL, hdl, L"HP Deskjet F4400 series", devmode, NULL, DM_OUT_BUFFER);
HDC printerDC = CreateDC(L"WINSPOOL", devmode->dmDeviceName, NULL, devmode);
DOCINFO info;
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
StartDoc(printerDC, &info);
StartPage(printerDC);
Rectangle(printerDC, 100, 100, 200, 200);
EndPage(printerDC);
EndDoc(printerDC);
DeleteDC(printerDC);


and translated it into this:
.if ax==IDB_BUTTON

invoke PrintDlg,addr prndlg
invoke SendMessage,hEdit,WM_SETTEXT,0,addr devmode.dmDeviceName
invoke OpenPrinter,addr szPrinterName,addr hPrinter,NULL
mov eax,rv(DocumentProperties,hWnd,hPrinter,addr szPrinterName,NULL,NULL,0)
invoke DocumentProperties,hWnd,hPrinter,addr szPrinterName,addr devmode,0,DM_OUT_BUFFER
invoke CreateDC,addr hService,addr devmode.dmDeviceName,NULL,addr devmode
mov prndlg.hDC,eax
mov hDC,eax
invoke StartDoc,prndlg.hDC,addr dci
invoke StartPage,prndlg.hDC
invoke Rectangle,prndlg.hDC,100,100,200,200
invoke EndPage,prndlg.hDC
invoke EndDoc,prndlg.hDC
invoke DeleteDC,prndlg.hDC
.endif


but nothing happens. The devmode.dmDeviceName doesn't change when PrintDlg is called. Can anyonw give some insight into this?

TimoVJL

If you use PrintDlg, you can use hdc from it., PD_RETURNDC
https://docs.microsoft.com/fi-fi/windows/win32/api/commdlg/ns-commdlg-printdlga?redirectedfrom=MSDN

https://docs.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialog-boxes
May the source be with you

xandaz


xandaz

    PRINTDLG.hDevMode doesn't return the printer name. Why would that be? does anyone have an example of this? Thanks

xandaz

   so...i lost my faith with PrintDlg and got into EnumPrinters instead. Does anyone know how to get the icon corresponding to each printer? i thought it would be PRINTER_INFO_1 but it didn't work. Can someone give me a hand? thanks

TouEnMasm


Icon are found in the resource of axecute files,dll...
If you know the full path of the printer,perhaps you can extract the icon of the resource.
Fa is a musical note to play with CL

TimoVJL

PrintDlg
https://www.codeproject.com/Articles/764057/GDI-Drawing-and-Printing
void GDIDraw::Print(HWND hWnd)
{
   PRINTDLG pd = {0};
   pd.lStructSize = sizeof( pd );
   pd.hwndOwner = hWnd;
   pd.Flags = PD_RETURNDC;
   
   // Retrieves the printer DC
   if (PrintDlg(&pd))
   {
      HDC hdc = pd.hDC;
      StartDoc (hdc, &di);
      StartPage (hdc);   
 
      // Drawing code begin
      //   
      RECT rc;
      rc.top = 100;
      rc.left = 100;
      rc.bottom = 300;
      rc.right = 300;

      HBRUSH greenBrush=CreateSolidBrush(RGB(0,255,0));
      FillRect(hdc, &rc, greenBrush);
      DeleteObject(greenBrush);
      //
      // Drawing code end

      EndPage (hdc);
      EndDoc(hdc);
      DeleteObject(hdc);
   }
}
May the source be with you

xandaz

   Thanks guys, it's been helpfull. ty :thumbsup:

xandaz

   What i trully meant was where the hell does PrinDlg get it's icons?

xandaz

   Timo. Thanks for the input, but, your code doesn't work. The document shows in the printer tray but it remains there unoperational. It doesn't print.
invoke StartDoc,prndlg.hDC,addr dci
invoke StartPage,prndlg.hDC
invoke CreateSolidBrush,0ffh
mov obj,eax
invoke SelectObject,prndlg.hDC,eax
invoke FillRect,prndlg.hDC,addr rect,obj
; invoke Rectangle,prndlg.hDC,100,100,200,200
invoke EndPage,prndlg.hDC
invoke EndDoc,prndlg.hDC
invoke DeleteObject,obj

TimoVJL

A test program that works in my PC
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commdlg.h>

void GDIDraw_Print(HWND hWnd)
{
   PRINTDLG pd = {0};
   pd.lStructSize = sizeof( pd );
   pd.hwndOwner = hWnd;
   pd.Flags = PD_RETURNDC;
   
   // Retrieves the printer DC
   if (PrintDlg(&pd))
   {
      HDC hdc = pd.hDC;
      StartDoc (hdc, NULL);
      StartPage (hdc);   

      // Drawing code begin
      //   
      RECT rc;
      rc.top = 100;
      rc.left = 100;
      rc.bottom = 300;
      rc.right = 300;

      HBRUSH greenBrush=CreateSolidBrush(RGB(0,255,0));
      FillRect(hdc, &rc, greenBrush);
      DeleteObject(greenBrush);
      //
      // Drawing code end

      EndPage (hdc);
      EndDoc(hdc);
      DeleteObject(hdc);
   }
}

void __cdecl WinMainCRTStartup(void)
{
GDIDraw_Print(0);
ExitProcess(0);
}
May the source be with you

xandaz

   Timo. Thanks. your little app didn't work on my end.

jj2007

Do the RichMasm and qEditor print dialogs work on your machine? Both are invoked with Ctrl P

xandaz

   Yes. They're working. The document stays stalled i n printer tray and nothig happens. If I write it to PDF, it works. Thanks

xandaz

   Finally got it to work. Unmentioning an output file for the DOCINFO struct did the work.