Sign in to follow this  
Followers 0
EvilRubberDuck

Clipboard open

9 posts in this topic

#1 ·  Posted (edited)

#include <GDIPlus.au3>
#include <ClipBoard.au3>

; Capture full screen
Send("{PRINTSCREEN}") ; Screen
;Send("!{PRINTSCREEN}") ; window

_Main()

ShellExecute(@ScriptDir & "\Image.jpg")

Func _Main()
    Local $hBmp, $hImage

    If Not _ClipBoard_Open(0) Then _WinAPI_ShowError("_ClipBoard_Open failed")
    $hBmp = _ClipBoard_GetDataEx($CF_BITMAP)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)

    ; Save bitmap to file
    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Image.jpg") ;$sNewName)

    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_Shutdown()
    _ClipBoard_Close()

EndFunc ;==>_Main

Hey guys! I got this code from this post:

 

On 6/10/2010 at 11:46 PM, Malkey said:

Max Kipness

 

Your example appears to be trying to combine these two methods.

 

#include <ScreenCapture.au3>

_ScreenCapture_Capture(@ScriptDir & "\GDIPlus_Image.jpg")
ShellExecute(@ScriptDir & "\GDIPlus_Image.jpg")

and

 

#include <GDIPlus.au3>
#include <ClipBoard.au3>

; Capture full screen
Send("{PRINTSCREEN}") ; Screen
;Send("!{PRINTSCREEN}") ; window

_Main()

ShellExecute(@ScriptDir & "\Image.jpg")

Func _Main()
    Local $hBmp, $hImage

    If Not _ClipBoard_Open(0) Then _WinAPI_ShowError("_ClipBoard_Open failed")
    $hBmp = _ClipBoard_GetDataEx($CF_BITMAP)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)

    ; Save bitmap to file
    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Image.jpg") ;$sNewName)

    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_Shutdown()
    _ClipBoard_Close()

EndFunc ;==>_Main

But i get the error: Clipboar open failed. 

Anyone can help me?

 

Thank you

Edited by EvilRubberDuck

Share this post


Link to post
Share on other sites



Looks like a bit has changed since 6 years ago code wise. I'm checking https://www.autoitscript.com/autoit3/docs/libfunctions/Clipboard Management.htm for what has and I'll see what I can do.


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

Not seeing anything yet, but if you're really just trying to save a screenshot and nothing else I'd recommend using the example from:

https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_SaveImage.htm


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

I know of that function, but i need it to be using the print screen key. 

I tried to add more #include, close the clipboard before open it but i couldn't get it to work. :/

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I read this:  This function fails if another window has the clipboard open.

And tried to use this function ( _ClipBoard_GetOpenWindow ) before open clipboard to see if any window has clipboard opened and i got this: 0x00010010.

But i don't know how to identify the window with this handle :/ If it is any window.

 

Edited by EvilRubberDuck

Share this post


Link to post
Share on other sites
3 minutes ago, EvilRubberDuck said:

I read this:  This function fails if another window has the clipboard open.

And tried to use this function ( _ClipBoard_GetOpenWindow ) before open clipboard to see if any window has clipboard opened and i got this: 0x00010010.

But i don't know how to identify the window with this handle :/ If it is any window.

 

You can use Example 2 from https://www.autoitscript.com/autoit3/docs/functions/WinList.htm to find out


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

#include <GDIPlus.au3>
#include <ClipBoard.au3>
#include <MsgBoxConstants.au3>



; Capture full screen
Send("{PRINTSCREEN}") ; Screen
;Send("!{PRINTSCREEN}") ; window

_Main()

ShellExecute(@ScriptDir & "\Image.jpg")

Func _Main()
    Local $hBmp, $hImage

    MsgBox(0,"ola", _ClipBoard_GetOpenWindow () )
    If Not _ClipBoard_Open(0) Then _WinAPI_ShowError("_ClipBoard_Open failed")
    $hBmp = _ClipBoard_GetDataEx($CF_BITMAP)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)

    ; Save bitmap to file
    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Image.jpg") ;$sNewName)

    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_Shutdown()
    _ClipBoard_Close()

EndFunc ;==>_Main

I just want to laugh... so if i put the msgbox there to show me the handle of the window wih clipboard open it actually works the whole code. I get the printscreen. If i take ou that line it doesn't work... Maybe if i put a sleep fucntion ...

 

Edit: Yap! If i put sleep(100) before clipboard_open, the code works! Maybe it takes more time to get the print to the clipboard than it gets to autoit to get from line 5 to line 15. It must be it right?

 

Edited by EvilRubberDuck

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

29 minutes ago, EvilRubberDuck said:

I used it and didn't get any window with that handle!

DRAMATIC MUSIC INTENSIFIES

 

33 minutes ago, EvilRubberDuck said:

I just want to laugh... so if i put the msgbox there to show me the handle of the window wih clipboard open it actually works the whole code. I get the printscreen. If i take ou that line it doesn't work... Maybe if i put a sleep fucntion ...

 

Edit: Yap! If i put sleep(100) before clipboard_open, the code works! Maybe it takes more time to get the print to the clipboard than it gets to autoit to get from line 5 to line 15. It must be it right?

 

Glad your issue got resolved. Perhaps the printscreen button just doesn't like closing early which is what that window handle was.

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

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