0

I have referred the following link:

Silverlight for Windows Embedded

By referring this link i created a demo application which consist of two buttons created using Microsoft expression blend 2 tools. And then written a code referring the above site. Now my button names are "Browser Button" and "Media Button". On click of any one of the button i should able to launch the respective application. I was able to do for "Browser Button" but not for "Media Button" and if i do for "Media Button" then i am not able to do for "Browser Button".. I mean to say that how should i create event handler for both the buttons.

This is the code in c++ which i should modify

class BtnEventHandler
{
public:
    HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
    {
        RETAILMSG(1,(L"Browser event"));
        Execute(L"\\Windows\\iesample.exe",L"");
        return S_OK;
    }
};



// entry point for the application.
INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
 LPWSTR lpCmdLine,int nCmdShow)
{
    PrintMessage();
    int      exitCode = -1;
    HRESULT  hr = S_OK;

if (!XamlRuntimeInitialize())
    return -1;

HRESULT retcode;
IXRApplicationPtr app;

if (FAILED(retcode=GetXRApplicationInstance(&app)))
    return -1;

if (FAILED(retcode=app->AddResourceModule(hInstance)))
    return -1;

XRWindowCreateParams wp;

ZeroMemory(&wp, sizeof(XRWindowCreateParams));

wp.Style       = WS_OVERLAPPED;
wp.pTitle      = L"Bounce Test";
wp.Left        = 0;
wp.Top         = 0;

XRXamlSource xamlsrc;

xamlsrc.SetResource(hInstance,TEXT("XAML"),MAKEINTRESOURCE(IDR_XAML1));


IXRVisualHostPtr vhost;
if (FAILED(retcode=app->CreateHostFromXaml(&xamlsrc, &wp, &vhost)))
    return -1;  

IXRFrameworkElementPtr root;    
if (FAILED(retcode=vhost->GetRootElement(&root)))
    return -1;  

IXRButtonBasePtr btn;   
if (FAILED(retcode=root->FindName(TEXT("BrowserButton"), &btn)))
    return -1;      

IXRDelegate<XRMouseButtonEventArgs>* clickdelegate;
BtnEventHandler handler;    

if(FAILED(retcode=CreateDelegate
    (&handler,&BtnEventHandler::OnClick,&clickdelegate)))
    return -1;
if (FAILED(retcode=btn->AddClickEventHandler(clickdelegate)))
    return -1;

UINT exitcode;
if (FAILED(retcode=vhost->StartDialog(&exitcode)))
    return -1;

return exitCode;
}

I have to add event handler for both the button so that on emulator whenever i click on any one of the button i should be able to launch the respective applications.

Thanks in advance

4

1 に答える 1

2

各ボタンのハンドラーとなる 2 つの別個の関数を作成できます。
どのボタンが押されたかを同じハンドラーに識別させ、それに応じて動作させたい場合は、それを示す次の MSDN 記事を読むことができます。


私はこれを試していませんが、ソース オブジェクトのIXRDependencyObject::GetNameを使用して、どのボタンが押されたかを知ることもできます。

ハンドラーは次のようになります。

HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
    BSTR pName[50];

    source->GetName(pName);
    if (_tcscmp(L"BrowserEvent", LPCWSTR(pName)) == 0)
    {
            RETAILMSG(1,(L"Browser event"));
            Execute(L"\\Windows\\iesample.exe",L"");

    }
    else if (_tcscmp(L"BrowserEvent", LPCWSTR(pName)) == 0)
    {
            /* Handle another button or element */
    }
    return S_OK;
}
于 2010-05-06T14:03:40.467 に答える