Document2\execCommand with Copy

Everything else that doesn't fall into one of the other PB categories.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Document2\execCommand with Copy

Post by DevilDog »

Has anyone used the Document2\execCommand command to copy the currently selected text in Internet Explorer?

I've tried

Code: Select all

iCopy.l = ANSI2BSTR("Copy")
  If Document2\execCommand(@iCopy,#False,0,0) = #S_OK
with no luck. I have a reference to the current open instance of Internet Explorer IHTMLdocument2 but can't figure out a way to copy the currently selected text.

I've also looked into using the IHTMLSelection object but couldn't figure out how the TextRange (created with the createRange command) object can return the selected text.

Can anyone help please? :?
When all is said and done, more is said than done.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

try:

Code: Select all

iCopy.l = ANSI2BSTR("Copy") 
  If Document2\execCommand(iCopy,#False,0,0) = #S_OK
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

No dice,
I tried also changing the #False to 0 and the Ansi2Bstr to Ansi2Uni with no luck. UGH!

Are we breaking new ground here? Exploring uncharted territory? Has anyone done this before?

I wonder because I saw Freak's IETool source code where he keyboards a Ctrl+C to copy the selected text into the clipboard. Is this why he did it that way?

I mean I guess it's possible to do it that way but I think I would need a reference to the IWebbrowser2 interface which I currently do not have. I'm one level down in the IHTMLDocument2 level.

Any other ideas? Anyone?
When all is said and done, more is said than done.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

can you post whole source or example?
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

OK, first I get a handle to the "Internet Explorer_Server" window in the current running instance of IE and I pass it to the code below (provided by Freak)

Code: Select all

Procedure.l GetIHTMLDocument2(ExplorerServerWindow) 

  HtmlDoc.IHTMLDocument2 = 0 
      
  OleAcc = OpenLibrary(#PB_Any, "OLEACC.DLL") 
  If OleAcc And IsFunction(OleAcc, "ObjectFromLresult") 

    Message = RegisterWindowMessage_("WM_HTML_GETOBJECT") 
    SendMessageTimeout_(ExplorerServerWindow, Message, 0, 0, #SMTO_ABORTIFHUNG, 1000, @MessageResult) 
      
    CallFunction(OleAcc, "ObjectFromLresult", MessageResult, ?IID_IHTMLDocument2, 0, @HtmlDoc)    
 
    CloseLibrary(OleAcc) 
  EndIf 
  
  ProcedureReturn HtmlDoc 
EndProcedure 
This works great and I do end up with a pointer to the IHTMLDocument2 interface.

From there I'm just simply trying to run the code:

Code: Select all

iCopy.l = ANSI2BSTR("Copy") 
  If Document2\execCommand(iCopy,#False,0,0) = #S_OK
When all is said and done, more is said than done.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

you should call it like:

Code: Select all

Command.VARIANT
Command\vt = #VT_BSTR
Command\bstrVal = Ansi2Uni("copy")
      
If Document2\execCommand(@Command, #VARIANT_FALSE, 0, @Success) = #S_OK 
  Debug Success
EndIf
see: http://msdn.microsoft.com/library/defau ... ommand.asp

but:

Code: Select all

If Document2\queryCommandEnabled(Ansi2Uni("Copy"), @Success) = #S_OK
  Debug Success
EndIf
returns #VT_FALSE, so it seem you can't call this command.
see: http://msdn.microsoft.com/library/defau ... nabled.asp

but maybe i am wrong, i am not into this COM stuff.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You can probably only call this on the execCommand() method of the selected TextRange object itself.

> I wonder because I saw Freak's IETool source code where he keyboards a Ctrl+C to copy the selected text into the clipboard. Is this why he did it that way?

The reason is that i wrote that tool a long time ago and was quite new to windows programming in general.
It was just the simplest solution.

Not many people have done this in PB so far (as far as i know). I do not
have a real use for all this IE stuff, so i only experiment with it when others have a question.

I have put an example here on reading the selected text without the clipboard:
viewtopic.php?p=103173#103173
quidquid Latine dictum sit altum videtur
Post Reply