please test this screenshot-print

Everything else that doesn't fall into one of the other PB categories.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

please test this screenshot-print

Post by Froggerprogger »

Hi!

A customer says that a program of mine isn't able to print.
I want to know if it is perhaps related to his PC or PC-knowledge, because I cannot find any bug.

Could you please try the following snippet, perhaps with default printing-properties set to landscape and high resolution under Start -> Printer -> <standard printer> ?

Or does anybody find a bug or has an idea how to improve the source to make the printing more reliable ?

Thanks a lot!

Code: Select all

#offsetX = 0
#offsetY = 0
#percentX = 1
#percentY = #percentX

Procedure PrintScreenEx(offsetX.f, offsetY.f, widthPercent.f, heightPercent.f)
    hDcDesktop  = GetDC_(GetDesktopWindow_())
    
    w = GetSystemMetrics_(#SM_CXSCREEN)
    h = GetSystemMetrics_(#SM_CYSCREEN)
    CreateImage(0, w, h)
     
    hDC = StartDrawing(ImageOutput(0))
      BitBlt_(hDC, 0, 0, w, h, hDcDesktop, 0, 0, #SRCCOPY)
    StopDrawing()

    ReleaseDC_(GetDesktopWindow_(), hDcDesktop)

    GrabImage(0, 1, offsetX * w, offsetY * h, widthPercent * w, heightPercent * h)
    FreeImage(0)

    DefaultPrinter()

    If 1.0 * ImageWidth(1) / PrinterPageWidth() >= 1.0 * ImageHeight(1) / PrinterPageHeight()
      pw = PrinterPageWidth()
      ph = ImageHeight(1) * PrinterPageWidth() / ImageWidth(1)
    Else 
      ph = PrinterPageHeight()
      pw = ImageWidth(1) * PrinterPageHeight() / ImageHeight(1)
    EndIf
    
    If StartPrinting("Print_Screen")
      If StartDrawing(PrinterOutput())
        DrawImage(ImageID(1), (PrinterPageWidth() - pw)/2, (PrinterPageHeight() - ph)/2, pw, ph)
        StopDrawing()
      EndIf
      StopPrinting()
    EndIf
    
    
EndProcedure

PrintScreenEx(#offsetX, #offsetY, #percentX, #percentY)
%1>>1+1*1/1-1!1|1&1<<$1=1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Works perfectly here, no glitches.
BERESHEIT
User avatar
Michael Vogel
Addict
Addict
Posts: 2820
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Seems to work here either, maybe the customer is able install a "print to pdf" driver, so he would be able to forward the (wrong) output to you...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Give him a special version which generates a log and ask him to send the log to you:

Code: Select all

#offsetX = 0 
#offsetY = 0 
#percentX = 1 
#percentY = #percentX 

Procedure PrintScreenEx(offsetX.f, offsetY.f, widthPercent.f, heightPercent.f) 
    CreateFile(0, "c:\_log.txt")
    hDcDesktop  = GetDC_(0) ; ---------------------- This is how to get the screen DC.
    WriteStringN(0, "hDCDesktop: " + Str(hDcDesktop))
    
    w = GetSystemMetrics_(#SM_CXSCREEN) 
    h = GetSystemMetrics_(#SM_CYSCREEN) 
    WriteStringN(0, Str(w) + ", " + Str(h))
    res = CreateImage(0, w, h) 
    WriteStringN(0, "CreateImage: " + Str(res))
    
    hDC = StartDrawing(ImageOutput(0))
      WriteStringN(0, "hDCImage: " + Str(hDC))
      res = BitBlt_(hDC, 0, 0, w, h, hDcDesktop, 0, 0, #SRCCOPY) 
      WriteStringN(0, "BitBlt: " + Str(res))
    StopDrawing() 

    ReleaseDC_(0, hDcDesktop) 

    GrabImage(0, 1, offsetX * w, offsetY * h, widthPercent * w, heightPercent * h) 
    FreeImage(0) 

    res = DefaultPrinter()
    WriteStringN(0, "Default printer available? " + Str(res))

    If 1.0 * ImageWidth(1) / PrinterPageWidth() >= 1.0 * ImageHeight(1) / PrinterPageHeight() 
      pw = PrinterPageWidth() 
      ph = ImageHeight(1) * PrinterPageWidth() / ImageWidth(1) 
    Else 
      ph = PrinterPageHeight() 
      pw = ImageWidth(1) * PrinterPageHeight() / ImageHeight(1) 
    EndIf 
    
    If StartPrinting("Print_Screen") 
      WriteStringN(0, "Started printing")
      If StartDrawing(PrinterOutput()) 
        WriteStringN(0, "Drawing on printer")
        DrawImage(ImageID(1), (PrinterPageWidth() - pw)/2, (PrinterPageHeight() - ph)/2, pw, ph) 
        StopDrawing() 
      Else
        WriteStringN(0, "Could not start drawing on printer")
      EndIf 
      StopPrinting() 
    Else
      WriteStringN(0, "Could not start print")
    EndIf 
    
    
EndProcedure 

PrintScreenEx(#offsetX, #offsetY, #percentX, #percentY)


Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Hi and thanks a lot for your tests and tipps!

Now I phoned one of them and it seems that their installation is not correct. A correct installation would be done by extracting a zip-archive to somewhere on hd, but the person at the phone told me about a chaos of folders and files on the desktop. So perhaps the main-program (flash-exe) couldn't even find the printing-exe (inside the /fscommand). (Further the printer was attached via network and usb at the same time)

I hope that was the reason. Somebody is going to test it there today. Otherwise I will write a log-version as Trond says. I didn't made any checks, because when the software is in action (a fullscreen-flash-program on an event) there shouldn't appear any messagebox, even on printing-errors.

If this was the reason I think about devilering an installer-exe instead of a zip-archive next time, to avoid such DAU-mistakes.
(DAU = 'dümmst anzunehmender user', should be SIU in english: 'silliest imaginable user' :wink: )
%1>>1+1*1/1-1!1|1&1<<$1=1
Post Reply