AutoHotkey Community

It is currently May 27th, 2012, 3:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: March 26th, 2010, 7:24 pm 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
Hi, is there any simple method for reading the content of a file (non-text, binary such as graphics or audio data) from Windows Explorer?

Code:
^!4::
Send, ^c
Clipwait
IfExist, %ClipBoard%
FileRead, Clippy, %Clipboard%
Clipboard = %Clippy%
Return


This works for text files, and so I can read a text file into the clipboard or any var while in Explorer. But I'm not getting it to work for graphics files etc. in order to paste them into the appropriate editor. How is this done?

Cheers, ribbet.1


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 26th, 2010, 7:29 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Code:
^!4::
Send, ^c
Clipwait
IfExist, %ClipBoard%
FileRead, Clipboard, *c %Clipboard%
Return


:?:

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 26th, 2010, 7:37 pm 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
sinkfaze wrote:
Code:
^!4::
Send, ^c
Clipwait
IfExist, %ClipBoard%
FileRead, Clipboard, *c %Clipboard%
Return


:?:


Thanks but I don't think that works. Any other ideas?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2010, 7:49 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
If you have irfanview you can do so via the commandline if I'm not mistaken, replace your fileread with pathtoirfanview.exe %clipboard% /clipcopy
-> copy image to the clipboard

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2010, 8:09 pm 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
hugov wrote:
If you have irfanview you can do so via the commandline if I'm not mistaken, replace your fileread with pathtoirfanview.exe %clipboard% /clipcopy
-> copy image to the clipboard


This is a nice workaround solution for a lot of different file types. I think there must not be an easy way of doing this in ahk itself? Can't use clipboardall as an output var.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2010, 8:14 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
I'm sure some wizards like sean or tic will be able to do it all in ahk (perhaps you will find some info in their screenshot (sean) and or gdi+ (tic) scripts and libraries) but it if works it works :-)

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2010, 9:53 pm 
Offline

Joined: February 20th, 2007, 1:37 pm
Posts: 198
Location: D.C.
hugov wrote:
I'm sure some wizards like sean or tic will be able to do it all in ahk (perhaps you will find some info in their screenshot (sean) and or gdi+ (tic) scripts and libraries) but it if works it works :-)


Thanks, HugoV. As always, you rock. I'm still hoping somebody will come along and answer my question with an all-AHK solution. Anything?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2010, 9:57 am 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
to get a graphics file into clipboard maybe:

Code:
fileselectfile,file   ;only graphics files!!


DllCall( "LoadLibrary", Str,"gdiplus" )
VarSetCapacity(si, 16, 0), si := Chr(1)
DllCall( "gdiplus\GdiplusStartup", UIntP,pToken, UInt,&si, UInt,0 )

pBitmap:=Gdip_CreateBitmapFromFile(File)

DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,0 )

SetClipboardData(hBitmap)

DllCall( "gdiplus\GdipDisposeImage", UInt,pBitmap )
DllCall( "gdiplus\GdiplusShutdown", UInt,pToken )
Return                                                     


Gdip_CreateBitmapFromFile(sFile)
{
   VarSetCapacity(wFile, 1023)
   DllCall("kernel32\MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sFile, "Int", -1, "UInt", &wFile, "Int", 512)
   DllCall("gdiplus\GdipCreateBitmapFromFile", "UInt", &wFile, "UInt*", pBitmap)
   Return, pBitmap
}

SetClipboardData(hBitmap)
{
   DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
   hDIB :=   DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
   pDIB :=   DllCall("GlobalLock", "Uint", hDIB)
   DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
   DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
   DllCall("GlobalUnlock", "Uint", hDIB)
   DllCall("DeleteObject", "Uint", hBitmap)
   DllCall("OpenClipboard", "Uint", 0)
   DllCall("EmptyClipboard")
   DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
   DllCall("CloseClipboard")
}



From code made by Sean in screencapture.ahk but all errors and mistakes in this example are from me !!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2010, 9:36 pm 
Thank you! I'm gathering it would take something pretty elaborate to work with just any binary content. I will definitely play with this.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn and 27 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group