Just starting out? Need help? Post your questions and find answers here.
Marco2007
Enthusiast
Posts: 648 Joined: Tue Jun 12, 2007 10:30 am
Location: not there...
Post
by Marco2007 » Sun Oct 21, 2007 2:05 pm
Hi,
is there any chance to copy a file to the clipboard, then runprogram("word.doc") and just press ctrl-v to paste the file?
just like that:
I originally posted that on the German forum:
http://www.purebasic.fr/german/viewtopic.php?t=14603
thanx
Marco
Sparkie
PureBatMan Forever
Posts: 2307 Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA
Post
by Sparkie » Tue Oct 30, 2007 2:02 am
I've pieced this together from various sources (Google). It's a long shot but it might be worth a try. I don't have Word here so I can't say if it works or not with the #CF_HDROP format. It does NOT work with WordPad nor OpenOffice.
(It DOES work for pasting a file into Explorer
)
Code: Select all
Procedure CopyFile2ClipBoard(file.s)
clipFile = 0
If OpenClipboard_(0)
EmptyClipboard_()
hGlobal = GlobalAlloc_(#GHND, SizeOf(DROPFILES) + Len(file) + 2)
If hGlobal
*lpGlobal.DROPFILES = GlobalLock_(hGlobal)
ZeroMemory_(*lpGlobal, SizeOf(DROPFILES))
*lpGlobal\pFiles = SizeOf(DROPFILES)
*lpGlobal\fWide = 0
*lpGlobal\fNC = 0
*lpGlobal\pt\x = 0
*lpGlobal\pt\y = 0
CopyMemory_((*lpGlobal + SizeOf(DROPFILES)), @file, Len(file) + 2)
GlobalUnlock_(hGlobal)
If SetClipboardData_(#CF_HDROP, hGlobal)
;SetClipboardData_(#CF_TEXT, file)
clipFile = #True
EndIf
EndIf
CloseClipboard_()
EndIf
ProcedureReturn clipFile
EndProcedure
file2copy.s = OpenFileRequester("Select file to copy to the ClipBoard", "", "All files|*.*", 0)
If file2copy
CopyFile2ClipBoard(file2copy)
;RunProgram("Wordpad")
EndIf
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
Marco2007
Enthusiast
Posts: 648 Joined: Tue Jun 12, 2007 10:30 am
Location: not there...
Post
by Marco2007 » Wed Oct 31, 2007 10:07 pm
Sparkie
PureBatMan Forever
Posts: 2307 Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA
Post
by Sparkie » Thu Nov 01, 2007 1:17 am
You're welcome....... I guess we got lucky with that one
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
Marco2007
Enthusiast
Posts: 648 Joined: Tue Jun 12, 2007 10:30 am
Location: not there...
Post
by Marco2007 » Thu May 29, 2008 8:51 pm
Hi Sparkie,
sorry for being nasty again.
Do you know, what I have to do to get this one work
?
thanx
marco
PureBasic for Windows
akj
Enthusiast
Posts: 668 Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham
Post
by akj » Thu May 29, 2008 10:27 pm
Here's another way to do it:
Code: Select all
Procedure CopyFile2ClipBoard(file.s)
Protected clipFile = 0
Protected *mem, fil
Protected fez = FileSize(file)
If fez>0
*mem = AllocateMemory(fez+2)
fil = ReadFile(#PB_Any, file)
clipfile = ReadData(fil, *mem, fez)
CloseFile(fil)
SetClipboardText(PeekS(*mem, fez))
FreeMemory(*mem)
EndIf
ProcedureReturn clipfile
EndProcedure
Define file2copy.s
file2copy = OpenFileRequester("Select file to copy to the ClipBoard", "", "All files|*.*", 0)
If file2copy
CopyFile2ClipBoard(file2copy)
RunProgram("Wordpad")
EndIf
End
Anthony Jordan
ar-s
Enthusiast
Posts: 344 Joined: Sat Oct 06, 2007 11:20 pm
Location: France
Post
by ar-s » Mon Jun 02, 2008 1:17 pm
Thanks for that cool procedure
PB
PureBasic Expert
Posts: 7581 Joined: Fri Apr 25, 2003 5:24 pm
Post
by PB » Mon Apr 13, 2009 1:18 pm
> Here's another way to do it
Sorry, akj, but your way doesn't work for me. I copy an exe file with it,
but I can't paste it in Explorer like Sparkie's code does. Don't know why.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
rsts
Addict
Posts: 2736 Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA
Post
by rsts » Mon Apr 13, 2009 1:27 pm
PB wrote: > Here's another way to do it
I can't paste it in Explorer like Sparkie's code does. Don't know why.
maybe setClipboardText has something to do with it?
Peeks isn't going to handle an exe.
cheers