Sign in to follow this  
Followers 0
Sundance

edit screencapture and put it to clipboard problem

11 posts in this topic

Hiho folks.

Its time again for me to have a little problem i can't solve:

Following i will try:

- take a screen capture

- modify the capture (add time stamp and some text)

- put the capture to the clipboard

At the moment the script does :

$hBitmap = _ScreenCapture_Capture("", $iX1 + 1, $iY1 + 1, $iX2-1, $iY2-1, False)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
_GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "\Capture.bmp")
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )

The saved picture contains the "Hello" string but the SetDataEx command returns with a 0.

And i can't figure out why.

$hBitmap is a handle to a HBITMAP

$hImage is a handle to a bitmap object

$hGraphic is a handle to a graphic object

_GDIPlus_BitmapCreateHBITMAPFromBitmap needs a handle to a bitmap object (=>$hImage) and returns a handle to a HBITMAP (=>$hBitmap2)

_ClipBoard_SetDataEx gets the handle to the HBITMAP object (=>$hBitmap2) and the format parameter $CF_BITMAP

So everthing seems right but SetDataEx won't work.

Has somebody a hint for me?

thx in advance

Sundance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try:

_ClipBoard_Open(0)
_ClipBoard_Empty()
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
_ClipBoard_Close()

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thx UEZ for the fast reply. I tried and overlooked my code but it won't function. The 0 result of the _CliBoard_SetDataEx was my failure. I mistyped the $iResult variable in the consolewrite with $iresult :-)

Here is a little testscript which also won't do:

#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
$hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
$hImage  = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
ConsoleWrite("$hImage: " & $hImage & @CRLF)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
ConsoleWrite("$hGraphic: " & $hGraphic & @CRLF)
    _GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
_GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "Capture.bmp")
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
ConsoleWrite("$hBitmap2: " & $hBitmap2 & @CRLF & "$iresult: " & $iResult & @CRLF)

_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

The saved picture is fine but nothing is in the clipboard...

thx

Sundance

Share this post


Link to post
Share on other sites

Try this code:

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
$hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
$hImage  = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
ConsoleWrite("$hImage: " & $hImage & @CRLF)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
ConsoleWrite("$hGraphic: " & $hGraphic & @CRLF)
    _GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
;~ _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "Capture.bmp")
$hBitmap2 = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
ConsoleWrite("$hBitmap2: " & $hBitmap2 & @CRLF & "$iresult: " & $iResult & @CRLF)

_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
    Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
    If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CopyImage

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It works. Many thanks. But why doesn't my script work? It should be....

I tried the whole day to get it running and you need minutes... (shame on me)

thx

Sundance

PS: Ich werd blass. Wie bist du darauf gekommen? Danke Dir!! :idea:

Edited by Sundance

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It works. Many thanks. But why doesn't my script work? It should be....

I tried the whole day to get it running and you need minutes... (shame on me)

thx

Sundance

PS: Ich werd blass. Wie bist du darauf gekommen? Danke Dir!! :idea:

Ich hatte das gleiche Problem mit dem Windows Screenshooter ;)

Gruß,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Try this code:

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
$hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
ConsoleWrite("$hImage: " & $hImage & @CRLF)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
ConsoleWrite("$hGraphic: " & $hGraphic & @CRLF)
_GDIPlus_GraphicsDrawString ( $hGraphic, "Hello", 10, 3, "Arial", 12)
;~ _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "Capture.bmp")
$hBitmap2 = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP )
ConsoleWrite("$hBitmap2: " & $hBitmap2 & @CRLF & "$iresult: " & $iResult & @CRLF)

_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
    Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
    If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
    Return $Ret[0]
EndFunc ;==>_WinAPI_CopyImage

Br,

UEZ

Hello!

I'm using your script to copy a png to clipboard (only way i found to paste images in Excel) but it copies to png file without transparency.

Is it possible to preserve transparency?

Here's your script edited to use an already existing image file (png):

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hBitmap, $hBitmap2, $hImage, $iResult
;~ $hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_GDIPlus_Startup()
;~ $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "frame.png")
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
$hBitmap2 = _WinAPI_CopyImage(_GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitMap2, $CF_BITMAP )
_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown ( )

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
Return $Ret[0]
EndFunc ;==>_WinAPI_CopyImage
Edited by telmob

Share this post


Link to post
Share on other sites

I searched the web for a solution and found this link: http://www.notesoncode.com/articles/2010/08/16/HandlingTransparentImagesOnTheClipboardIsForSomeReasonHard.aspx

I tried to convert a part of it but something is still wrong here!

#include <Constants.au3>
#include <Clipboard.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()

Global $hBitmap = _GDIPlus_BitmapCreateFromFile(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png"))

$hHBitmap = WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hHBitmap = ' & $hHBitmap & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

;~ Global $hBitmap2 = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG + $LR_CREATEDIBSECTION) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms648031(v=vs.85).aspx

_ClipBoard_Open(0)
_ClipBoard_Empty()
$iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_DIBV5)
;~ $iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_BITMAP)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iResult = ' & $iResult & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If $iResult Then MsgBox(0, "Success", "Image copied to clipboard properly!", 10)
_ClipBoard_Close()

_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_ShutDown ( )
Exit

;~ Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
;~     Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
;~     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
;~     Return $Ret[0]
;~ EndFunc   ;==>_WinAPI_CopyImage

Func WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    Local Const $tagBITMAPV5HEADER = 'dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;'

    Local Const $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)
    DllStructSetData($tBIV5HDR, 'bV5Size', DllStructGetSize($tBIV5HDR))
    DllStructSetData($tBIV5HDR, 'bV5Width', $Ret[2])
    DllStructSetData($tBIV5HDR, 'bV5Height', $Ret[3])
    DllStructSetData($tBIV5HDR, 'bV5Planes', 1)
    DllStructSetData($tBIV5HDR, 'bV5BitCount', 32)
    DllStructSetData($tBIV5HDR, 'bV5Compression', 3) ; $BI_BITFIELDS = 3
    DllStructSetData($tBIV5HDR, 'bV5SizeImage', $Ret[3] * DllStructGetData($tData, 'Stride'))
    DllStructSetData($tBIV5HDR, 'bV5RedMask', 0x00FF0000)
    DllStructSetData($tBIV5HDR, 'bV5GreenMask', 0x0000FF00)
    DllStructSetData($tBIV5HDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIV5HDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIV5HDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIV5HDR, 'bV5Intent', 4) ; $LCS_GM_IMAGES = 4

    $hResult = _WinAPI_CreateDIBSection(0, $tBIV5HDR, 0, $pBits) ;$DIB_RGB_COLORS = 0

    If (Not @error) And $hResult Then
;~      Local $tPixel
;~      Local $Stride = DllStructGetData($tData, "Stride")
;~      Local $Scan0 = DllStructGetData($tData, "Scan0")
;~      $tBits = DllStructCreate('dword[' & $Ret[2] * $Ret[3] & ']', $pBits)
;~      For $y = 0 To $Ret[3]
;~          For $x = 1 To $Ret[2]
;~              $tPixel = DllStructCreate("int", $Scan0 + ($y * $Stride) + ($x * 4))
;~              $iPixel = DllStructGetData($tPixel, 1)
;~              DllStructSetData($tBits, 1, $iPixel, $x + ($Ret[2] * $y))
;~          Next
;~      Next
        _WinAPI_SetBitmapBits($hResult, $Ret[2] * $Ret[3] * 4, DllStructGetData($tData, 'Scan0'))
    Else
        $hResult = 0
    EndIf
    $tPixel = 0
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
EndFunc   ;==>_GDIPlus_BitmapCreateDIBFromBitmap

Func _WinAPI_SetBitmapBits($hBitmap, $iSize, $pBits)
    Local $Ret = DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hBitmap, 'dword', $iSize, 'ptr', $pBits)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_SetBitmapBits

Func _WinAPI_CreateDIBSection($hDC, $tBITMAPINFO, $iUsage, ByRef $pBits, $hSection = 0, $iOffset = 0)
    $pBits = 0
    Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', $hDC, 'ptr', DllStructGetPtr($tBITMAPINFO), 'uint', $iUsage, 'ptr*', 0, 'ptr', $hSection, 'dword', $iOffset)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    $pBits = $Ret[4]
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CreateDIBSection

I cannot see the issue why it is not working.

Maybe somebody can help here!

Some small corrections to your code:

#include <Constants.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>

Global $hHBitmap, $hBitmap2, $hImage, $iResult
_GDIPlus_Startup()
;~ $hBitmap = _ScreenCapture_Capture("", 10, 10, 300, 300, False)
_ClipBoard_Open(0)
_ClipBoard_Empty()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "frame.png")
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hBitmap2 = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)
$iResult = _ClipBoard_SetDataEx($hBitMap2, $CF_BITMAP )
_ClipBoard_Close()
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hHBitmap)
_WinAPI_DeleteObject($hBitmap2)
_GDIPlus_ShutDown ( )
Exit

Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
Return $Ret[0]
EndFunc ;==>_WinAPI_CopyImage

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks for your reply UEZ.

I'm going nuts over this....

_ClipPutFile works great except for MS-Excel... If i paste it first in a word document (for example) and then copy/paste it manually into Excel it works, but not via autoit automation. :(

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I'm still working on it and I've a bitmapv5 but it is empty...

#include <Constants.au3>
#include <Clipboard.au3>
#include <GDIPlus.au3>
;~ #include  "WinAPIEx.au3"
_GDIPlus_Startup()

Global $hBitmap = _GDIPlus_BitmapCreateFromFile(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png"))

$hHBitmap = WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hHBitmap = ' & $hHBitmap & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

_ClipBoard_Open(0)
_ClipBoard_Empty()

;~ Global $hBitmap2 = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms648031(v=vs.85).aspx

$iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_DIBV5)
;~ $iResult = _ClipBoard_SetDataEx($hHBitmap, $CF_BITMAP)
;~ $iResult = _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iResult = ' & $iResult & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
If $iResult Then MsgBox(0, "Success", "Image copied to clipboard properly!", 10)

_ClipBoard_Close()

_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_Shutdown()
Exit

;~ Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0); from _WinAPIEx by Yashied
;~     Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)
;~     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
;~     Return $Ret[0]
;~ EndFunc   ;==>_WinAPI_CopyImage

Func WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
    Local $aRet, $tData, $pBits, $hResult = 0, $tBIV5HDR, $iBuffLen, $hMem, $pPackedDIBV5, $iStride, $iScan0

    Local Const $tagBITMAPV5HEADER = 'dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;'

    $aRet = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($aRet[0]) Then Return 0

    $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)

    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $iStride = DllStructGetData($tData, "Stride")
    $iScan0 = DllStructGetData($tData, "Scan0")

    $iBuffLen = DllStructGetSize($tBIV5HDR) + $aRet[3] * $iStride
    $hMem = _MemGlobalAlloc($iBuffLen, BitOR(0x2000, 0x002, 0x0040)) ; -> $GMEM_DDESHARE = 0x2000, $GMEM_MOVEABLE = 0x0002, $GMEM_ZEROINIT = 0x0040
    $pPackedDIBV5 = _MemGlobalLock($hMem)
    $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER, $pPackedDIBV5)

    DllStructSetData($tBIV5HDR, 'bV5Size', DllStructGetSize($tBIV5HDR))
    DllStructSetData($tBIV5HDR, 'bV5Width', $aRet[2])
    DllStructSetData($tBIV5HDR, 'bV5Height', $aRet[3])
    DllStructSetData($tBIV5HDR, 'bV5Planes', 1)
    DllStructSetData($tBIV5HDR, 'bV5BitCount', 32)
    DllStructSetData($tBIV5HDR, 'bV5Compression', 3) ; $BI_BITFIELDS = 3
    DllStructSetData($tBIV5HDR, 'bV5SizeImage', $aRet[3] * DllStructGetData($tData, 'Stride'))
    DllStructSetData($tBIV5HDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIV5HDR, 'bV5RedMask', 0x00FF0000)
    DllStructSetData($tBIV5HDR, 'bV5GreenMask', 0x0000FF00)
    DllStructSetData($tBIV5HDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIV5HDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIV5HDR, 'bV5Intent', 4) ; $LCS_GM_IMAGES = 4

    $hResult = _WinAPI_CreateDIBitmap(0, $tBIV5HDR, 0, $pBits) ;$DIB_RGB_COLORS = 0
    $r = _WinAPI_SetBitmapBits($hResult, $aRet[2] * $aRet[3] * 4, $iScan0)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $r = ' & $r & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    _MemGlobalUnlock($hMem)

    Return $hMem
EndFunc   ;==>WinAPI_BitmapCreateDIBFromBitmap

Func _WinAPI_SetBitmapBits($hBitmap, $iSize, $pBits)
    Local $Ret = DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hBitmap, 'dword', $iSize, 'ptr', $pBits)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_SetBitmapBits

Func _WinAPI_CreateDIBitmap($hDC, $tBITMAPINFO, $iUsage, $pBits = 0)
    Local $pBI = DllStructGetPtr($tBITMAPINFO)
    Local $Init = 0
    If $pBits Then
        $Init = 0x04
    EndIf
    Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBitmap', 'hwnd', $hDC, 'ptr', $pBI, 'dword', $Init, 'ptr', $pBits, 'ptr', $pBI, 'uint', $iUsage)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CreateDIBitmap

Func _WinAPI_CreateDIBSection($hDC, $tBITMAPINFO, $iUsage, ByRef $pBits, $hSection = 0, $iOffset = 0)
    $pBits = 0
    Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', $hDC, 'ptr', DllStructGetPtr($tBITMAPINFO), 'uint', $iUsage, 'ptr*', 0, 'ptr', $hSection, 'dword', $iOffset)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    $pBits = $Ret[4]
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CreateDIBSection

Maybe someone has an idea...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

@Sundance, i made a script using 3 Udf's Jscript, I hope to help you.

Link: http://www.mediafire.com/?u3490z4v4dt1yy0

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • rudi
      By rudi
      Hello.
      I fail trying to save content from WhatsApp other then plain text to a file that way, that non-char-content will be preserved in it's correct encoding. e.g. Emojis are spoiled.
      I've tried to do so using just filewrite() as well as forcing UTF
      #include <clipboard.au3> MsgBox(0,"Ready to read clipboard","Mark some WhatsApp content with non-char elements, e.g. Emojis, copy that to your clipboard (CTRL+c), then click OK here.") $ClipContent=_ClipBoard_GetData() ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ClipContent = ' & $ClipContent & @CRLF & '>Error code: ' & @error & @CRLF & "Extended: " & @extended & @CRLF) ;### Debug Console $File="C:\temp\ClipSaveToFile.txt" $h=FileOpen($File,2+8+64) ; overwrite, create path, UTF16 FileWrite($h,$ClipContent) FileClose($h) $h=FileOpen($File,64) $NeuGelesen=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $NeuGelesen = ' & $NeuGelesen & @CRLF & '>Error code: ' & @error & @CRLF & StringLen ($NeuGelesen) & @CRLF ) ;### Debug Console FileClose($h) _ClipBoard_SetData($NeuGelesen) MsgBox(0,"Done","Re-read content of TEMP file was placed to the clipboard. Now paste this into WhatsApp. (Emojis will be spoiled)") I've also tried other encodings (16, 32, 64, 512)

      Or what is a different, functional approach to save WhatsApp Content to File in a way, to be able to to get it back to post it back to WhatsApp?

      Regards, Rudi.
    • AndreyS
      By AndreyS
      Hello to you, dear developers!
      Could you please tell me if there is an easy way to determine if the information was pasted from the clipboard?
      Without any variation of the insertion via Ctrl+V, or through the context menu.
      I revised the Help and many forum topics, but found nothing suitable.
      Can there be any WinAPI system events that determine this event?
    • Nareshm
      By Nareshm
      Its possible to past previously copied text to somewhere with autoit script ?
      If yes, How it ?
      example : Before I copied ABCD and then copied the PQRS, how to past the previously copied ABCD ?
    • mmoalem
      By mmoalem
      I seem to have an issue with clipget() - the following bit of code copy URL from chrome address bar - than using clipget() i try to grab the URL into a variable and input it into a spreadsheet. the script did not put anything into the sheet 
      originally I though it was an issue with  OOo/LibO Calc UDF and posted it there :
       
      than I tried writing $NewURL into a text file and than just a msgbox but it comes blank. (the URL is in the clipboard as i can paste it)
       
      send ("!d") ;select URL in browser send ("^c") ;copy selected URL Local $NewURL = ClipGet() MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, $sTitle, $NewURL ) am I doing something wrong? is there an issue with a URL characters?
    • tcurran
      By tcurran
      Here's a short UDF that will, at least in most cases, detect whether a window can be copied from or pasted to programmatically--for example, by Send()ing ctl-c, ctl-v. This is often disabled when programs (like your AutoIt script) run at a lower UAC integrity level than the application they are trying to operate on.
      #include <WinAPI.au3> Func _WindowIsPasteable($handle) ;accepts window handle; returns true or false whether a window will accept Ctl-C, Ctl-V Local $bCanPaste = True Local $hTestWindowPID = 0 Local $hTestWindowTID = _WinAPI_GetWindowThreadProcessId($handle, $hTestWindowPID) _WinAPI_AttachThreadInput(_WinAPI_GetCurrentThreadId(), $hTestWindowTID, True);attach to window we want to paste into $bCanPaste = _WinAPI_GetFocus() ;Test whether window is paste-able--returns False if it is not _WinAPI_AttachThreadInput(_WinAPI_GetCurrentThreadId, $hTestWindowTID, False);detach from window thread Return $bCanPaste EndFunc Pass it a window handle; it returns true or false whether a window will accept programmatic pasting. The function may not work on the CMD window, since it handles the clipboard uniquely.
      This function works by attaching to the program thread of the window whose handle it receives, then attempting to perform a GetFocus on that thread. In most cases, the attempt will fail if the window will not accept programmatic copy-paste.