Jump to content

screencapture into clipboard


Recommended Posts

Hi, my be someone can help me please!

I can find the way to put image.jpg in clipboard and retrive it with ctrl+v in other application?

I get a screenshot of region of window with this function:

Func SnapShot()
WinActive("Camera")
$hcamera=WinGetHandle("Camera")
_ScreenCapture_CaptureWnd($scatto,$hcamera,20,45,335,280,false)
_ScreenCapture_SetJPGQuality(80)
_ScreenCapture_SaveImage($scatto,1,true)
EndFunc

Now I need to copy on clipboard the image that i saved with the jpg format and quality (otherway the bmp file will be too heavy) for released with CTRL+v in other application i guess!

I tried with all function of clipboard but the result is always 0. Nothing to paste when i'll go in other application.

_ClipBoard_Open(0)
_ClipBoard_SetData($scatto,2)
_ClipBoard_Close()

please a little help

thanks

Link to comment
Share on other sites

_ClipBoard_SetDataEx

--------------------------------------------------------------------------------

Places data on the clipboard in a specified clipboard format

#Include <Clipboard.au3>

_ClipBoard_SetDataEx(ByRef $hMemory[, $iFormat = 1])

Parameters

$hMemory Handle to the data in the specified format. This parameter can be NULL, indicating that the

window provides data in the specified clipboard format upon request. If a window delays rendering, it must

process the $WM_RENDERFORMAT and $WM_RENDERALLFORMATS messages. If this function succeeds, the system owns

the object identified by the $hMemory parameter. The application may not write to or free the data once

ownership has been transferred to the system, but it can lock and read from the data until the _ClipBoard_Close

function is called. The memory must be unlocked before the clipboard is closed. If the $hMemory parameter

identifies a memory object, the object must have been allocated using the function with the $GMEM_MOVEABLE

flag.

$iFormat Specifies a clipboard format:

$CF_TEXT - Text format

$CF_BITMAP - Handle to a bitmap (HBITMAP)

$CF_METAFILEPICT - Handle to a metafile picture (METAFILEPICT)

$CF_SYLK - Microsoft Symbolic Link (SYLK) format

$CF_DIF - Software Arts' Data Interchange Format

$CF_TIFF - Tagged image file format

$CF_OEMTEXT - Text format containing characters in the OEM character set

$CF_DIB - BITMAPINFO structure followed by the bitmap bits

$CF_PALETTE - Handle to a color palette

$CF_PENDATA - Data for the pen extensions to Pen Computing

$CF_RIFF - Represents audio data in RIFF format

$CF_WAVE - Represents audio data in WAVE format

$CF_UNICODETEXT - Unicode text format

$CF_ENHMETAFILE - Handle to an enhanced metafile (HENHMETAFILE)

$CF_HDROP - Handle to type HDROP that identifies a list of files

$CF_LOCALE - Handle to the locale identifier associated with text in the clipboard

$CF_DIBV5 - BITMAPV5HEADER structure followed by bitmap color and the bitmap bits

$CF_OWNERDISPLAY - Owner display format

$CF_DSPTEXT - Text display format associated with a private format

$CF_DSPBITMAP - Bitmap display format associated with a private format

$CF_DSPMETAFILEPICT - Metafile picture display format associated with a private format

$CF_DSPENHMETAFILE - Enhanced metafile display format associated with a private format

" I haven't failed. I've just found 10,000 ways that won't work." Thomas Edison "You cannot help men permanently by doing for them what they could and should do for themselves." Abraham Lincoln

Link to comment
Share on other sites

MaxNMB

Hi! Example:

#include <GuiConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test GUI", 800, 600)

$hPic = GUICtrlCreatePic("", 0, 0, 800, 600)
GUICtrlSetState(-1, $GUI_DISABLE)

GUISetState()

_SetBackground()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetBackground()
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    
    Local $hParent, $hChild, $hBitmap, $hWnd
    
    Run("mspaint " & @SystemDir & "\setup.bmp")
    
    WinWait("[Class:MSPaintApp]")
    
    Local $hParent = WinGetHandle("[Class:MSPaintApp]")
    Local $hChild = ControlGetHandle($hParent, "", "Afx:1000000:81")
    
    WinActivate($hParent)
    
    $hBitmap = _ScreenCapture_CaptureWnd("", $hChild)
    
    WinClose($hParent)
    
    $hWnd = GUICtrlGetHandle($hPic)
    If $hWnd = 0 Then Return SetError(2, 0, 0)
    
    DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(3, 0, 0)
    
    _WinAPI_DeleteObject($hBitmap)
EndFunc
:) Edited by rasim
Link to comment
Share on other sites

_ClipBoard_SetDataEx

--------------------------------------------------------------------------------

Places data on the clipboard in a specified clipboard format

#Include <Clipboard.au3>

_ClipBoard_SetDataEx(ByRef $hMemory[, $iFormat = 1])

Parameters

$hMemory Handle to the data in the specified format. This parameter can be NULL, indicating that the

window provides data in the specified clipboard format upon request. If a window delays rendering, it must

process the $WM_RENDERFORMAT and $WM_RENDERALLFORMATS messages. If this function succeeds, the system owns

the object identified by the $hMemory parameter. The application may not write to or free the data once

ownership has been transferred to the system, but it can lock and read from the data until the _ClipBoard_Close

function is called. The memory must be unlocked before the clipboard is closed. If the $hMemory parameter

identifies a memory object, the object must have been allocated using the function with the $GMEM_MOVEABLE

flag.

$iFormat Specifies a clipboard format:

$CF_TEXT - Text format

$CF_BITMAP - Handle to a bitmap (HBITMAP)

$CF_METAFILEPICT - Handle to a metafile picture (METAFILEPICT)

$CF_SYLK - Microsoft Symbolic Link (SYLK) format

$CF_DIF - Software Arts' Data Interchange Format

$CF_TIFF - Tagged image file format

$CF_OEMTEXT - Text format containing characters in the OEM character set

$CF_DIB - BITMAPINFO structure followed by the bitmap bits

$CF_PALETTE - Handle to a color palette

$CF_PENDATA - Data for the pen extensions to Pen Computing

$CF_RIFF - Represents audio data in RIFF format

$CF_WAVE - Represents audio data in WAVE format

$CF_UNICODETEXT - Unicode text format

$CF_ENHMETAFILE - Handle to an enhanced metafile (HENHMETAFILE)

$CF_HDROP - Handle to type HDROP that identifies a list of files

$CF_LOCALE - Handle to the locale identifier associated with text in the clipboard

$CF_DIBV5 - BITMAPV5HEADER structure followed by bitmap color and the bitmap bits

$CF_OWNERDISPLAY - Owner display format

$CF_DSPTEXT - Text display format associated with a private format

$CF_DSPBITMAP - Bitmap display format associated with a private format

$CF_DSPMETAFILEPICT - Metafile picture display format associated with a private format

$CF_DSPENHMETAFILE - Enhanced metafile display format associated with a private format

I can read the help-file by my self, and when someone ask help you and your friends just post the help file. Ohhhh this is a very nice help!

thank you at all. Who are you? Ahhh yes you are a "guru", and the gure do not help no one! But you can need help in future in your life that no concern the autoIT...and I hope that no one help you! You will read the help file :)

Have a good day, and please do not replay anymore.

Link to comment
Share on other sites

MaxNMB

Hi! Example:

#include <GuiConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test GUI", 800, 600)

$hPic = GUICtrlCreatePic("", 0, 0, 800, 600)
GUICtrlSetState(-1, $GUI_DISABLE)

GUISetState()

_SetBackground()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetBackground()
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    
    Local $hParent, $hChild, $hBitmap, $hWnd
    
    Run("mspaint " & @SystemDir & "\setup.bmp")
    
    WinWait("[Class:MSPaintApp]")
    
    Local $hParent = WinGetHandle("[Class:MSPaintApp]")
    Local $hChild = ControlGetHandle($hParent, "", "Afx:1000000:81")
    
    WinActivate($hParent)
    
    $hBitmap = _ScreenCapture_CaptureWnd("", $hChild)
    
    WinClose($hParent)
    
    $hWnd = GUICtrlGetHandle($hPic)
    If $hWnd = 0 Then Return SetError(2, 0, 0)
    
    DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(3, 0, 0)
    
    _WinAPI_DeleteObject($hBitmap)
EndFunc
:)

Thanks very much for your replay. I'm very glad to you.

But i'm not asking this. My be is my bad english, i'm sorry! I try to explane:

I have a file "photo.jpg" in my script dir. (is not a bmp file is a jpg file)

So i guess open a file (it's ok in your example with paint)

I would place simple into clipboard.

Thats all!!

Then i close the script, i will go in othere application (database FilemakerPro, and then I'll paste with a simple CTRL+v

is possibile to do that?

thanks

Link to comment
Share on other sites

Finally, I got it to work:

http://www.answers.com/topic/clipboard-bitmap?cat=technology

#include <ClipBoard.au3>
$GUI = GUICreate("GUI clipimage")
;~ $h = _WinAPI_GetModuleHandle("")
$hBitmap = _WinAPI_LoadImage("","C:\WINDOWS\Angler.bmp", $IMAGE_BITMAP, 128,128, $LR_LOADFROMFILE)

_ClipBoard_Open($GUI)
_ClipBoard_Empty()
_ClipBoard_SetDataEx( $hBitmap, $CF_BITMAP)
_ClipBoard_Close()
If Not _ClipBoard_IsFormatAvailable($CF_BITMAP)  Then
        MsgBox(0,"", "There was an error while pasting the bitmap to the clipboard!")
EndIf

I tried to do this often, but now it works ?!?

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Finally, I got it to work:

http://www.answers.com/topic/clipboard-bitmap?cat=technology

#include <ClipBoard.au3>
$GUI = GUICreate("GUI clipimage")
;~ $h = _WinAPI_GetModuleHandle("")
$hBitmap = _WinAPI_LoadImage("","C:\WINDOWS\Angler.bmp", $IMAGE_BITMAP, 128,128, $LR_LOADFROMFILE)

_ClipBoard_Open($GUI)
_ClipBoard_Empty()
_ClipBoard_SetDataEx( $hBitmap, $CF_BITMAP)
_ClipBoard_Close()
If Not _ClipBoard_IsFormatAvailable($CF_BITMAP)  Then
        MsgBox(0,"", "There was an error while pasting the bitmap to the clipboard!")
EndIf

I tried to do this often, but now it works ?!?

Well done ProgAndy. That's the first successful script on the AutpIt Forums I've seen that loads an image to clipboard.

FYI see http://www.autoitscript.com/forum/index.ph...st&p=514590

Shows getting image from clipboard.

Link to comment
Share on other sites

Now, I made a better UDf from it :)

The problems of the other Scripts were the differencies between GDI32-HBITMAP and GDIPlus-HBITMAP. Now I fpund a way to convert them easily :(. I found it on http://weblogs.foxite.com/vfpimaging/archi...01/09/3103.aspx

The UDF: http://www.autoitscript.com/forum/index.php?showtopic=70237

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

ProgAndy,

Thank you very much!! that's what I wanted. Great !

Now a little problem: if I have a JPG file and not a BMP, is possible to load and copy to clipboard too? ( this becouse naturally when i'll go to paste in other application, the image.jpg file is less heavy of a image.bmp file! )

I belevie that it is impossible becouse is not way to handle a jpg format file. is true? If I mistake, can show me how do that? Which kind of parameter is possible to use for image?

Help file report for the IMAGE structure only:

$CF_BITMAP - Handle to a bitmap (HBITMAP)

$CF_METAFILEPICT - Handle to a metafile picture (METAFILEPICT)

$CF_TIFF - Tagged image file format

$CF_DIB - BITMAPINFO structure followed by the bitmap bits

$CF_OWNERDISPLAY - Owner display format

$CF_DSPBITMAP - Bitmap display format associated with a private format

$CF_DSPMETAFILEPICT - Metafile picture display format associated with a private format

I tried to change your code with the parameters above...but no way!

Anyway Thanks again, have a nice day.

Max

Edited by MaxNMB
Link to comment
Share on other sites

ProgAndy,

Thank you very much!! that's what I wanted. Great !

Now a little problem: if I have a JPG file and not a BMP, is possible to load and copy to clipboard too? ( this becouse naturally when i'll go to paste in other application, the image.jpg file is less heavy of a image.bmp file! )

I belevie that it is impossible becouse is not way to handle a jpg format file. is true? If I mistake, can show me how do that? Which kind of parameter is possible to use for image?

If you look and run ProgAndy's UDF It will load a JPG file to clipboard. I just tried it. Also tried Gif, png, and Bmp files with success. Could not load tif file. He has an example file at the bottom of his UDF where you can change the file path/name to suit you.

His link repeated here is:-

http://www.autoitscript.com/forum/index.ph...st&p=514857

To state to obvious, you do have to paste into a graphics area like MS Paint.

ProgAndy has made it too easy for us.

Edited by Malkey
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...