Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

842 lines
23 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. TSRDPRemoteDesktopClient
  5. Abstract:
  6. This is the TS/RDP implementation of the Remote Desktop Client class.
  7. The Remote Desktop Client class hierarchy provides a pluggable C++
  8. interface for remote desktop access, by abstracting the implementation
  9. specific details of remote desktop access for the client-side
  10. The TSRDPRemoteDesktopClass implements remote-desktopping
  11. with the help of an instance of the MSTSC ActiveX client control.
  12. Author:
  13. Tad Brockway 02/00
  14. Revision History:
  15. --*/
  16. #ifndef __TSRDPREMOTEDESKTOPCLIENT_H_
  17. #define __TSRDPREMOTEDESKTOPCLIENT_H_
  18. #include "resource.h"
  19. #include <atlctl.h>
  20. #include "RDCHostCP.h"
  21. #include <mstsax.h>
  22. #include <rdchost.h>
  23. #include <RemoteDesktopTopLevelObject.h>
  24. #include <RemoteDesktopUtils.h>
  25. #include "parseaddr.h"
  26. #pragma warning (disable: 4786)
  27. #include <list>
  28. #include "icshelpapi.h"
  29. #define IDC_MSTSCEVENT_SOURCE_OBJ 1
  30. #define IDC_CHANNELEVENT_SOURCE_OBJ 2
  31. #define WM_STARTLISTEN (0xBFFE)
  32. #define WM_TSCONNECT (0xBFFF)
  33. #define WM_LISTENTIMEOUT_TIMER 1
  34. #define WM_CONNECTCHECK_TIMER 2
  35. #define MAX_FETCHIPADDRESSRETRY 5
  36. //
  37. // MSTSC ActiveX GUID
  38. //
  39. #define MSTSCAX_TEXTGUID _T("{7cacbd7b-0d99-468f-ac33-22e495c0afe5}")
  40. #define RDC_CHECKCONN_TIMEOUT (30 * 1000) //millisec. default value to ping is 30 seconds
  41. #define RDC_CONNCHECK_ENTRY L"ConnectionCheck"
  42. //
  43. // Info for all the event functions is entered here
  44. // there is a way to have ATL do this automatically using typelib's
  45. // but it is slower.
  46. //
  47. static _ATL_FUNC_INFO TSRDPClientEventFuncNoParamsInfo =
  48. {
  49. CC_STDCALL, // Calling convention.
  50. VT_EMPTY, // Return type.
  51. 0, // Number of arguments.
  52. {VT_EMPTY} // Argument types.
  53. };
  54. static _ATL_FUNC_INFO TSRDPClientEventFuncLongParamInfo =
  55. {
  56. CC_STDCALL, // Calling convention.
  57. VT_EMPTY, // Return type.
  58. 1, // Number of arguments.
  59. {VT_I4} // Argument types.
  60. };
  61. static _ATL_FUNC_INFO TSRDPClientEventFuncTwoStringParamInfo =
  62. {
  63. CC_STDCALL, // Calling convention.
  64. VT_EMPTY, // Return type.
  65. 2, // Number of arguments.
  66. {VT_BSTR, // Argument types
  67. VT_BSTR}
  68. };
  69. static _ATL_FUNC_INFO TSRDPClientEventFuncReceivePublicKeyParamInfo =
  70. {
  71. CC_STDCALL, // Calling convention.
  72. VT_EMPTY, // Return type.
  73. 2, // Number of arguments.
  74. {VT_BSTR, // Argument types
  75. VT_BYREF | VT_BOOL }
  76. };
  77. static _ATL_FUNC_INFO TSRDPClientEventFuncOneStringParamInfo =
  78. {
  79. CC_STDCALL, // Calling convention.
  80. VT_EMPTY, // Return type.
  81. 1, // Number of arguments.
  82. {VT_BSTR} // Argument types
  83. };
  84. ///////////////////////////////////////////////////////
  85. //
  86. // CMSTSCClientEventSink
  87. //
  88. class CTSRDPRemoteDesktopClient;
  89. class CMSTSCClientEventSink :
  90. public IDispEventSimpleImpl<IDC_MSTSCEVENT_SOURCE_OBJ, CMSTSCClientEventSink,
  91. &DIID_IMsTscAxEvents>,
  92. public CRemoteDesktopTopLevelObject
  93. {
  94. public:
  95. CTSRDPRemoteDesktopClient *m_Obj;
  96. public:
  97. BEGIN_SINK_MAP(CMSTSCClientEventSink)
  98. SINK_ENTRY_INFO(IDC_MSTSCEVENT_SOURCE_OBJ, DIID_IMsTscAxEvents,
  99. DISPID_CONNECTED, OnRDPConnected,
  100. &TSRDPClientEventFuncNoParamsInfo)
  101. SINK_ENTRY_INFO(IDC_MSTSCEVENT_SOURCE_OBJ, DIID_IMsTscAxEvents,
  102. DISPID_DISCONNECTED, OnDisconnected,
  103. &TSRDPClientEventFuncLongParamInfo)
  104. SINK_ENTRY_INFO(IDC_MSTSCEVENT_SOURCE_OBJ, DIID_IMsTscAxEvents,
  105. DISPID_LOGINCOMPLETE, OnLoginComplete,
  106. &TSRDPClientEventFuncNoParamsInfo)
  107. SINK_ENTRY_INFO(IDC_MSTSCEVENT_SOURCE_OBJ, DIID_IMsTscAxEvents,
  108. DISPID_RECEVIEDTSPUBLICKEY, OnReceivedTSPublicKey,
  109. &TSRDPClientEventFuncReceivePublicKeyParamInfo)
  110. SINK_ENTRY_INFO(IDC_MSTSCEVENT_SOURCE_OBJ, DIID_IMsTscAxEvents,
  111. DISPID_CHANNELRECEIVEDDATA, OnReceiveData,
  112. &TSRDPClientEventFuncTwoStringParamInfo)
  113. END_SINK_MAP()
  114. CMSTSCClientEventSink()
  115. {
  116. m_Obj = NULL;
  117. }
  118. ~CMSTSCClientEventSink();
  119. //
  120. // Event Sinks
  121. //
  122. void __stdcall OnReceivedTSPublicKey(BSTR publicKey, VARIANT_BOOL* pfContinue);
  123. HRESULT __stdcall OnRDPConnected();
  124. HRESULT __stdcall OnLoginComplete();
  125. HRESULT __stdcall OnDisconnected(long disconReason);
  126. void __stdcall OnReceiveData(BSTR chanName, BSTR data);
  127. //
  128. // Return the name of this class.
  129. //
  130. virtual const LPTSTR ClassName() {
  131. return TEXT("CMSTSCClientEventSink");
  132. }
  133. };
  134. ///////////////////////////////////////////////////////
  135. //
  136. // CCtlChannelEventSink
  137. //
  138. // Control Channel Event Sink
  139. //
  140. class CCtlChannelEventSink :
  141. public IDispEventSimpleImpl<IDC_CHANNELEVENT_SOURCE_OBJ, CCtlChannelEventSink,
  142. &DIID__ISAFRemoteDesktopDataChannelEvents>,
  143. public CRemoteDesktopTopLevelObject
  144. {
  145. public:
  146. CTSRDPRemoteDesktopClient *m_Obj;
  147. public:
  148. BEGIN_SINK_MAP(CCtlChannelEventSink)
  149. SINK_ENTRY_INFO(IDC_CHANNELEVENT_SOURCE_OBJ, DIID__ISAFRemoteDesktopDataChannelEvents,
  150. DISPID_RDSCHANNELEVENTS_CHANNELDATAREADY, DataReady,
  151. &TSRDPClientEventFuncOneStringParamInfo)
  152. END_SINK_MAP()
  153. CCtlChannelEventSink()
  154. {
  155. m_Obj = NULL;
  156. }
  157. ~CCtlChannelEventSink();
  158. //
  159. // Event Sinks
  160. //
  161. void __stdcall DataReady(BSTR channelName);
  162. //
  163. // Return the name of this class.
  164. //
  165. virtual const LPTSTR ClassName() {
  166. return TEXT("CCtlChannelEventSink");
  167. }
  168. };
  169. ///////////////////////////////////////////////////////
  170. //
  171. // CTSRDPRemoteDesktopClient
  172. //
  173. class CMSTSCClientEventSink;
  174. class ATL_NO_VTABLE CTSRDPRemoteDesktopClient :
  175. public CComObjectRootEx<CComSingleThreadModel>,
  176. public CComControl<CTSRDPRemoteDesktopClient>,
  177. public IPersistStreamInitImpl<CTSRDPRemoteDesktopClient>,
  178. public IOleControlImpl<CTSRDPRemoteDesktopClient>,
  179. public IOleObjectImpl<CTSRDPRemoteDesktopClient>,
  180. public IOleInPlaceActiveObjectImpl<CTSRDPRemoteDesktopClient>,
  181. public IViewObjectExImpl<CTSRDPRemoteDesktopClient>,
  182. public IOleInPlaceObjectWindowlessImpl<CTSRDPRemoteDesktopClient>,
  183. public IPersistStorageImpl<CTSRDPRemoteDesktopClient>,
  184. public ISpecifyPropertyPagesImpl<CTSRDPRemoteDesktopClient>,
  185. public IQuickActivateImpl<CTSRDPRemoteDesktopClient>,
  186. public IDataObjectImpl<CTSRDPRemoteDesktopClient>,
  187. public IProvideClassInfo2Impl<&CLSID_TSRDPRemoteDesktopClient, &DIID__ISAFRemoteDesktopClientEvents, &LIBID_RDCCLIENTHOSTLib>,
  188. public CComCoClass<CTSRDPRemoteDesktopClient, &CLSID_TSRDPRemoteDesktopClient>,
  189. public IDispatchImpl<ISAFRemoteDesktopClient, &IID_ISAFRemoteDesktopClient, &LIBID_RDCCLIENTHOSTLib>,
  190. public IDispatchImpl<ISAFRemoteDesktopTestExtension, &IID_ISAFRemoteDesktopTestExtension, &LIBID_RDCCLIENTHOSTLib>,
  191. public IDataChannelIO,
  192. public CProxy_ISAFRemoteDesktopClientEvents< CTSRDPRemoteDesktopClient>,
  193. public CProxy_IDataChannelIOEvents< CTSRDPRemoteDesktopClient>,
  194. public IConnectionPointContainerImpl<CTSRDPRemoteDesktopClient>,
  195. public CRemoteDesktopTopLevelObject
  196. {
  197. friend CCtlChannelEventSink;
  198. private:
  199. IMsRdpClient2 *m_TSClient;
  200. HWND m_TSClientWnd;
  201. CAxWindow m_TSClientAxView;
  202. BOOL m_ConnectionInProgress;
  203. BOOL m_RemoteControlRequestInProgress;
  204. BOOL m_ConnectedToServer;
  205. BOOL m_Initialized;
  206. LONG m_LastExtendedErrorInfo;
  207. //
  208. // Event sink receives events fired by the TS client control..
  209. //
  210. CMSTSCClientEventSink m_TSClientEventSink;
  211. //
  212. // Control Channel Event Sink
  213. //
  214. CCtlChannelEventSink m_CtlChannelEventSink;
  215. //
  216. // Multiplexes Channel Data
  217. //
  218. CComPtr<ISAFRemoteDesktopChannelMgr> m_ChannelMgr;
  219. CComPtr<ISAFRemoteDesktopDataChannel> m_CtlChannel;
  220. //
  221. // The parsed connection parameters.
  222. //
  223. DWORD m_ConnectParmVersion;
  224. CComBSTR m_AssistantAccount;
  225. CComBSTR m_AssistantAccountPwd;
  226. CComBSTR m_HelpSessionName;
  227. CComBSTR m_HelpSessionID;
  228. CComBSTR m_HelpSessionPwd;
  229. CComBSTR m_TSSecurityBlob;
  230. ServerAddressList m_ServerAddressList;
  231. CComBSTR m_ConnectedServer;
  232. LONG m_ConnectedPort;
  233. //
  234. // The complete connection string.
  235. //
  236. CComBSTR m_ConnectParms;
  237. //
  238. // Expert side to be transmitted over to user
  239. //
  240. CComBSTR m_ExpertBlob;
  241. //
  242. // Search for a child window of the specified parent window.
  243. //
  244. typedef struct _WinSearch
  245. {
  246. HWND foundWindow;
  247. LPTSTR srchCaption;
  248. LPTSTR srchClass;
  249. } WINSEARCH, *PWINSEARCH;
  250. HWND SearchForWindow(HWND hwndParent, LPTSTR srchCaption, LPTSTR srchClass);
  251. static BOOL CALLBACK _WindowSrchProc(HWND hwnd, PWINSEARCH srch);
  252. //timer related members
  253. DWORD m_PrevTimer;
  254. UINT m_TimerId;
  255. DWORD m_RdcConnCheckTimeInterval;
  256. BOOL m_ListenConnectInProgress; // duration of StartListen() until mstscax connected.
  257. SOCKET m_ListenSocket; // listen() socket
  258. SOCKET m_TSConnectSocket; // accept() scoket
  259. DWORD m_ICSPort; // port that ICS library punch on ICS server
  260. BOOL m_InitListeningLibrary; // Instance of object initialize WinSock/ICS library.
  261. UINT_PTR m_ListenTimeoutTimerID; // Timer ID for listen timeout.
  262. void
  263. ListenConnectCleanup()
  264. {
  265. m_ListenConnectInProgress = FALSE;
  266. if( INVALID_SOCKET != m_ListenSocket ) {
  267. closesocket( m_ListenSocket );
  268. }
  269. if( (UINT_PTR)0 != m_ListenTimeoutTimerID ) {
  270. KillTimer( m_ListenTimeoutTimerID );
  271. }
  272. if( INVALID_SOCKET != m_TSConnectSocket ) {
  273. closesocket( m_TSConnectSocket );
  274. }
  275. if( 0 != m_ICSPort ) {
  276. ClosePort( m_ICSPort );
  277. }
  278. m_ListenSocket = INVALID_SOCKET;
  279. m_TSConnectSocket = INVALID_SOCKET;
  280. m_ICSPort = 0;
  281. }
  282. //
  283. // Variable to manage WinSock and ICS library startup/shutdown, WinSock/ICS library
  284. // is RDP specific so not declare in parent class.
  285. //
  286. static LONG gm_ListeningLibraryRefCount; // Number of time we reference WinSock and ICS library
  287. //
  288. // accessing only global variable, no need for per-instance.
  289. //
  290. static HRESULT
  291. InitListeningLibrary();
  292. static HRESULT
  293. TerminateListeningLibrary();
  294. //
  295. // Listen socket already in progress
  296. //
  297. inline BOOL
  298. ListenConnectInProgress() {
  299. return m_ListenConnectInProgress;
  300. }
  301. protected:
  302. //
  303. // Final Initialization.
  304. //
  305. virtual HRESULT Initialize(LPCREATESTRUCT pCreateStruct);
  306. //
  307. // Generate a remote control request message for the
  308. // server.
  309. //
  310. HRESULT GenerateRCRequest(BSTR *rcRequest);
  311. //
  312. // Generate a 'client authenticate' request.
  313. //
  314. HRESULT GenerateClientAuthenticateRequest(BSTR *authenticateReq);
  315. //
  316. // Generate a version information packet.
  317. //
  318. HRESULT GenerateVersionInfoPacket(BSTR *versionInfoPacket);
  319. //
  320. // Send the terminate shadowing key sequence to the server.
  321. //
  322. HRESULT SendTerminateRCKeysToServer();
  323. //
  324. // Handle Remote Control 'Control' Channel messages.
  325. //
  326. VOID HandleControlChannelMsg();
  327. //
  328. // Translate an MSTSC disconnect code into a Salem disconnect
  329. // code.
  330. //
  331. LONG TranslateMSTSCDisconnectCode(DisconnectReasonCode disconReason,
  332. ExtendedDisconnectReasonCode extendedReasonCode);
  333. //
  334. // Disconnects the client from the server.
  335. //
  336. STDMETHOD(DisconnectFromServerInternal)(
  337. LONG disconnectCode
  338. );
  339. HRESULT
  340. SetupConnectionInfo(BOOL bListen, BSTR expertBlob);
  341. //
  342. // Connect to server with port
  343. //
  344. HRESULT
  345. ConnectServerPort(
  346. BSTR ServerName,
  347. LONG portNumber
  348. );
  349. //
  350. // Connect to server with established socket
  351. //
  352. HRESULT
  353. ConnectServerWithOpenedSocket();
  354. //generate a simple message for checking if the connection is alive
  355. HRESULT GenerateNullData(BSTR *bstrMsg);
  356. //
  357. // Retrieve connect parm
  358. //
  359. HRESULT
  360. RetrieveUserConnectParm( BSTR* pConnectParm );
  361. void
  362. FireListenConnect( DWORD ErrCode )
  363. {
  364. return;
  365. }
  366. public:
  367. //
  368. // Constructor/Destructor
  369. //
  370. CTSRDPRemoteDesktopClient() {
  371. //
  372. // We are window'd, even if our parent supports Windowless
  373. // controls.
  374. //
  375. m_bWindowOnly = TRUE;
  376. m_ConnectedToServer = FALSE;
  377. m_Initialized = FALSE;
  378. m_TSClient = NULL;
  379. m_TSClientWnd = NULL;
  380. m_ConnectionInProgress = FALSE;
  381. m_RemoteControlRequestInProgress = FALSE;
  382. m_LastExtendedErrorInfo = 0;
  383. m_TimerId = 0; //used for pinging
  384. m_RdcConnCheckTimeInterval = RDC_CHECKCONN_TIMEOUT;
  385. //
  386. // No reference to listening library.
  387. //
  388. m_InitListeningLibrary = FALSE;
  389. m_ListenConnectInProgress = FALSE;
  390. m_ListenSocket = INVALID_SOCKET;
  391. m_TSConnectSocket = INVALID_SOCKET;
  392. m_ListenTimeoutTimerID = (UINT_PTR) 0;
  393. m_ICSPort = 0;
  394. //
  395. // Not valid until unitialized.
  396. //
  397. SetValid(FALSE);
  398. }
  399. ~CTSRDPRemoteDesktopClient();
  400. HRESULT FinalConstruct();
  401. DECLARE_REGISTRY_RESOURCEID(IDR_TSRDPREMOTEDESKTOPCLIENT)
  402. DECLARE_PROTECT_FINAL_CONSTRUCT()
  403. //
  404. // Event Sinks
  405. //
  406. VOID OnRDPConnected();
  407. VOID OnLoginComplete();
  408. VOID OnDisconnected(long disconReason);
  409. VOID OnMSTSCReceiveData(BSTR data);
  410. VOID OnReceivedTSPublicKey(BSTR tsPublicKey, VARIANT_BOOL* bContinue);
  411. //
  412. // Interface Map
  413. //
  414. BEGIN_COM_MAP(CTSRDPRemoteDesktopClient)
  415. COM_INTERFACE_ENTRY(IViewObjectEx)
  416. COM_INTERFACE_ENTRY(IViewObject2)
  417. COM_INTERFACE_ENTRY(IViewObject)
  418. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  419. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  420. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  421. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  422. COM_INTERFACE_ENTRY(IOleControl)
  423. COM_INTERFACE_ENTRY(IOleObject)
  424. COM_INTERFACE_ENTRY(IPersistStreamInit)
  425. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  426. COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
  427. COM_INTERFACE_ENTRY(IQuickActivate)
  428. COM_INTERFACE_ENTRY(IPersistStorage)
  429. COM_INTERFACE_ENTRY(IDataObject)
  430. COM_INTERFACE_ENTRY(IProvideClassInfo)
  431. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  432. COM_INTERFACE_ENTRY(ISAFRemoteDesktopClient)
  433. COM_INTERFACE_ENTRY(ISAFRemoteDesktopTestExtension)
  434. COM_INTERFACE_ENTRY2(IDispatch, ISAFRemoteDesktopClient)
  435. COM_INTERFACE_ENTRY(IDataChannelIO)
  436. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  437. END_COM_MAP()
  438. //
  439. // Property Map
  440. //
  441. BEGIN_PROP_MAP(CTSRDPRemoteDesktopClient)
  442. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  443. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  444. // Example entries
  445. // PROP_ENTRY("Property Description", dispid, clsid)
  446. // PROP_PAGE(CLSID_StockColorPage)
  447. END_PROP_MAP()
  448. //
  449. // Connection Point Map
  450. //
  451. BEGIN_CONNECTION_POINT_MAP(CTSRDPRemoteDesktopClient)
  452. CONNECTION_POINT_ENTRY(DIID__ISAFRemoteDesktopClientEvents)
  453. CONNECTION_POINT_ENTRY(DIID__IDataChannelIOEvents)
  454. END_CONNECTION_POINT_MAP()
  455. //
  456. // Message Map
  457. //
  458. BEGIN_MSG_MAP(CTSRDPRemoteDesktopClient)
  459. CHAIN_MSG_MAP(CComControl<CTSRDPRemoteDesktopClient>)
  460. DEFAULT_REFLECTION_HANDLER()
  461. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  462. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  463. MESSAGE_HANDLER(WM_SIZE, OnSize)
  464. MESSAGE_HANDLER(WM_TSCONNECT, OnTSConnect)
  465. MESSAGE_HANDLER(WM_TIMER, OnTimer)
  466. END_MSG_MAP()
  467. // Handler prototypes:
  468. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  469. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  470. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  471. //
  472. // IViewObjectEx Methods
  473. //
  474. DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
  475. public:
  476. LRESULT OnTSConnect(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  477. LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  478. LRESULT OnStartListen(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  479. //
  480. // OnDraw
  481. //
  482. HRESULT OnDraw(ATL_DRAWINFO& di)
  483. {
  484. RECT& rc = *(RECT*)di.prcBounds;
  485. Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
  486. HRESULT hr;
  487. if (!m_Initialized) {
  488. hr = S_OK;
  489. SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
  490. LPCTSTR pszText = _T("TSRDP Remote Desktop Client");
  491. TextOut(di.hdcDraw,
  492. (rc.left + rc.right) / 2,
  493. (rc.top + rc.bottom) / 2,
  494. pszText,
  495. lstrlen(pszText));
  496. }
  497. return hr;
  498. }
  499. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  500. {
  501. //
  502. // Hide our window, by default.
  503. //
  504. //ShowWindow(SW_HIDE);
  505. if (!m_Initialized) {
  506. LPCREATESTRUCT pCreateStruct = (LPCREATESTRUCT)lParam;
  507. Initialize(pCreateStruct);
  508. }
  509. return 0;
  510. }
  511. LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  512. {
  513. DC_BEGIN_FN("CTSRDPRemoteDesktopClient::OnSetFocus");
  514. //
  515. // Set focus back to the client window, if it exists.
  516. //
  517. if (m_TSClientWnd != NULL) {
  518. ::PostMessage(m_TSClientWnd, uMsg, wParam, lParam);
  519. }
  520. DC_END_FN();
  521. return 0;
  522. }
  523. //
  524. // OnSize
  525. //
  526. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  527. {
  528. DC_BEGIN_FN("CTSRDPRemoteDesktopClient::OnSize");
  529. if (m_TSClientWnd != NULL) {
  530. RECT rect;
  531. GetClientRect(&rect);
  532. ::MoveWindow(m_TSClientWnd, rect.left, rect.top,
  533. rect.right, rect.bottom, TRUE);
  534. }
  535. DC_END_FN();
  536. return 0;
  537. }
  538. LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  539. {
  540. bHandled = TRUE;
  541. return 0;
  542. //return DefWindowProc(uMsg, wParam, lParam);
  543. }
  544. //
  545. // ISAFRemoteDesktopClient Methods
  546. //
  547. STDMETHOD(ConnectToServer)(BSTR Server);
  548. STDMETHOD(DisconnectFromServer)();
  549. STDMETHOD(ConnectRemoteDesktop)();
  550. STDMETHOD(DisconnectRemoteDesktop)();
  551. STDMETHOD(get_IsRemoteDesktopConnected)(BOOL * pVal);
  552. STDMETHOD(get_IsServerConnected)(BOOL * pVal);
  553. STDMETHOD(put_EnableSmartSizing)(BOOL val);
  554. STDMETHOD(get_EnableSmartSizing)(BOOL *pVal);
  555. STDMETHOD(put_ColorDepth)(LONG Val);
  556. STDMETHOD(get_ColorDepth)(LONG* pVal);
  557. STDMETHOD(get_ExtendedErrorInfo)(LONG *error) {
  558. *error = m_LastExtendedErrorInfo;
  559. return S_OK;
  560. }
  561. STDMETHOD(get_ChannelManager)(ISAFRemoteDesktopChannelMgr **mgr) {
  562. *mgr = m_ChannelMgr;
  563. return S_OK;
  564. }
  565. STDMETHOD(put_ConnectParms)(/*[in]*/BSTR parms) {
  566. m_ConnectParms = parms;
  567. return S_OK;
  568. }
  569. STDMETHOD(get_ConnectParms)(/*[out, retval]*/BSTR *parms) {
  570. CComBSTR tmp;
  571. tmp = m_ConnectParms;
  572. *parms = tmp.Detach();
  573. return S_OK;
  574. }
  575. //
  576. // Scriptable Event Object Registration Properties (not supported)
  577. //
  578. STDMETHOD(put_OnConnected)(/*[in]*/IDispatch *iDisp) { return E_FAIL; }
  579. STDMETHOD(put_OnDisconnected)(/*[in]*/IDispatch *iDisp) { return E_FAIL; }
  580. STDMETHOD(put_OnConnectRemoteDesktopComplete)(/*[in]*/IDispatch *iDisp) { return E_FAIL; }
  581. STDMETHOD(put_OnListenConnect)(/*[in]*/IDispatch *iDisp) { return E_FAIL; }
  582. STDMETHOD(put_OnBeginConnect)(/*[in]*/IDispatch *iDisp) { return E_FAIL; }
  583. //
  584. // IDataChannelIO Methods
  585. //
  586. STDMETHOD(SendData)(/*[in]*/BSTR data);
  587. STDMETHOD(put_ChannelMgr)(/*[in]*/ISAFRemoteDesktopChannelMgr *newVal);
  588. //
  589. // Return the name of this class.
  590. //
  591. virtual const LPTSTR ClassName() {
  592. return TEXT("CTSRDPRemoteDesktopServer");
  593. }
  594. //
  595. // ISAFRemoteDesktopTestExtension
  596. //
  597. STDMETHOD(put_TestExtDllName)(/*[in]*/BSTR newVal);
  598. STDMETHOD(put_TestExtParams)(/*[in]*/BSTR newVal);
  599. STDMETHOD(get_ConnectedServer)(/*[in]*/BSTR* Val) {
  600. HRESULT hr = S_OK;
  601. if( m_ConnectedToServer ) {
  602. *Val = m_ConnectedServer.Copy();
  603. }
  604. else {
  605. hr = E_FAIL;
  606. }
  607. return hr;
  608. }
  609. STDMETHOD(get_ConnectedPort)(/*[in]*/LONG* Val) {
  610. HRESULT hr = S_OK;
  611. if( m_ConnectedToServer ) {
  612. *Val = m_ConnectedPort;
  613. }
  614. else {
  615. hr = E_FAIL;
  616. }
  617. return hr;
  618. }
  619. STDMETHOD(CreateListenEndpoint)(
  620. /*[in]*/ LONG port,
  621. /*[out, retval]*/ BSTR* pConnectParm
  622. );
  623. STDMETHOD(StartListen)(
  624. /*[in]*/ LONG timeout
  625. );
  626. STDMETHOD(AcceptListenConnection)(
  627. /*[in]*/BSTR expertBlob
  628. );
  629. STDMETHOD(StopListen)();
  630. };
  631. ///////////////////////////////////////////////////////
  632. //
  633. // CTSRDPRemoteDesktopClient Inline Methods
  634. //
  635. inline STDMETHODIMP
  636. CTSRDPRemoteDesktopClient::get_IsServerConnected(
  637. BOOL *pVal
  638. )
  639. /*++
  640. Routine Description:
  641. Indicates whether the client is connected to the server, excluding
  642. control over the remote user's desktop.
  643. Arguments:
  644. pVal - Set to TRUE if the client is connected to the server.
  645. Return Value:
  646. S_OK on success. Otherwise, an error code is returned.
  647. --*/
  648. {
  649. DC_BEGIN_FN("CTSRDPRemoteDesktopClient::get_IsServerConnected");
  650. HRESULT hr = S_OK;
  651. if (IsValid()) {
  652. *pVal = m_ConnectedToServer;
  653. }
  654. else {
  655. ASSERT(FALSE);
  656. hr = E_FAIL;
  657. }
  658. DC_END_FN();
  659. return hr;
  660. }
  661. inline STDMETHODIMP
  662. CTSRDPRemoteDesktopClient::get_IsRemoteDesktopConnected(
  663. BOOL *pVal
  664. )
  665. /*++
  666. Routine Description:
  667. Indicates whether the control is currently controlling the remote user's
  668. desktop.
  669. Arguments:
  670. pVal - Sets to TRUE if the control is currently connected to the server.
  671. Return Value:
  672. S_OK on success. Otherwise, an error code is returned.
  673. --*/
  674. {
  675. DC_BEGIN_FN("CTSRDPRemoteDesktopClient::get_IsRemoteDesktopConnected");
  676. HRESULT hr = S_OK;
  677. if (IsValid()) {
  678. *pVal = m_RemoteControlRequestInProgress;
  679. }
  680. else {
  681. ASSERT(FALSE);
  682. hr = E_FAIL;
  683. }
  684. DC_END_FN();
  685. return hr;
  686. }
  687. #endif //__TSRDPREMOTEDESKTOPCLIENT_H_