I can't seem to find a working example of how you're supposed to use the ActiveX RDP client. I found Using the Remote Desktop ActiveX control but it doesn't explain how it's to be used. I was able to get a connection but since most of the methods return void
, how do you do things like get any error codes, or test that connection was successful, detect the disconnect, etc?
What I used to get it working with no error checking is:
CMsRdpClientAdvancedSettings8 advancedSettings = m_ocx.get_AdvancedSettings6();
m_ocx.put_Server (L"192.168.1.2"); // ip processor
m_ocx.put_UserName (L"user"); // handler username
m_ocx.put_Domain(L"pc1");
m_ocx.put_DesktopHeight (768); // Resolution
m_ocx.put_DesktopWidth (1024); // Resolution
advancedSettings.put_SmartSizing (TRUE); // The size of the controlScalingThe Remote Desktop
advancedSettings.put_AuthenticationLevel(2);
advancedSettings.put_EnableCredSspSupport(TRUE);
m_ocx.put_ColorDepth(32);
m_ocx.put_DisconnectedText(_T("Disconnected"));
m_ocx.put_ConnectingText (_T ( "Please wait ...")); // display text in the interface connection
m_ocx.Connect();
You can refer to this document ActiveX Control Containers: Handling Events from an ActiveX Control, use BEGIN_EVENTSINK_MAP
to get the RDP control message. The event ID is in the header file of the RDP class(CMSTSCAX1.h), here is my test code for your reference.
//use DECLARE_EVENTSINK_MAP() in CMFCRDPTestDlg.h
BEGIN_EVENTSINK_MAP(CMFCRDPTestDlg, CDialogEx)
ON_EVENT(CMFCRDPTestDlg, IDC_MSTSCAX1, 1, CMFCRDPTestDlg::OnConnectingMstscax1, VTS_NONE)
ON_EVENT(CMFCRDPTestDlg, IDC_MSTSCAX1, 2, CMFCRDPTestDlg::OnConnectedMstscax1, VTS_NONE)
ON_EVENT(CMFCRDPTestDlg, IDC_MSTSCAX1, 3, CMFCRDPTestDlg::OnLoginCompleteMstscax1, VTS_NONE)
ON_EVENT(CMFCRDPTestDlg, IDC_MSTSCAX1, 4, CMFCRDPTestDlg::OnDisconnectedMstscax1, VTS_I4)
ON_EVENT(CMFCRDPTestDlg, IDC_MSTSCAX1, 22, CMFCRDPTestDlg::OnLogonErrorMstscax1, VTS_I4)
END_EVENTSINK_MAP()
void CMFCRDPTestDlg::OnConnectingMstscax1()
{
AfxMessageBox(_T("Connecting"));
}