Counter Strike : Global Offensive Source Code
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.

92 lines
2.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Receives shell commands from other applications and forwards them
  4. // to the shell command handler.
  5. //
  6. // $Workfile: $
  7. // $Date: $
  8. //
  9. //-----------------------------------------------------------------------------
  10. // $Log: $
  11. //
  12. // $NoKeywords: $
  13. //=============================================================================//
  14. #include "stdafx.h"
  15. #include "Shell.h"
  16. #include "ShellMessageWnd.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. static const char *g_pszClassName = "Worldcraft_ShellMessageWnd";
  20. BEGIN_MESSAGE_MAP(CShellMessageWnd, CWnd)
  21. //{{AFX_MSG_MAP(CShellMessageWnd)
  22. ON_WM_COPYDATA()
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. //-----------------------------------------------------------------------------
  26. // Purpose: Creates the hidden shell message window.
  27. // Output : Returns true on success, false on failure.
  28. //-----------------------------------------------------------------------------
  29. bool CShellMessageWnd::Create(void)
  30. {
  31. WNDCLASS wndcls;
  32. memset(&wndcls, 0, sizeof(WNDCLASS));
  33. wndcls.style = 0;
  34. wndcls.lpfnWndProc = AfxWndProc;
  35. wndcls.hInstance = AfxGetInstanceHandle();
  36. wndcls.hIcon = NULL;
  37. wndcls.hCursor = NULL;
  38. wndcls.hbrBackground = NULL;
  39. wndcls.lpszMenuName = NULL;
  40. wndcls.cbWndExtra = 0;
  41. wndcls.lpszClassName = g_pszClassName;
  42. if (!AfxRegisterClass(&wndcls))
  43. {
  44. AfxMessageBox("Could not register the Hammer shell message window class.");
  45. return(false);
  46. }
  47. return(CWnd::CreateEx(0, g_pszClassName, g_pszClassName, 0, CRect(0, 0, 10, 10), NULL, 0) == TRUE);
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose: Attaches a shell command handler to this message window. All commands
  51. // received by this message window will be sent to the command handler.
  52. // Input : pShell - Shell command handler. NULL disables command processing.
  53. //-----------------------------------------------------------------------------
  54. void CShellMessageWnd::SetShell(CShell *pShell)
  55. {
  56. Assert(pShell != NULL);
  57. m_pShell = pShell;
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose: Handles the WM_COPYDATA message containing the shell command from
  61. // another application.
  62. // Input : pWnd - Temporary CWnd object of the sending window.
  63. // pCopyData - Copy data struct with shell command in the lpData field.
  64. // Output : Returns TRUE on success, FALSE on failure.
  65. //-----------------------------------------------------------------------------
  66. BOOL CShellMessageWnd::OnCopyData(CWnd *pWnd, COPYDATASTRUCT *pCopyData)
  67. {
  68. if (m_pShell != NULL)
  69. {
  70. if (pCopyData->lpData != NULL)
  71. {
  72. return(m_pShell->RunCommand((const char *)pCopyData->lpData) ? TRUE : FALSE);
  73. }
  74. }
  75. return(FALSE);
  76. }