开发者

How to invoke an already running instance of an application

I am developing a BHO with c++ for identifying the phone numbers on any webpage, highlighting the phone numbers and invoking an utility when click on the phone number.

I am using IHtmlTxtRange::findtext for finding the phone numbers and for highlighting the phone numbers I am injecting HTML's span tag to the web page using IHtmlTxtRange::pastetext().

I want to invoke the same instance of an already running application, when click on the phone number on web page . How to achieve this with onclick() of HTML span tag.

Below I have given the code snippet which I am using for finding and highlighting the phone number.

lpBody->createTextRange(&lpTxtRange);

lpBody->Release();

CComBSTR html;

CComBSTR newhtml;

long t;

VARIANT_BOOL bFound;

int i=0;

int size= findText.size();

for(int i=0;i<size;i++)

{   

    while(1)

    {

        CComBSTR str1= findText[i].c_str();

        lpTxtRange->findText(str1,0,lFlags,&bFound);

        if(bFound==-1)

        {

            newhtml.Empty();

            lpTxtRange->get_htmlText(&html);

            newhtml.Append("<span id='");

            newhtml.Append(L"begin_highlight");

            newhtml.Append("' title='");

            newhtml.Append(L"call this phone number ");

            newhtml.Append(str1);

            newhtml.Append("' style='");

            newhtml.Append(L"color: white; background-color: grey");

            newhtml.Append("'>");

            newhtml.AppendBSTR(html);

            newhtml.Append("</span>");

            lpTxtRange->pasteHTML(newhtml);

            lpTxtRange->move开发者_运维知识库Start((BSTR)CComBSTR("Character"),1,&t);

            lpTxtRange->moveEnd((BSTR)CComBSTR("Textedit"),1,&t);

        }

        else

             break;

    }



}



lpTxtRange->Release();

findText.clear();

Thanks a lot.


This may help with half of your problem..

You can use EnumWindows to find the window of your running application. To identify the window as being your application, you can use the class name of the window (which you could use a GUID for). GetClassNameA should get this from your HWND.

In the app that you are sending the data to, be sure to set this class name up when the main window is created.

To actually send the data to it, you can send it a WM_COPYDATA command using SendMessage and a COPYDATASTRUCT. The receiving application then need to receive this via its message loop.

All that is left then is getting a callback in the BHO when you item is clicked to do all of this!

Edit: this could be of use for that: Is it possible to use a BHO (IE8) to track which links a user clicks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜