locked
CustomContext ShowContextMenu gets passed IHTMLElement, but I want the selected text RRS feed

  • Question

  • I would like to add an IE context menu which posts the selected text to a database.

    Working from the example found here I am able to make the menu appear when I right click on a selection, but

    I cannot seem to get the selected text

    what is passed is of type [object IHTMLElement]

    which doesn't seem to have a way to get the selected text, 

    I know this is kind of vague, I could post the code, but....

    here is what I see that looks relevant...

    a function ShowContextMenu(int dwID, POINT pt, object pcmdtReserved, object pdispReserved)

    where pcmdtReserved is the variable which represents the selection context

    in that function if dwID == NativeMethods.CONTEXT_MENU_CONST.CONTEXT_MENU_TEXTSELECT

    then the example sets the contextMenu.Tag to the src value of the image tag (this is where I want the selected text to go)

    but.. pcmdtReserved  (by trial and errors) works out to a IHTMLElement

     

    Any help is appreciated

     

    Thursday, December 8, 2011 8:02 PM

Answers

  • On 12/8/2011 3:02 PM, scenariolab wrote:

    I would like to add an IE context menu which posts the selected text to a database.

    _Working from the example
    found_here<http://code.msdn.microsoft.com/windowsdesktop/CSCustomIEContextMenu-f784ff82>
    I am able to make the menu appear when I right click on a selection,
    but

    I cannot seem to get the selected text

    what is passed is of type [object IHTMLElement]

    Try element.document.selection.createRange().text


    Igor Tandetnik

    • Marked as answer by scenariolab Saturday, December 10, 2011 3:53 PM
    Thursday, December 8, 2011 9:05 PM