abcjeff Posted April 17, 2023 Share Posted April 17, 2023 Try to copy the bitmap of a image file to clipboard then paste into MS Paint, but Paint doesn't recognize the data and show an error. In fact Paint even freeze for a while. $rst is not 0, meaning _ClipBoard_SetDataEx succeed, but the image is not in the clipboard viewer and can't be paste into other program. Here is the code: #include <Constants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIHObj.au3> #include <File.au3> #include <Clipboard.au3> _GDIPlus_Startup() _ClipBoard_Open(0) Global $hBmp = _GDIPlus_BitmapCreateFromFile("C:\Users\olnw\Desktop\123.jpg") $hImage = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) $rst = _ClipBoard_SetDataEx($hImage, $CF_BITMAP) MsgBox(0,$rst,$rst) ;_GDIPlus_BitmapDispose($hImage) ;_WinAPI_DeleteObject($hBmp) ;_GDIPlus_Shutdown() ;_ClipBoard_Close() Paint error message: Link to comment Share on other sites More sharing options...
ioa747 Posted April 17, 2023 Share Posted April 17, 2023 (edited) edit: and if you want to use ms-pant, in main script (SmartNote) is a function Func _PicToClip($Path) ; use ms-paint to copy image to clipboard Edited April 17, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Solution ioa747 Posted April 17, 2023 Solution Share Posted April 17, 2023 to forum I know that I know nothing Link to comment Share on other sites More sharing options...
abcjeff Posted April 17, 2023 Author Share Posted April 17, 2023 17 minutes ago, ioa747 said: Thank you. _WinAPI_CopyImage did the trick. Link to comment Share on other sites More sharing options...
KaFu Posted April 17, 2023 Share Posted April 17, 2023 #include <GDIPlus.au3> #include <Clipboard.au3> _GDIPlus_Startup() _ClipBoard_Open(0) Local $hBmp = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\test.png") Local $hImage = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) Local $res = _ClipBoard_SetDataEx(_WinAPI_CopyImage($hImage), $CF_BITMAP) _WinAPI_DeleteObject($hImage) _GDIPlus_BitmapDispose($hBmp) _ClipBoard_Close() _GDIPlus_Shutdown() OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
ioa747 Posted April 17, 2023 Share Posted April 17, 2023 @KaFu it gives me the below error Local $res = _ClipBoard_SetDataEx(_WinAPI_CopyImage($hImage), $CF_BITMAP) : error: _ClipBoard_SetDataEx() called with Const or expression on ByRef-param(s). I know that I know nothing Link to comment Share on other sites More sharing options...
KaFu Posted April 17, 2023 Share Posted April 17, 2023 Caused by the "ByRef" of $hMemory in _ClipBoard_SetDataEx(), design decision and should not change the functionality. Not sure why it throws an error for you, and not for me 🙄. Maybe because I run the latest Beta of Au3Check.exe? #include <GDIPlus.au3> #include <Clipboard.au3> _GDIPlus_Startup() _ClipBoard_Open(0) Global $hBmp = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\test.png") Global $hImage = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) Global $hImage_Copy = _WinAPI_CopyImage($hImage) Global $res = _ClipBoard_SetDataEx($hImage_Copy, $CF_BITMAP) _WinAPI_DeleteObject($hImage) _GDIPlus_BitmapDispose($hBmp) _ClipBoard_Close() _GDIPlus_Shutdown() OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
ioa747 Posted April 17, 2023 Share Posted April 17, 2023 OK with this I know that I know nothing Link to comment Share on other sites More sharing options...
Nine Posted April 17, 2023 Share Posted April 17, 2023 NOT a good idea to put _WinAPI_CopyImage as a parameter or simply said : not with a delete object. Eventually this will create a large memory leak. Like the Beatles said : Dear Prudence “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
KaFu Posted April 17, 2023 Share Posted April 17, 2023 (edited) Object is handed to system clipboard and must not be deleted by script. Edit: Run this and check with task-manager #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> #include <Clipboard.au3> For $i = 1 To 1000 Sleep(1000) _GDIPlus_Startup() _ClipBoard_Open(0) Global $hBmp = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\test.png") Global $hImage = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) Global $hImage_Copy = _WinAPI_CopyImage($hImage) ConsoleWrite(@AutoItPID & @tab & $i & @tab & $hImage_Copy & @crlf) Global $res = _ClipBoard_SetDataEx($hImage_Copy, $CF_BITMAP) _WinAPI_DeleteObject($hImage) _GDIPlus_BitmapDispose($hBmp) _ClipBoard_Close() _GDIPlus_Shutdown() Next Edited April 18, 2023 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Nine Posted April 18, 2023 Share Posted April 18, 2023 Good catch @KaFu. Per help file on _ClipBoard_SetDataEx. Quote 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 KaFu 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
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