The clipboard contains a captured image.
I would like to paste(ctrl+v) the image to the windows explorer contents pane as a file.
(The type of file created is not important.)
Could it be done?
Pasting an image to the Windows Explorer
Re: Pasting an image to the Windows Explorer
one way:
(you would have to choose a custom hotkey, because otherwise it would interfere with ctrl+v)
(you would have to choose a custom hotkey, because otherwise it would interfere with ctrl+v)
Code: Select all
;q:: ;save image on clipboard to a file in the current folder
WinGet, hWnd, ID, A
vDir := JEE_ExpWinGetDir(hWnd)
if !InStr(FileExist(vDir), "D")
{
MsgBox % "error: dir not found:`r`n""" vDir """"
Return
}
pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromClipboard()
vPath := vDir "\z image " A_Now ".png"
Gdip_SaveBitmapToFile(pBitmap, vPath)
Gdip_Shutdown(pToken)
MsgBox % vPath
Return
;==================================================
JEE_ExpWinGetDir(hWnd="")
{
if (hWnd = "")
WinGet, hWnd, ID, A
WinGetClass, vWinClass, % "ahk_id " hWnd
if (vWinClass = "Progman") || (vWinClass = "WorkerW")
Return A_Desktop
if !(vWinClass = "CabinetWClass") && !(vWinClass = "ExploreWClass")
Return ""
for oWin in ComObjCreate("Shell.Application").Windows
if (oWin.HWND = hWnd)
{
vDir := oWin.Document.Folder.Self.Path
break
}
oWin := ""
Return vDir
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Pasting an image to the Windows Explorer
Thank you for the script. However, I am getting a non-existent function error regarding Gdip_Startup(), Gdip_CreateBitmapFromClipboard(), Gdip_SaveBitmapToFile(), Gdip_Shutdown(), etc.
Re: Pasting an image to the Windows Explorer
jeeswg's code requires the Gdip_All.ahk include:
Code: Select all
#Include <Gdip_All> ; http://www.autohotkey.net/~Rseding91/Gdip%20All/Gdip_All.ahk
Re: Pasting an image to the Windows Explorer
@GEV. Cheers.
An alternative, you create a temporary file, and then cut (or copy) that file to the clipboard, allowing you to use ctrl+v as per usual.
An alternative, you create a temporary file, and then cut (or copy) that file to the clipboard, allowing you to use ctrl+v as per usual.
Code: Select all
q:: ;save image on clipboard to a temporary file, then next time you press ctrl+v the image is moved to the current folder
pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromClipboard()
if (pBitmap > 0)
{
;choose a path for the temporary image
vPath := A_Desktop "\z image " A_Now ".png"
Gdip_SaveBitmapToFile(pBitmap, vPath)
if FileExist(vPath)
JEE_ClipboardSetPaths(vPath, "cut")
MsgBox % vPath
}
else
{
DllCall("CloseClipboard")
MsgBox % "error getting image from clipboard"
}
Gdip_Shutdown(pToken)
Return
;==================================================
JEE_ClipboardSetPaths(vPaths, vDropEffect=0x5)
{
;DROPEFFECT_LINK := 4, DROPEFFECT_MOVE := 2, DROPEFFECT_COPY := 1
(SubStr(vDropEffect, 1, 2) = "cu") ? (vDropEffect := 0x2) : "" ;cut
(SubStr(vDropEffect, 1, 2) = "co") ? (vDropEffect := 0x5) : "" ;copy
;GMEM_ZEROINIT := 0x40, GMEM_MOVEABLE := 0x2
hDrop := DllCall("GlobalAlloc", UInt,0x42, UPtr,20+(StrLen(vPaths)+2)*2, Ptr)
pDrop := DllCall("GlobalLock", Ptr,hDrop, Ptr)
;DROPFILES struct
NumPut(20, pDrop+0, 0, "UInt")
NumPut(1, pDrop+16, 0, "UInt")
;e.g. CF_HDROP with 3 paths: 'path1 null path2 null path3 null null'
vOffset := 20
Loop, Parse, vPaths, `n, `r
if !(A_LoopField = "")
vOffset += StrPut(A_LoopField, pDrop+vOffset, StrLen(A_LoopField)+1, "UTF-16")*2
if !(hWnd := A_ScriptHwnd)
hWnd := WinExist("ahk_pid " DllCall("GetCurrentProcessId", UInt))
;0xF = CF_HDROP
DllCall("GlobalUnlock", Ptr,hDrop)
DllCall("OpenClipboard", Ptr,hWnd)
DllCall("EmptyClipboard")
DllCall("SetClipboardData", UInt,0xF, Ptr,hDrop)
if (vDropEffect = 0)
{
DllCall("CloseClipboard")
return
}
hDropEffect := DllCall("GlobalAlloc", UInt,0x42, UPtr,4, Ptr)
pDropEffect := DllCall("GlobalLock", Ptr,hDropEffect)
DllCall("RtlFillMemory", Ptr,pDropEffect, UPtr,1, UChar,vDropEffect)
DllCall("GlobalUnlock", Ptr,hDropEffect)
vFormat := DllCall("RegisterClipboardFormat", Str,"Preferred DropEffect")
DllCall("SetClipboardData", UInt,vFormat, Ptr,hDropEffect)
DllCall("CloseClipboard")
return
}
Last edited by jeeswg on 04 Apr 2017, 19:58, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Pasting an image to the Windows Explorer
Thank you. Your script works well in sense that the clipboard image is made a file, but the file is directed to the Desktop and not the current Windows Explorer contents pane. How would I go about modifying it?
From my understanding, it seems that the core functions are Gdip_CreateBitmapFromClipboard() and Gdip_SaveBitmapToFile(), which creates a bitmap variable and saves it to a file at a designated path(e.g. Desktop). Could you please explain what the function JEE_ClipboardSetPaths() does?
From my understanding, it seems that the core functions are Gdip_CreateBitmapFromClipboard() and Gdip_SaveBitmapToFile(), which creates a bitmap variable and saves it to a file at a designated path(e.g. Desktop). Could you please explain what the function JEE_ClipboardSetPaths() does?
Re: Pasting an image to the Windows Explorer
I've produced 2 scripts above. The 2nd script had the same description as the 1st, I've now corrected this.
method 1:
- choose a hotkey, but not ctrl+v,
- create an image in the current folder
method 2:
- choose a hotkey, but not ctrl+v,
- create an image in a temporary folder,
- that image is then 'cut' to the clipboard,
- next time you press ctrl+v in an Explorer window/on Desktop, the image is moved from the temporary folder to the current window
I chose Desktop as the temporary folder in the example, normally I would choose some arbitrary folder somewhere, and not Desktop.
functions:
- Gdip_CreateBitmapFromClipboard - image data retrieved from clipboard into AHK's memory
- Gdip_SaveBitmapToFile - image data in AHK's memory saved to a file
- JEE_ExpWinGetDir - get folder path for an Explorer window
- JEE_ClipboardSetPaths - put a list of files onto the clipboard, with a cut/copied drop effect, ctrl+v (paste) will then move/copy the files based on the drop effect
method 1:
- choose a hotkey, but not ctrl+v,
- create an image in the current folder
method 2:
- choose a hotkey, but not ctrl+v,
- create an image in a temporary folder,
- that image is then 'cut' to the clipboard,
- next time you press ctrl+v in an Explorer window/on Desktop, the image is moved from the temporary folder to the current window
I chose Desktop as the temporary folder in the example, normally I would choose some arbitrary folder somewhere, and not Desktop.
functions:
- Gdip_CreateBitmapFromClipboard - image data retrieved from clipboard into AHK's memory
- Gdip_SaveBitmapToFile - image data in AHK's memory saved to a file
- JEE_ExpWinGetDir - get folder path for an Explorer window
- JEE_ClipboardSetPaths - put a list of files onto the clipboard, with a cut/copied drop effect, ctrl+v (paste) will then move/copy the files based on the drop effect
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: marypoppins_1, mikeyww, OrangeCat, RussF and 134 guests