Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Clipboard API help



  • Please log in to reply
2 replies to this topic
Saturday
  • Members
  • 2 posts
  • Last active: Mar 14 2015 06:10 AM
  • Joined: 10 Mar 2015

Hi forum :)

I'm confused with the ahks API interface since the manual isn't explaining it very well so i decided to ask for your help. i'm basically trying to make a line of code that outputs the image content of the clipboard to a file.

#Persistent
return

OnClipboardChange:
hue := DllCall("GetClipBoardData", "UInt", CF_Bitmap)
FileAppend, %hue%, %A_ScriptDir%\add1.bmp
Sleep, 500
return

I tried coding it like the one above but it only outputs a blank file.

I'm kinda new to coding and i don't know much of the advanced stuff so please help.



Elgin
  • Members
  • 79 posts
  • Last active: Dec 18 2015 08:07 PM
  • Joined: 29 Jul 2011

Hi!

 

It's a bit more complex:

- The clipboard needs to be opnend before you can access its data

- CF_Bitmap is not defined in Autohotkey, so you need to use its value (2)

GetClipBoardData does not return a bitmap but only a handle to a bitmap which needs to be converted to an actual bitmap first. Doing so is easiest with the GDI+ library by tic which can be found here: http://www.autohotke...ary-145-by-tic/

 

This should work:

#Persistent
#Include Gdip.ahk
return

OnClipboardChange:
	sfileto:="add1.bmp"
	pToken:=Gdip_Startup()
	DllCall("OpenClipboard", "Uint", 0)
	If	 DllCall("IsClipboardFormatAvailable", "Uint", 2) && (hBM:=DllCall("GetClipboardData", "Uint", 2)) 
	{
		pBitmap:=Gdip_CreateBitmapFromHBITMAP(hbm)
		Gdip_SaveBitmapToFile(pBitmap, sfileto)
                Gdip_DisposeImage(pBitmap)
	}
	DllCall( "CloseClipboard" )
	Gdip_Shutdown(pToken)
return




Saturday
  • Members
  • 2 posts
  • Last active: Mar 14 2015 06:10 AM
  • Joined: 10 Mar 2015
✓  Best Answer

 

Hi!

 

It's a bit more complex:

- The clipboard needs to be opnend before you can access its data

- CF_Bitmap is not defined in Autohotkey, so you need to use its value (2)

GetClipBoardData does not return a bitmap but only a handle to a bitmap which needs to be converted to an actual bitmap first. Doing so is easiest with the GDI+ library by tic which can be found here: http://www.autohotke...ary-145-by-tic/

 

This should work:

#Persistent
#Include Gdip.ahk
return

OnClipboardChange:
	sfileto:="add1.bmp"
	pToken:=Gdip_Startup()
	DllCall("OpenClipboard", "Uint", 0)
	If	 DllCall("IsClipboardFormatAvailable", "Uint", 2) && (hBM:=DllCall("GetClipboardData", "Uint", 2)) 
	{
		pBitmap:=Gdip_CreateBitmapFromHBITMAP(hbm)
		Gdip_SaveBitmapToFile(pBitmap, sfileto)
                Gdip_DisposeImage(pBitmap)
	}
	DllCall( "CloseClipboard" )
	Gdip_Shutdown(pToken)
return


Thank you very much for your help!
It finally worked.

So what I was trying wasn't as simple as i thought.