graydwarf Posted March 6, 2015 Posted March 6, 2015 _ScreenCapture_CaptureWnd ( $g_SnapShotDirectory & "\" & $g_sSnapShotName & "_Edited.jpg", $g_SnapShotWindow, 0 , 0, -1, -1, False ) ; Save a copy to disk _GDIPlus_Startup() Local $hImg = _GDIPlus_ImageLoadFromFile($g_SnapShotDirectory & "\" & $g_sSnapShotName & "_Edited.jpg") Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) _GDIPlus_ImageDispose($hImg) _GDIPlus_Shutdown() _ClipBoard_SetData($hBitmap) Repro Steps: - Capture screenshot of window, save to disk - Load image from disk - Convert it into a HBITMAP - Place the image on the clipboard Results: - Nothing getting on the clipboard (pasting into mspaint not working) Expected: - Image is placed on clipboard so I can paste it into other apps. I'm missing something because many other people have done this and this code is pretty much copy/paste out of other forum posts. What am I doing wrong? I tried adding $CF_BITMAP for the iFormat param but nothing changed.
graydwarf Posted March 6, 2015 Author Posted March 6, 2015 If I chang the '_ClipBoard_SetData' call to '_ClipBoard_SetDataEx' and then try capturing and pasting, I get an error from mspaint which is; "The information on the Clipboard can't be inserted into Paint."
Solution UEZ Posted March 6, 2015 Solution Posted March 6, 2015 You have to use _WinAPI_CopyImage _ClipBoard_SetDataEx to put a GDI image to the clipboard. Not tested example $hHBitmap = _ScreenCapture_CaptureWnd ("", $g_SnapShotWindow, 0 , 0, -1, -1, False ) $hClipboard_Bitmap = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) _WinAPI_DeleteObject($hHBitmap) _ClipBoard_Open(0) $hCP = _ClipBoard_SetDataEx($hClipboard_Bitmap, $CF_BITMAP) _ClipBoard_Close() graydwarf 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
graydwarf Posted March 7, 2015 Author Posted March 7, 2015 You have to use _WinAPI_CopyImage _ClipBoard_SetDataEx to put a GDI image to the clipboard. Not tested example $hHBitmap = _ScreenCapture_CaptureWnd ("", $g_SnapShotWindow, 0 , 0, -1, -1, False ) $hClipboard_Bitmap = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) _WinAPI_DeleteObject($hHBitmap) _ClipBoard_Open(0) $hCP = _ClipBoard_SetDataEx($hClipboard_Bitmap, $CF_BITMAP) _ClipBoard_Close() That did the trick! Thank you!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now