AutoHotkey Community

It is currently May 27th, 2012, 8:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: September 22nd, 2009, 7:13 am 
Offline

Joined: March 25th, 2009, 2:04 pm
Posts: 24
I have test the "GetClipboardData" functon with Word, but it returns nothing. Can you tell me why?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2009, 9:10 am 
Offline

Joined: October 27th, 2006, 10:12 am
Posts: 649
.rtf seems to be a complicated topic as there are quite a lot format options, you need to look at the topic really from the detailed perspective.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2009, 12:59 pm 
Offline

Joined: March 25th, 2009, 2:04 pm
Posts: 24
I have tried all the options, but it still return nothing. How about that?

Code:
p::
CF_TEXT = 1
CF_UNICODETEXT = 13
CF_RTF = Rich Text Format
CF_RTFNOOBJS = Rich Text Format Without Objects
CF_DIB = 8
CF_DIBV5 = 17

GetClipboardData(CF_TEXT, str)
MsgBox %str%
GetClipboardData(CF_UNICODETEXT, str)
MsgBox %str%
GetClipboardData(CF_RTF, str)
MsgBox %str%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2009, 8:32 pm 
Offline

Joined: November 8th, 2009, 8:00 pm
Posts: 1
Thanks you very much for your work PhiLho, it works very well !

(although it takes a few hours to get everything working, especially if at first you have no idea how autohotkey or the windows clipboard works...)

Laszlo wrote:
I could only paste the Rich Text clipboard into Word and WordPad. When I attempt pasting it into Notepad or any other application, nothing shows up. They probably need multiple clipboard formats. I wonder, is HTML any better? Could you add support to HTML clipboards?


This script already support this function, I just used it to set a hotkey to send formatted text to notepad, wordpad, open office, and mozilla products.
To do this, you need to add to the clipboard the following types :

CF_TEXT
Rich Text Format (get this one from a wordpad ctrl-c)
HTML Format (and the last three from seamonkey, maybe thunderbird composing ?)
text/_moz_htmlcontext
text/html

(the last three of them are needed by mozilla products, or at least seamonkey, I didn't try with firefox.)

I used PhiLho's Hex2Bin function for the last two types (see Frhed if you don't have an hex editor at hand)
I also strongly recommend CLCL if you have no idea how the windows clipboard works : it simply display it using a tree-view style, that's all you need to know)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 18th, 2012, 7:44 pm 
Offline

Joined: December 2nd, 2010, 12:25 am
Posts: 73
Location: Ontario, Canada
Ok, I have spent way too many hours tring to get this to work.
Can someone please help me with this.

For some reason the following code only puts the first character on the clipboard "S".

Code:
#SingleInstance force
#NoEnv

CF_TEXT := 1
myData := "Sigh!"

SetClipBoardData(CF_TEXT, myData, 0, true)

MsgBox, All Done
ExitApp


SetClipboardData(_format, ByRef @data, _dataSize=0, _bEmptyClipboard=true)
{
   local res, mem, str, cfFormat, errorCode

   errorCode = 0

   If (_dataSize = 0)
   {
      ; Assume it is a simple string; otherwise, should provide real length...
      _dataSize := StrLen(@data)
     If (_dataSize = 0)
      {
         errorCode = SIZE
         Goto SCD_End
      }
   }

   ; Open the clipboard, and empty it.
   res := DllCall("OpenClipboard", "Uint", 0)
   If (res = 0)
   {
      errorCode = OC
      Goto SCD_End
   }
   If (_bEmptyClipboard)
   {
      DllCall("EmptyClipboard")
   }

   ; Allocate a global memory object for the text
   mem := DllCall("GlobalAlloc"
         , "Uint", 2 ; GMEM_MOVEABLE
         , "Uint", _dataSize + 1) ; +1 in case it is a zero-terminated string
   If (mem = 0)
   {
      errorCode = GA
      Goto SCD_End
   }

   ; Lock the handle and copy the text to the buffer
   str := DllCall("GlobalLock", "Uint", mem)
   ; str is a pointer to a memory area, so is treated as Uint
   DllCall("RtlMoveMemory"
         , "Uint", str
         , "Str", @data
         , "Uint",_dataSize)
   ; In case it is a zero-terminated string, we put the final zero
   DllCall("RtlZeroMemory", "Uint", str + _dataSize, "Uint", 1)
   DllCall("GlobalUnlock", "Uint", mem)

   ; Handle format
   If _format is integer
   {
      cfFormat := _format
   }
   Else
   {
      cfFormat := DllCall("RegisterClipboardFormat", "Str", _format)
      If (cfFormat = 0)
      {
         errorCode = RCF
         Goto SCD_End
      }
   }

   ; Place the handle on the clipboard
   res := DllCall("SetClipboardData"
         , "Uint", cfFormat
         , "Uint", mem)
   If (res = 0)
   {
      errorCode = SCD
      Goto SCD_End
   }

SCD_End:
   If errorCode != 0
   {
      errorCode = %errorCode%  (%A_LastError%)
   }
   ; Close the clipboard
   DllCall("CloseClipboard")

   ErrorLevel := errorCode
}


I am using win 7 x64 but got the same result in a win xp x86 virtual machine.


Last edited by AmourSpirit on January 20th, 2012, 4:14 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2012, 10:08 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Compatibility issue, it works well on AHK Basic, I just tried.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2012, 11:43 am 
Offline
User avatar

Joined: January 25th, 2006, 8:08 am
Posts: 225
Location: Froschtümpel
It's more a UNICODE issue - works well with AHK_L Ansi ...


Code:
   ...
   DllCall("RtlMoveMemory"         
            , "Uint", str
            , "Str", @data
           , "Uint",_dataSize)

    DllCall("RtlZeroMemory", "Uint", str + dataSize, "Uint", 1)
   ...



You probably have to use UNICODE Variants/values here ... (you also have to consider when determining datasize, that UNICODE needs more memory ...)

_________________________

Code:
;     (.)~(.)   
;    (-------)                                   
;---ooO-----Ooo---------------------------------------------------
;    Hoppfrosch  - AHK 1.1.05.06 Unicode 32bit on Win7 Ultimate
;-----------------------------------------------------------------                       
;    ( )   ( )                           
;    /|\   /|\ 


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2012, 1:05 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
@hoppfrosch thanks a lot, I'm learning.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2012, 3:50 pm 
Offline

Joined: December 2nd, 2010, 12:25 am
Posts: 73
Location: Ontario, Canada
Does anyone know the answer to solve this. It is currently outside my scope of knowledge.

hoppfrosch wrote:
It's more a UNICODE issue - works well with AHK_L Ansi ...


Code:
   ...
   DllCall("RtlMoveMemory"         
            , "Uint", str
            , "Str", @data
           , "Uint",_dataSize)

    DllCall("RtlZeroMemory", "Uint", str + dataSize, "Uint", 1)
   ...




You probably have to use UNICODE Variants/values here ... (you also have to consider when determining datasize, that UNICODE needs more memory ...)

_________________________

[code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2012, 7:50 am 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
check this
http://www.autohotkey.com/forum/viewtopic.php?t=79998
you can do what above example shows with one line:
Code:
WinClipboard.Clear() ;if you want to clear the clipboard
WinClipboard.SetText( "Sigh!" )
WinClipboard.AppendText( "Hello!" ) ;to append text

though it is intended for unicode x32/x64, ansi will not work

_________________
Crypt|QMsgBox|PUM|Quick Cliq|WinClipboard


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2012, 6:34 pm 
Offline

Joined: December 2nd, 2010, 12:25 am
Posts: 73
Location: Ontario, Canada
I am not sure this class would work for me as Ultimately I need to set html onto the clipboard. I Posted my solution for Unicode below this post

Deo wrote:
check this
http://www.autohotkey.com/forum/viewtopic.php?t=79998
you can do what above example shows with one line:
Code:
WinClipboard.Clear() ;if you want to clear the clipboard
WinClipboard.SetText( "Sigh!" )
WinClipboard.AppendText( "Hello!" ) ;to append text

though it is intended for unicode x32/x64, ansi will not work


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2012, 6:42 pm 
Offline

Joined: December 2nd, 2010, 12:25 am
Posts: 73
Location: Ontario, Canada
This is my Solution to get copying "Html Format" to the clipboard. This was tested on Windows 7 x64 AutoHotkkey_L v1.1.05.04.
I found no issues so far with this script.

Code:
CF_HTML := "HTML Format"

pushHTML(sHtmlFragment, title = "", sourceUrl = "")
{
Header =
(
Version:1.0
StartHTML:aaaaaaaa
EndHTML:bbbbbbbb
StartFragment:cccccccc
EndFragment:dddddddd
StartSelection:cccccccc
EndSelection:cccccccc
)
; http://blogs.msdn.com/b/jmstall/archive/2007/01/21/sample-code-html-clipboard.aspx
Pre := "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""><HTML><HEAD><TITLE>" . title . "</TITLE></HEAD><BODY><!--StartFragment-->"
Post := "<!--EndFragment--></BODY></HTML>"

   offSet := 6
   sData := Header
   if (sourceUrl){
      sData := sData . "SourceURL:" . sourceUrl
   }
   iStartHTML := StrLen(sData) + offSet
   
   sData := sData . Pre
   iStartFrag := StrLen(sData) + offSet
   
   sData := sData . sHtmlFragment
   iEndFrag := StrLen(sData) + offSet
   
   sData := sData . Post
   iEndHTML := StrLen(sData) + offSet
   iPadLen := 8
   StringReplace sData, sData, aaaaaaaa, % StrPad(iStartHTML, "0", iPadLen)
   StringReplace sData, sData, bbbbbbbb, % StrPad(iEndHTML, "0", iPadLen)
   StringReplace sData, sData, cccccccc, % StrPad(iStartFrag, "0", iPadLen), All
   StringReplace  sData, sData, dddddddd, % StrPad(iEndFrag, "0", iPadLen)

   Return, sData


StrPad(Str, PadChar,PadLen,Left=1)
{
   StringLen, sLen, str
   
   if (sLen >= PadLen)
      return str
   
   sDif := PadLen - sLen
   strPad := ""
   
   Loop, %sDif%
   {
      strPad := strPad . PadChar
   }
   Retval := ""
   If (Left=1)
   {
      Retval := strPad . Str
   }
   else
   {
      Retval := str . strPad
   }
   return Retval
}

SetClipboardData(_format, ByRef @data, _dataSize=0, _bEmptyClipboard=true)
{
   local res, mem, str, cfFormat, errorCode
   errorCode = 0

   If (_dataSize = 0)
   {
      ; Assume it is a simple string; otherwise, should provide real length...
      _dataSize := StrLen(@data)
     If (_dataSize = 0)
      {
         errorCode = SIZE
         Goto SCD_End
      }
   }

   ; Open the clipboard, and empty it.
   res := DllCall("OpenClipboard", "Uint", 0)
   If (res = 0)
   {
      errorCode = OC
      Goto SCD_End
   }
   If (_bEmptyClipboard)
   {
      DllCall("EmptyClipboard")
   }

   ; Allocate a global memory object for the text
   mem := DllCall("GlobalAlloc"
         , "Uint", 2 ; GMEM_MOVEABLE
         , "Uint", _dataSize + 1) ; +1 in case it is a zero-terminated string
   If (mem = 0)
   {
      errorCode = GA
      Goto SCD_End
   }

   ; Lock the handle and copy the text to the buffer
   str := DllCall("GlobalLock", "Uint", mem)
   ; str is a pointer to a memory area, so is treated as Uint
 
   ;~ ; In case it is a zero-terminated string, we put the final zero
   StrPut(@data, str , _dataSize +1,Encoding = "utf-16")
   DllCall("GlobalUnlock", "Uint", mem)

   ; Handle format
   If _format is integer
   {
      cfFormat := _format
   }
   Else
   {
      cfFormat := DllCall("RegisterClipboardFormat", "Str", _format)
      If (cfFormat = 0)
      {
         errorCode = RCF
         Goto SCD_End
      }
   }

   ; Place the handle on the clipboard
   res := DllCall("SetClipboardData"
         , "Uint", cfFormat
         , "Uint", mem)
   If (res = 0)
   {
      errorCode = SCD
      Goto SCD_End
   }

SCD_End:
   If errorCode != 0
   {
      errorCode = %errorCode%  (%A_LastError%)
   }
   ; Close the clipboard
   DllCall("CloseClipboard")

   ErrorLevel := errorCode
}

; only needed if you want to retrieve the html from the clipboard
ClipboardGet_HTML( byref Data ) { ; www.autohotkey.com/forum/viewtopic.php?p=392624#392624
 If CBID := DllCall( "RegisterClipboardFormat", Str,"HTML Format", Uint )
  If DllCall( "IsClipboardFormatAvailable", Uint,CBID ) <> 0
   If DllCall( "OpenClipboard", Uint,0 ) <> 0
    If hData := DllCall( "GetClipboardData", Uint,CBID, Uint )
       DataL := DllCall( "GlobalSize", Uint,hData, Uint )
     , pData := DllCall( "GlobalLock", Uint,hData, Uint )
     , VarSetCapacity( data, dataL * ( A_IsUnicode ? 2 : 1 ) ), StrGet := "StrGet"
     , A_IsUnicode ? Data := %StrGet%( pData, dataL, 0 )
                   : DllCall( "lstrcpyn", Str,Data, Uint,pData, Uint,DataL )
     , DllCall( "GlobalUnlock", Uint,hData )
 DllCall( "CloseClipboard" )
Return dataL ? dataL : 0
}

Simple Example:
Code:
RawHtml := "<h2><span style='color: rgb(0, 100, 0);'><u>Hello World</u></span></h2>"
Html := pushHTML(RawHtml, "My Hello World")
SetClipboardData(CF_HTML, Html)
MsgBox, % Html
MsgBox, Html is now on the clipboard and can be pasted into a Html editor.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 22nd, 2012, 6:31 am 
Offline

Joined: December 2nd, 2010, 12:25 am
Posts: 73
Location: Ontario, Canada
Can anyone help with this? in Chrome or Dreamweaver the "Html Format" works fine but Firefox will not paste anything. It say in this post that firefox needs "text/html" format on the clipboard.
Code:
Html := pushHTML(OutputText)
   SetClipBoardData("HTML Format", Html, 0, false)
   SetClipBoardData("text/html", Html, 0, true)


This is What gets pasted into Firefox ( gmail or online html editor such as tinyMCE )

敖獲潩㩮⸰ਹ瑓牡䡴䵔㩌〰〰〰㔹䔊摮呈䱍〺〰〰㌵ਲ਼瑓牡䙴慲浧湥㩴〰〰㄰㜲䔊摮牆条敭瑮〺〰〰〵㰱呈䱍㰾佂奄㰾ⴡ匭慴瑲牆条敭瑮ⴭ匾敥䔠敶湲瑯㩥䠠汥潬圠牯摬‬愼栠敲㵦攢敶湲瑯㩥⼯瘯敩⽷ㄱ㐷㤸㜶猯〱⼹昲晤㈱㤷愭捣ⵦ㌴㘰㠭ㄹⴳ㈵戰㉤㤰㍦㘰㈯摦ㅦ㜲ⴹ捡晣㐭〳ⴶ㤸㌱㔭〲摢〲昹〳⼶㸢猼慰瑳汹㵥挧汯牯›杲⡢ⰰㄠ㠲‬⤰✻䐾獥瑫灯⼼灳湡㰾愯ⰾ㰠⁡牨晥✽瑨灴㩳⼯睷⹷癥牥潮整挮浯瘯敩⽷昲晤㈱㤷愭捣ⵦ㌴㘰㠭ㄹⴳ㈵戰㉤㤰㍦㘰氿捯污㵥湥渣㈽摦ㅦ㜲ⴹ捡晣㐭〳ⴶ㤸㌱㔭〲摢〲昹〳✶琠牡敧㵴弧汢湡❫圾扥⼼㹡映牯映牵桴牥椠普牯慭楴湯㰮ⴡ䔭摮牆条敭瑮ⴭ㰾䈯䑏㹙⼼呈䱍>

In Chrome ( gmail ) or Dreamweaver the html paste fine.
For Example:
See Evernote: Hello World, Desktop, Web for further information.

I am using AutoHotkey_L Unicode on Window 7 x64


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 23rd, 2012, 2:56 pm 
Offline

Joined: January 22nd, 2012, 6:10 pm
Posts: 5
anybody had any luck getting this to work with putting formatted HTML on the clipboard?

Any help on getting this to work would be really appreciated


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 23rd, 2012, 3:54 pm 
@AmourSpirit: see first page where Firefox is mentioned, it uses a different format.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Aravind, Google Feedfetcher, Stigg and 12 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