Page 2 of 2

Re: Grab desktop wallpaper to image?

Posted: Sun May 28, 2017 3:31 pm
by RASHAD
Using Danilo & NM code with the simplicity of RASHAD :P
Tested with 7,8 & 10

Code: Select all

Procedure LoadPictureFile(image,File.s) 
  hFile = CreateFile_(File, #GENERIC_READ, 0, #Null, #OPEN_EXISTING, 0, #Null) 
  If hFile 
    dwFileSize = GetFileSize_(hFile, #Null) 
    HGLOBAL    = GlobalAlloc_(#GMEM_MOVEABLE, dwFileSize) 
    If HGLOBAL 
      pvData = GlobalLock_(HGLOBAL)
      bRead = ReadFile_(hFile, pvData, dwFileSize, @dwBytesRead, #Null) 
      GlobalUnlock_(HGLOBAL)      
      If bRead 
        If CreateStreamOnHGlobal_(HGLOBAL, #True, @pstm.IStream) = #S_OK 
          If OleLoadPicture_(pstm, dwFileSize, #False,?IID_IPicture, @Bild.IPicture) = #S_OK 
            Bild\get_Height(@Height) 
            Bild\get_Width(@Width)             
            ExamineDesktops()
            result = CreateImage(image,DesktopWidth(0),DesktopHeight(0))            
            If result
              hDC = StartDrawing(ImageOutput(image)) 
                Bild\Render(hDC,0,DesktopHeight(0),DesktopWidth(0),-DesktopHeight(0),0,0,Width,Height,0) 
              StopDrawing() 
            EndIf           
            Bild\Release() 
          EndIf 
          pstm\Release() 
        EndIf 
      EndIf 
    EndIf 
    CloseHandle_(hFile) 
  EndIf 
  ProcedureReturn result
EndProcedure 

img$ = Space(#MAX_PATH)
SystemParametersInfo_(#SPI_GETDESKWALLPAPER, #MAX_PATH, @img$, 0)
image = LoadPictureFile(1,img$) 

SaveImage(1,GetHomeDirectory()+"test.bmp",#PB_ImagePlugin_BMP)

DataSection 
  IID_IPicture: 
    Data.l $7BF80980 
    Data.w $BF32,$101A 
    Data.b $8B,$BB,$00,$AA,$00,$30,$0C,$AB 
EndDataSection 


Re: Grab desktop wallpaper to image?

Posted: Sun May 28, 2017 10:12 pm
by Dude
I get this:

Code: Select all

Line: 37 - The specified #Image is not initialised.
Reason: there's a desktop image shown, but no file for it. That's why I can't rely on loading a file to get the image.

It's okay - I'll just toggle the desktop icons before snapshotting the image. Don't worry about it anymore. :)

Re: Grab desktop wallpaper to image?

Posted: Mon May 29, 2017 1:23 am
by netmaestro
@RASHAD: Nice implementation, works perfectly here. Thanks for the post :mrgreen:

Re: Grab desktop wallpaper to image?

Posted: Mon May 29, 2017 12:18 pm
by Dude
netmaestro wrote:works perfectly here
Yep, because the wallpaper file still exists for you. ;) It doesn't for me, so I can't use his solution.