PrintWindow API at absolute position [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

PrintWindow API at absolute position [Resolved]

Post by Kwai chang caine »

Hello at all,

Thanks to splendid Netmaestro code
viewtopic.php?p=400913#p400913
I can choose what window i want put in my screenshot 8)

But i try since 3 hours to locate the image without succes :oops:

Code: Select all

Prototype.l pPrintWindow(hWnd.l, hDc.l, lFlags.l)
Global hLib.l = OpenLibrary(#PB_Any , "user32.dll")
Global PrintWindow_.pPrintWindow = GetFunction(hLib , "PrintWindow")

RunProgram("Explorer.exe", "/n, C:\" , "")

While Not HwndC
 Delay(500)
 HwndC = FindWindow_(#Null, "C:\")
Wend
 
SetWindowPos_(HwndC, 0, 200, 200, -1, -1, #SWP_NOSIZE | #SWP_NOACTIVATE)

ExamineDesktops()
CreateImage(0, DesktopWidth(0), DesktopHeight(0), 24)

hdc = StartDrawing(ImageOutput(0))
 PrintWindow_(FindWindow_(#Null, "Program Manager"), hdc, 0)
 PrintWindow_(HwndC, hdc, 0)
StopDrawing()

SizeScreenShotX = DesktopWidth(0) / 2
SizeScreenShotY = DesktopHeight(0) / 2
ResizeImage(0, SizeScreenShotX, SizeScreenShotY)
OpenWindow(0,0,0,SizeScreenShotX, SizeScreenShotY, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,SizeScreenShotX, SizeScreenShotY,ImageID(0))

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

CloseLibrary(hLib)
Have you a way for move the "C:\" at the right place ?

Have a good day
Last edited by Kwai chang caine on Sun Oct 25, 2020 7:12 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: PrintWindow API at absolute position

Post by Olli »

Maybe this ?

Code: Select all

RunProgram("Explorer.exe", "/n", "C:\")
If you could explain what you want to see (which directory? ) and where do you want a image file, if it is what you want.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PrintWindow API at absolute position

Post by Kwai chang caine »

Like i have write, i use the Netmaestro code, it's a screenshot but window by window
You enumerate all the handles of desktop windows opened and choose if you want to put it in the screeshot, it's amazing 8)
That works but the PrintWindow not ask the X,Y position where print the famous catching window :|
There are surely a way for writing the image at the good place....but i don't know how :oops:

I have also searched with another RASHAD splendid code
viewtopic.php?p=401260#p401260
and try

Code: Select all

 GetWindowRect_(HwndC, r.RECT)
 SelectObject_(hdc, hBitmap)
 BitBlt_(hdc, r\left, r\top, r\right - r\left, r\bottom - r\top, GetWindowDC_(HwndC), r\right - r\left - 10, r\bottom - r\top - 10, #SRCCOPY | #CAPTUREBLT)
but that not works too , i don't how really use this API :|
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PrintWindow API at absolute position

Post by Kwai chang caine »

Finally i believe i have found, thanks to a RESCATOR code
viewtopic.php?p=450707#p450707
It's not really perfect, sometime there are foreground border around the windows but it's already a good move for Kcc :mrgreen:

Code: Select all

Prototype.l pPrintWindow(hWnd.l, hDc.l, lFlags.l)
Global hLib.l = OpenLibrary(#PB_Any , "user32.dll")
Global PrintWindow_.pPrintWindow = GetFunction(hLib , "PrintWindow")

ExamineDesktops()
#CAPTUREBLT  = $40000000
RunProgram("Explorer.exe", "/n, C:\" , "")

While Not HwndC
 HwndC = FindWindow_(#Null, "C:\")
 Delay(500)
Wend

GetWindowRect_(HwndC, r.RECT)
hBitmap = CreateImage(0, DesktopWidth(0), DesktopHeight(0), 24)

hdc = StartDrawing(ImageOutput(0))
 PrintWindow_(FindWindow_(#Null, "Program Manager"), hdc, 0)
 SelectObject_(hdc, hBitmap)
 BitBlt_(hdc, r\left, r\top, r\right - r\left, r\bottom - r\top, GetWindowDC_(#Null), r\left, r\top, #SRCCOPY | #CAPTUREBLT)
StopDrawing()

SizeScreenShotX = DesktopWidth(0) / 2
SizeScreenShotY = DesktopHeight(0) / 2
ResizeImage(0, SizeScreenShotX, SizeScreenShotY)
OpenWindow(0,0,0,SizeScreenShotX, SizeScreenShotY, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,SizeScreenShotX, SizeScreenShotY,ImageID(0))

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

CloseLibrary(hLib)
ImageThe happiness is a road...
Not a destination
Post Reply