Author Topic: Contextual help project  (Read 114673 times)

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Contextual help project
« Reply #45 on: July 29, 2012, 07:03:24 PM »
Do a search, open the browser via a selection and resize/move the browser. Hit Esc to close the browser (not the search box)...

Can't see that one, sorry: F4 closes the browser, Esc works only in the xHelp dialog. And when I re-select, the browser appears with the latest position... or did I misunderstand something?

mywan

  • Guest
Re: Contextual help project
« Reply #46 on: July 29, 2012, 07:11:57 PM »
Do a search, open the browser via a selection and resize/move the browser. Hit Esc to close the browser (not the search box)...

Can't see that one, sorry: F4 closes the browser, Esc works only in the xHelp dialog. And when I re-select, the browser appears with the latest position... or did I misunderstand something?
In the latest version this has been fixed. Apparently the same condition that prevented the same page from displaying twice also prevented an update to the windows position settings. The last fix apparently killed 2 bird with 1 stone.

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Contextual help project
« Reply #47 on: July 30, 2012, 09:15:00 AM »
You will have to listen for the copy event in WindProc and send the selected text to the clipboard yourself.

I tried this in response to a keypress. No errors thrown but nothing on clipboard either ::)

                        IDM_COPY=15      ; Chappell, MSDN
                        OLECMDEXECOPT_DONTPROMPTUSER = 2   ; docobj.inc
                        invoke GetWindowLong, hWnd, WO_CONTAINER
                        mov ecx, eax
                        invoke vf([ecx].CContainer.m_pWebBrowser,IWebBrowser2, ExecWB), IDM_COPY, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0

mywan

  • Guest
Re: Contextual help project
« Reply #48 on: July 30, 2012, 02:36:41 PM »
Without worrying about getting it on the clipboard yet, if select a range of text can you read what range of text has been selected with a hotkey? Say just a MsgBox popup saying what has been selected?

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Contextual help project
« Reply #49 on: July 30, 2012, 03:45:54 PM »
IDM_COPY: Copies the current selection to the clipboard.

That sounds clear enough...

I wonder whether it has to do with some general IE settings on what is allowed or not. What I found on Google is that 1. copy should work by default with the webbrowser control, and 2. it can fail:
Quote
First, the execCommand method fails if the given command name is not supported for scripting. Second, the following commands fail (subject to the notes on coding errors, below) if they cannot get clipboard access before calling Exec:

    * Copy
    * Cut
    * InsertParagraph
    * Paste
http://www.geoffchappell.com/studies/windows/ie/mshtml/methods/basemso/execcommand.htm

In any case, this is all hilariously complicated. The guy who invented COM should be hanged (sorry if that hurts someone's feelings :bgrin:)

mywan

  • Guest
Re: Contextual help project
« Reply #50 on: July 30, 2012, 04:25:12 PM »
If you can obtain two pieces of information you can work around the problem regardless of its cause.

1) Can you read the user selected text (SelectedText) whether a copy is attempted or not?
2) Can you detect, in code, when somebody selects copy whether it fails to actually copy or not?

There are even ways to work around 2). If you can detect what text is selected from within your assembly then it is fairly trivial. Simply "invoke SetClipboardText selText", standard API call.

I tend to experiment with what bits of information I have access to. This information then defines what I have to work with to get around the problem, irrespective of what the cause of the problem was. I don't really don't know how it's supposed to be handled. In higher level languages this kind of information is hidden behind abstraction layers. However, there is often no need to implement a range of features through com that can more simply be handled yourself. The only really important thing is being able to retrieve the SelectedText in code. From there you can send it to the clipboard or anywhere else you choose.

If, as what you quoted said, this built in clipboard function fails if cannot get clipboard access before calling Exec it would make sense for it to fail. You code hasn't provided for access to the clipboard in order to prevent this method of failure. Basically you'll probably have to try and listen for the window messages generated in the failed attempt, and act accordingly.

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Contextual help project
« Reply #51 on: July 30, 2012, 04:32:39 PM »
Simply "invoke SetClipboardText selText", standard API call.

Which API is that? I always use SetClip$ "Hello World"...

mywan

  • Guest
Re: Contextual help project
« Reply #52 on: July 30, 2012, 05:41:13 PM »
SetClip$ looks like it would work fine. My experience in assembly is just getting started and the only one I was explicitly aware of in MASM was SetClipboardText proc ptxt:DWORD in masmlib.chm. However, there are several APIs pertaining to the clipboad. Perhaps OpenClipboard can give you the clipboard access needed to get the default to work.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms649048(v=vs.85).aspx
You will need to close the clipboard (CloseClipboard) when done.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms649035(v=vs.85).aspx

Here is a list of clipboard related APIs:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648709(v=vs.85).aspx

mywan

  • Guest
Re: Contextual help project
« Reply #53 on: July 30, 2012, 05:46:38 PM »
In fact, given the text you quoted about WM_COPY failing if it can't get clipboard access it makes sense that it would require a handle to the clipboard opened through the OpenClipboard API.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms649048(v=vs.85).aspx

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Contextual help project
« Reply #54 on: July 30, 2012, 08:15:26 PM »
SetClip$ looks like it would work fine.

Yes it does, because I've written it myself using OpenClipboard, SetClipboardData etc
The problem is elsewhere. For the copy action of the webbrowser, a special procedure is defined here and could be implemented as follows in IEContainer.asm - but it always returns error 80004005h:

Code: [Select]
invoke GetWindowLong, hWnd, WO_CONTAINER ; see also Exec_ in OleCommandTarget.asm
mov ecx, eax
invoke vf([ecx].CContainer.m_pWebBrowser,IWebBrowser2, ExecWB), IDM_COPY, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0

mywan

  • Guest
Re: Contextual help project
« Reply #55 on: July 30, 2012, 09:37:43 PM »
This looks like a permissions problem. I also remember something about needing a buffer to hold the data the clipboard accesses. I can't really play with your code much because while still trying to learn some basics my installation will remain the basic package.

What I would like to know is if you can access the pages dom to get retrieve htmlDocument.selection without worrying about putting it on the clipboard yet? If you can get this selected text then you can bypass the whole issue with IDM_COPY. All you have to do is figure out how to see the selected text independent of the clipboard.


jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Contextual help project
« Reply #56 on: July 30, 2012, 11:35:28 PM »
What I would like to know is if you can access the pages dom to get retrieve htmlDocument.selection

No. It's not included in the current webbrowser code, and implementing it via COM is way over my head, sorry...

mywan

  • Guest
Re: Contextual help project
« Reply #57 on: July 31, 2012, 12:47:10 AM »
Do you have a version of just the IEContainerSample that I can compile? The download version doesn't. I've done a lot of com automation of webpages in other languages and have some idea of what I'm looking for to work around the problem. Even my bank monitoring is fully automated from scripts stored on a TrueCrypt drive. I haven't actually used a container, just an IE instance, in many years though, and then the container merely took ownership as parents of other apps. However, I want to see what I can learn and need some asm source I can compile.

mywan

  • Guest
Re: Contextual help project
« Reply #58 on: July 31, 2012, 01:08:07 AM »
I just tried to attach to the embedded IE instance in your container with another app and was successful. I'm going to see what all I can get access to. Perhaps this is all I need given that you are basically controlling the container from a separate app also, albeit one written in asm.

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Contextual help project
« Reply #59 on: July 31, 2012, 01:51:11 AM »
Do you have a version of just the IEContainerSample that I can compile?

Attached, with personalised batch file for debugging. This assumes Japheth's WinInc package and folders
[Masm32drive]:\JWasm\WebBrowser
[Masm32drive]:\JWasm\Include
[Masm32drive]:\JWasm\bin
[Masm32drive]:\JWasm\Lib
etc, i.e. the archive needs to be unzipped to the root of [Masm32drive] with "use folder names" on.

The *.asc file is for use with RichMasm; if the JWasm/WinInc package is set up ok, drag \JWasm\WebBrowser\IEContainer.asc over \Masm32\RichMasm\RichMasm.exe and hit F6.
« Last Edit: July 31, 2012, 03:31:30 AM by jj2007 »