summaryrefslogtreecommitdiff
path: root/hammer/shellmessagewnd.cpp
blob: a4891857848e76766e497b0ce87cf40e91907d51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Receives shell commands from other applications and forwards them
//			to the shell command handler.
//
// $Workfile:     $
// $Date:         $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//

#include "stdafx.h"
#include "Shell.h"
#include "ShellMessageWnd.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>


static const char *g_pszClassName = "Worldcraft_ShellMessageWnd";


BEGIN_MESSAGE_MAP(CShellMessageWnd, CWnd)
	//{{AFX_MSG_MAP(CShellMessageWnd)
	ON_WM_COPYDATA()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//-----------------------------------------------------------------------------
// Purpose: Creates the hidden shell message window.
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CShellMessageWnd::Create(void)
{
	WNDCLASS wndcls;
	memset(&wndcls, 0, sizeof(WNDCLASS));
    wndcls.style         = 0;
    wndcls.lpfnWndProc   = AfxWndProc;
    wndcls.hInstance     = AfxGetInstanceHandle();
    wndcls.hIcon         = NULL;
    wndcls.hCursor       = NULL;
    wndcls.hbrBackground = NULL;
    wndcls.lpszMenuName  = NULL;
	wndcls.cbWndExtra    = 0;
    wndcls.lpszClassName = g_pszClassName;

	if (!AfxRegisterClass(&wndcls))
	{
		AfxMessageBox("Could not register the Hammer shell message window class.");
		return(false);
	}

	return(CWnd::CreateEx(0, g_pszClassName, g_pszClassName, 0, CRect(0, 0, 10, 10), NULL, 0) == TRUE);
}


//-----------------------------------------------------------------------------
// Purpose: Attaches a shell command handler to this message window. All commands
//			received by this message window will be sent to the command handler.
// Input  : pShell - Shell command handler. NULL disables command processing.
//-----------------------------------------------------------------------------
void CShellMessageWnd::SetShell(CShell *pShell)
{
	Assert(pShell != NULL);
	m_pShell = pShell;
}


//-----------------------------------------------------------------------------
// Purpose: Handles the WM_COPYDATA message containing the shell command from
//			another application.
// Input  : pWnd - Temporary CWnd object of the sending window.
//			pCopyData - Copy data struct with shell command in the lpData field.
// Output : Returns TRUE on success, FALSE on failure.
//-----------------------------------------------------------------------------
BOOL CShellMessageWnd::OnCopyData(CWnd *pWnd, COPYDATASTRUCT *pCopyData)
{
	if (m_pShell != NULL)
	{
		if (pCopyData->lpData != NULL)
		{
			return(m_pShell->RunCommand((const char *)pCopyData->lpData) ? TRUE : FALSE);
		}
	}

	return(FALSE);
}