covaks Posted May 23, 2008 Share Posted May 23, 2008 I want to be able to store clipboard data in my program and retrieve it later. Text works fine, but now I want to get screenshots working. I made a little example program to show the problem. I want to be able to take a screenshot, and click on the "Pic" button to have it stored there. Then copy some text and have it stored when I click on the "Text" button. Then, if I click on the "Pic" button a second time, it should place back into the clipboard the screenshot. The problem is, when I open up mspaint and try to paste, and error message box pops up saying "Error getting the clipboard data!". Also, is there an easier way to handle different formats? I tried just _ClipBoard_GetData() and _ClipBoard_SetData($vData), but that didn't seem to work. Am I going to have to determine what type of data is on the clipboard first, then call the get/set functions with the appropriate format? The help for GetData/SetData seem to indicate they will take care of that for me if I can use them correctly. expandcollapse popup#include <ClipBoard.au3> #include <Misc.au3> opt("GUIOnEventMode",1) Global $vClip1, $vClip2, $bClip1 = False, $bClip2 = False $hWnd = GuiCreate("") $hButton1 = GuiCtrlCreateButton("Pic",5,5,50) GUICtrlSetOnEvent(-1,"Button1") $hButton2 = GuiCtrlCreateButton("Text",5,30,50) GuiCtrlSetOnEvent(-1,"Button2") GuiSetState() While 1 Sleep(10) WEnd Func Button1() ; Hold CTRL while clicking button to clear. If _IsPressed("11") Then $vClip1 = "" GUICtrlSetBkColor($hButton1,0xCCCCCC) $bClip1 = False Return EndIf If Not $bClip1 Then ConsoleWrite("Getting data from clipboard.." & @CRLF) $bClip1 = True _ClipBoard_Open(0) $vClip1 = _ClipBoard_GetData($CF_BITMAP) GUICtrlSetBkColor($hButton1,0x00FF00) _ClipBoard_Close() ElseIf $bClip1 Then ConsoleWrite("Setting data to clipboard.." & @CRLF) _ClipBoard_Open(0) If _ClipBoard_SetData($vClip1, $CF_BITMAP) = 0 Then Consolewrite("Failed to set data.." & @CRLF) If _ClipBoard_IsFormatAvailable($CF_BITMAP) Then ConsoleWrite("Bitmap format available on clipboard" & @CRLF) _ClipBoard_Close() EndIf EndFunc Func Button2() If _IsPressed("11") Then $vClip2 = "" GUICtrlSetBkColor($hButton2,0xCCCCCC) $bClip2 = False Return EndIf If Not $bClip2 Then $bClip2 = Not $bClip2 _ClipBoard_Open(0) $vClip2 = _ClipBoard_GetData() GUICtrlSetBkColor($hButton2,0x00FF00) _ClipBoard_Close() ElseIf $bClip2 Then _ClipBoard_Open(0) _ClipBoard_Empty() _ClipBoard_SetData($vClip2) _ClipBoard_Close() EndIf EndFunc Link to comment Share on other sites More sharing options...
sandin Posted May 23, 2008 Share Posted May 23, 2008 don't use _ClipBoard_GetData() (or set data), instead of that use this command: _ClipBoard_GetDataEx() (or setDataEx) try this script (press PringScreen, then F11, then try paste it to paint): #Include <Clipboard.au3> HotKeySet("{F11}", "_display") While 1 Sleep(10) WEnd func _display() Local $var $var = _ClipBoard_GetDataEx($CF_BITMAP) Sleep(100) _ClipBoard_SetDataEx($var, $CF_BITMAP) EndFunc Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
covaks Posted May 23, 2008 Author Share Posted May 23, 2008 Thanks for the reply. Another problem crops up though. I want to be able to store other types of data on the clipboard in the meantime, and recall the bitmap later. As soon as you put some text or something on the clipboard, the SetDataEx function doesn't place the bitmap back in when executed. So for example: #Include <Clipboard.au3> HotKeySet("{F11}", "_display") While 1 Sleep(10) WEnd func _display() Local $var $var = _ClipBoard_GetDataEx($CF_BITMAP) msgbox(0,"","Copy some text from somewhere now, then click Ok here to put image back on clipboard") _ClipBoard_SetDataEx($var, $CF_BITMAP) msgox(0,"","Try pasting into paint now.. It won't work, the text is still on the clipboard") EndFunc Now when the first message box pops up, copy some text from somewhere. Then click OK. Next it should execute the _ClipBoard_SetDataEx($var,$CF_BITMAP) and place the contents of $var back into the clipboard shouldn't it? But it doesn't. If I go into mspaint after and paste, nothing happens. The text is still on the clipboard. Link to comment Share on other sites More sharing options...
sandin Posted May 23, 2008 Share Posted May 23, 2008 try with clipboard open and close: #Include <Clipboard.au3> HotKeySet("{F11}", "_display") $GUI = GUICreate("title", 200, 200) While 1 Sleep(10) WEnd func _display() _ClipBoard_Open ($GUI) Local $var $var = _ClipBoard_GetDataEx($CF_BITMAP) msgbox(0,"","Copy some text from somewhere now, then click Ok here to put image back on clipboard") _ClipBoard_SetDataEx($var, $CF_BITMAP) _ClipBoard_Close() EndFunc Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
sandin Posted May 23, 2008 Share Posted May 23, 2008 huh, it works only in that case, it doesn't work when you copy something else (not msgbox) while msgbox is opened. Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
covaks Posted May 23, 2008 Author Share Posted May 23, 2008 So, it doesn't work as expected for you either right? 1. I press print screen to take a screenshot 2. Run your latest script 3. When the message box pops up, I open notepad and copy some text, eg: "Foo" 4. Then click ok on the message box 5. Then try to paste into paint. It gives me the same error I was getting in my original script, "Error getting the clipboard data!" If after running your script above, I run the example script in the helpfile for _ClipBoard_FormatStr it shows the formats on the clipboard as Bitmap, DIB and DIB V5. The same as it does if I run it right after pressing print screen. So the _ClipBoard_SetDataEx function is putting something back on the clipboard with the same format. But something must be missing that is preventing it from pasting properly. 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