I have a log in screen when my application starts and would like the cursor to be waiting in the user name text box to type (without clicking). I was able to focus the cursor after the grid loads:
HRESULT MainPage::OnLoaded(__in IXRDependencyObject* pRoot)
{
UNREFERENCED_PARAMETER(pRoot);
HRESULT hr = InitializeComponent();
if (FAILED(hr))
{
goto Error;
}
if (m_pLogin)
{
m_pLogin->AddLoadedEventHandler(CreateDelegate(this, &MainPage::Login_Loaded));
}
Error:
return hr;
} // OnLoaded
HRESULT MainPage::Login_Loaded (IXRDependencyObject* pSender, XRRoutedEventArgs* pArgs)
{
HRESULT hr = S_OK;
m_pUserName->Focus(&pBool);
return hr;
}
This allows me to type but the cursor isn't actually visible.
I have seen other threads explaining that the browser plugin must have focus first, but this is an embedded silverlight application (C++) and not a silverlight webpage (C#). I cannot figure out how to set focus to the application when it starts without using the mouse. Any suggestions?
I was not able to accomplish this without a mouse click - but I used SendInput to synthesize a mouse click so the user doesn't have to.
HRESULT MainPage::OnLoaded(__in IXRDependencyObject* pRoot)
{
UNREFERENCED_PARAMETER(pRoot);
HRESULT hr = InitializeComponent();
if (FAILED(hr))
{
goto Error;
}
if (m_pLogin)
{
m_pLogin->AddLoadedEventHandler(CreateDelegate(this, &MainPage::Login_Loaded));
m_pLogin->AddMouseLeftButtonUpEventHandler(CreateDelegate(this, &MainPage::Login_MouseLeftButtonUp));
}
Error:
return hr;
} // OnLoaded
HRESULT MainPage::Login_Loaded (IXRDependencyObject* pSender, XRRoutedEventArgs* pArgs)
{
HRESULT hr = S_OK;
// execute mouse click
INPUT ip;
ip.type = INPUT_MOUSE;
ip.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE;
SendInput(1,&ip,sizeof(INPUT));
ip.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
SendInput(1,&ip,sizeof(INPUT));
return hr;
}
HRESULT MainPage::Login_MouseLeftButtonUp (IXRDependencyObject* pSender, XRMouseButtonEventArgs* pArgs)
{
HRESULT hr = S_OK;
m_pUserName->Focus(&pBool);
return hr;
}