Screenshot of window isn't themed

Just starting out? Need help? Post your questions and find answers here.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Screenshot of window isn't themed

Post by nco2k »

no, both windows have to be top-level windows.

but you can specify the position and size:

Code: Select all

dwm_thumbnail_properties\rcDestination\left = x
dwm_thumbnail_properties\rcDestination\top = y
dwm_thumbnail_properties\rcDestination\right = Width + dwm_thumbnail_properties\rcDestination\left
dwm_thumbnail_properties\rcDestination\bottom = Height + dwm_thumbnail_properties\rcDestination\top
and you can quickly turn it on or off:

Code: Select all

dwm_thumbnail_properties\fVisible = #True/#False
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Screenshot of window isn't themed

Post by skywalk »

@chi - Your fixes now capture the modern Calculator again, but my drawn windows are stripped of their theme. And I cannot get a clean, zero margin clip of my captured window. I have to go into the code and enter negative numbers but they are not symmetrical.

Is this correct summary?
PrintWindow() - captures PB drawn windows with theme. Fails on modern calculator and equivalents.
bitblt() + pixel looping/alphachannel - captures all windows minus theme.
DwmUpdateThumbnailProperties() - captures all windows + theme but writes to another Window. Still need to save image and back to original problem?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Screenshot of window isn't themed

Post by chi »

@skywalk: the clipboard seems to have issues with some 32bit images... updated source code
Et cetera is my worst enemy
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Screenshot of window isn't themed

Post by skywalk »

Hi chi - Your AeroShot code now captures the modern Calculator and PB drawn windows when saved to file. But, PB drawn windows saved to Clipboard still have extra padding. I remember having similar problems with PrintWindow_() and trying 32-bit data. It worked fine with 24-bit image data.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: Screenshot of window isn't themed

Post by RASHAD »

Capture almost any running application to clipboard
Exact size
After all it is workaround

Code: Select all

Global Dim h(100),n

Procedure tbWindows(hwnd,lParam)
    Protected.s title = Space(#MAX_PATH)    
    If GetWindowLongPtr_(hwnd,#GWL_EXSTYLE) ! #WS_EX_TOOLWINDOW And GetWindowLongPtr_(hwnd,#GWL_STYLE) & #WS_VISIBLE
        GetWindowText_(hwnd,title,#MAX_PATH)
        If title <> ""
            AddGadgetItem(0,-1,title)
            h(n) = hwnd
            n +1
        EndIf
    EndIf
    ProcedureReturn #True
EndProcedure

OpenWindow(0, 0, 0, 400,400, "Snapshot", #PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ListViewGadget(0,10,10,380,340)
ButtonGadget(1,10,365,60,24,"RUN")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0        
          hwnd = h(GetGadgetState(0))
          SetWindowPos_(hwnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
          wi.WINDOWINFO
          wi\cbSize = SizeOf(wi)
          GetWindowInfo_(hwnd,wi)
          ;cap = wi\rcClient\top - wi\rcWindow\top
          bord = wi\rcClient\left - wi\rcWindow\left
          hBitmap = CreateImage(0,wi\rcWindow\right-wi\rcWindow\left-2*bord+2,wi\rcWindow\bottom-wi\rcWindow\top-bord+1)
          hdc = StartDrawing(ImageOutput(0))
          SelectObject_(hdc, hBitmap)
            BitBlt_(hdc,0,0,wi\rcWindow\right-wi\rcWindow\left-2*bord+2,wi\rcWindow\bottom-wi\rcWindow\top-bord+1, GetDC_(0),wi\rcWindow\left+bord-1,wi\rcWindow\top , #SRCCOPY)
          StopDrawing()

          ClearClipboard()
          SetClipboardImage(0)
          SetWindowPos_(hwnd,#HWND_BOTTOM	,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE )
          FreeImage(0)
          
        Case 1
          ClearGadgetItems(0)
          n = 0
          ReDim h(100)
          EnumChildWindows_(FindWindow_("ToolbarWindow32",0),@tbWindows(),0)
          Delay(200)
          SetWindowPos_(WindowID(0), #HWND_TOPMOST, 0, 0, 0, 0,#SWP_NOSIZE|#SWP_NOMOVE| #SWP_SHOWWINDOW|#SWP_NOACTIVATE)
          
      EndSelect
  EndSelect
Until Quit = 1
Egypt my love
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Screenshot of window isn't themed

Post by skywalk »

TaDa! 8)
RASHAD, so simple and it respects the current theme of modern and PB drawn windows.
Also works with 24 or 32-bit image creations.
hBitmap = CreateImage(0,wi\rcWindow\right-wi\rcWindow\left-2*bord+2,wi\rcWindow\bottom-wi\rcWindow\top-bord+1,32)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Screenshot of window isn't themed

Post by Dude »

RASHAD wrote:Capture almost any running application to clipboard
Exact size
Sorry Rashad, but not quite. :( Here's how it captures Calculator on my PC:

Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Screenshot of window isn't themed

Post by Dude »

@nco2k: How can I remove (delete) all thumbnails from a window? When I try to use DwmUnregisterThumbnail_(hThumbnailId), I get this error:

Code: Select all

DwmUnregisterThumbnail_() is not a function, array, list, map or macro.
I just want to remove all thumbnails that I set, without closing the window that I put them on.
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Screenshot of window isn't themed

Post by firace »

Dude wrote:@nco2k: How can I remove (delete) all thumbnails from a window? When I try to use DwmUnregisterThumbnail_(hThumbnailId), I get this error:

Code: Select all

DwmUnregisterThumbnail_() is not a function, array, list, map or macro.
I just want to remove all thumbnails that I set, without closing the window that I put them on.
Seems to work fine here. Make sure you did not remove the import:

Code: Select all

    DwmUnregisterThumbnail_ = GetFunction(LibraryPB, "DwmUnregisterThumbnail")
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Screenshot of window isn't themed

Post by Dude »

Thanks firace, that was the problem. Got it sorted now. :)

The only thing is, I have to keep an array of all registered thumb IDs, then unregister them all manually. This works, but I wonder if there's some sort of bulk way to just unregister them all automatically?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Screenshot of window isn't themed

Post by Dude »

Anyone know how to capture fullscreen games to an image? Things like "Quake 2" just show a gray screen, even if I press PrintScreen to capture them to the clipboard. :(
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Screenshot of window isn't themed

Post by chi »

skywalk wrote:Hi chi - Your AeroShot code now captures the modern Calculator and PB drawn windows when saved to file. But, PB drawn windows saved to Clipboard still have extra padding. I remember having similar problems with PrintWindow_() and trying 32-bit data. It worked fine with 24-bit image data.
Just don't use the clipboard with 32bit images right now... ;) I already filed a bug report here
Dude wrote:Anyone know how to capture fullscreen games to an image? Things like "Quake 2" just show a gray screen, even if I press PrintScreen to capture them to the clipboard. :(
Maybe hook EndScene (DirectX) or glSwapBuffers (OpenGL)?!
Et cetera is my worst enemy
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Screenshot of window isn't themed

Post by Dude »

Another question about the DWM thumbnail code: is there a way to get the thumbnail size AFTER the thumbnail is drawn? I want to set my window height to be the thumbnail height, but I don't know what the thumbnail height will be until after it's drawn.
User avatar
idle
Always Here
Always Here
Posts: 5049
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Screenshot of window isn't themed

Post by idle »

Dude

This should capture your themed window

Code: Select all

#CAPTUREBLT = $40000000 

Procedure CapWindow(Hwnd) 
  
  Protected Rect.rect 
  Protected SrcDc,DestDc,Image,Result,W,H  
  If hwnd 
    SrcDc = GetDC_(0)
    If SrcDc 
      GetWindowRect_(Hwnd,@Rect)
      W = Rect\Right-Rect\Left 
      H = Rect\Bottom - Rect\Top 
      If W 
        Image = CreateImage(#PB_Any,W,H,32) 
        If Image 
          DestDc = StartDrawing(ImageOutput(Image))
          If DestDc 
            Result = BitBlt_(DestDc,0,0,W,H,Srcdc,Rect\Left,Rect\Top,#SRCCOPY | #CAPTUREBLT);
            If Result 
              ProcedureReturn Image 
            EndIf 
          EndIf 
        EndIf   
      EndIf   
    EndIf
  EndIf  
  
EndProcedure


Delay(2000)

winshot=CapWindow(GetForegroundWindow_()) 
SetClipboardImage(winshot)
If winshot
  FreeImage(winshot)
EndIf 
Windows 11, Manjaro, Raspberry Pi OS
Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Screenshot of window isn't themed

Post by Dude »

Thanks idle, it sure does! :)
Post Reply