October 31, 2025, 06:33:42 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


printer device context handle

Started by talun, January 17, 2009, 04:48:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

talun

January 17, 2009, 04:48:33 AM Last Edit: January 17, 2009, 04:54:06 AM by talun
Hi,
I'm trying to retrieve the printer device context handle with the sample code below with no results, and I'm not able to figure out where I'm wrong.
$include "windows.inc"

int prhdc=0,test=0,res=0


CONST BUTTON_1 = 1
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Printer test",&d1_handler
CONTROL d1,@BUTTON,"Push me...",74,73,152,56,0x50000000,BUTTON_1
res = DOMODAL d1
end

SUB d1_handler

   SELECT @MESSAGE
      CASE @IDINITDIALOG
         CENTERWINDOW d1
     CASE @IDCLOSEWINDOW
        CLOSEDIALOG d1,@IDOK
     CASE @IDCONTROL
        SELECT @CONTROLID
            CASE BUTTON_1
               IF @NOTIFYCODE = 0
                  test = Printer(d1)
                  if test <> 0
                     messagebox d1,"Ok!","Result"
                     /*
                        prhdc = d1.m_hPrintDC
                        PlayWithPrinter(prhdc...)
                        _DeleteDc(prhdc)
                    */
                  else
                     messagebox d1,"Problem!","Result"
                  endif
               ENDIF
          ENDSELECT
      ENDSELECT
     RETURN
ENDSUB



sub Printer(dialog d),int

  int result=0
  PRINTDLG pd

  _RtlZeroMemory(pd,len(PRINTDLG))

   pd.lStructSize = len(PRINTDLG)
   pd.hWndOwner   = d.hWnd   
   pd.hDevMode    = NULL
   pd.hDevNames   = NULL
   pd.Flags       = PD_ALLPAGES|PD_RETURNDC   
   pd.nFromPage   = 1
   pd.nToPage     = 1
   pd.nMinPage    = 1
   pd.nMaxPage    = 1
   pd.nCopies     = 1

   result = _PrintDlg(pd)

   if result <> 0
      d.m_hPrintDC = pd.hdc  :' stores the printer device context handle
   endif

   return result

END sub

Can someone help me?

Thanks!

Sergio

talun

Ok, the problem is solved  if I use the Sapero's include windowssdk.inc (but I'm not able to understand the reason...)  ???

$include "windowssdk.inc"

int prhdc=0,test=0,res=0


CONST BUTTON_1 = 1
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Printer test",&d1_handler
CONTROL d1,@BUTTON,"Push me...",74,73,152,56,0x50000000,BUTTON_1
res = DOMODAL d1
end

SUB d1_handler
   SELECT @MESSAGE
      CASE @IDINITDIALOG
         CENTERWINDOW d1
      CASE @IDCLOSEWINDOW
         CLOSEDIALOG d1,@IDOK
      CASE @IDCONTROL
         SELECT @CONTROLID
            CASE BUTTON_1
               IF @NOTIFYCODE = 0
                  test = Printer(d1)
                  if test <> 0
                     messagebox d1,"Ok!","Result"
                     /*
                        prhdc = d1.m_hPrintDC
                        PlayWithPrinter(prhdc...)
                        _DeleteDc(prhdc)
                     */   
                  else
                     messagebox d1,"Problem!","Result"
                  endif
               ENDIF
         ENDSELECT
   ENDSELECT
RETURN
ENDSUB



sub Printer(dialog d),int

   uint result=0
  PRINTDLG pd
   
   RtlZeroMemory(pd,len(PRINTDLG))

   pd.lStructSize = len(PRINTDLG)
  pd.hWndOwner   = d.hWnd   
   pd.hDevMode    = NULL
   pd.hDevNames   = NULL
   pd.Flags       = PD_ALLPAGES|PD_RETURNDC   
  pd.nFromPage   = 1
   pd.nToPage     = 1
   pd.nMinPage    = 1
   pd.nMaxPage    = 1
   pd.nCopies     = 1
   
   result = PrintDlg(pd)
   
   if result <> 0
      d.m_hPrintDC = pd.hdc  :' stores the printer device context handle
   endif
   
   return result
   
END sub



bye

Sergio