1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #ifndef __MaterialSender_h__
4 #define __MaterialSender_h__
7 #define WM_MATEDITSEND (WM_USER + 315)
9 enum EMaterialSenderMessage
12 eMSM_GetSelectedMaterial
= 2,
16 struct SMaterialMapFileHeader
19 void SetMaxHWND(HWND hWnd
)
21 hwndMax
= (int64
)hWnd
;
23 HWND
GetMaxHWND() const
28 void SetEditorHWND(HWND hWnd
)
30 hwndMatEdit
= (int64
)hWnd
;
32 HWND
GetEditorHWND() const
34 return (HWND
)hwndMatEdit
;
36 int64 msg
;// 64bits for both 32 and 64
37 int64 Reserved
;// 64bits for both 32 and 64
39 uint64 hwndMax
;// HWND for 32 and 64 is different
40 uint64 hwndMatEdit
;// HWND for 32 and 64 is different
47 CMaterialSender(bool bIsMatEditor
) : m_bIsMatEditor(bIsMatEditor
)
55 CMaterialSender::~CMaterialSender()
58 CloseHandle(hMapFile
);
70 if (!m_h
.GetMaxHWND() || !m_h
.GetEditorHWND() || !::IsWindow(m_h
.GetMaxHWND()) || !::IsWindow(m_h
.GetEditorHWND()))
72 if (!m_h
.GetMaxHWND() || !m_h
.GetEditorHWND() || !::IsWindow(m_h
.GetMaxHWND()) || !::IsWindow(m_h
.GetEditorHWND()))
80 CloseHandle(hMapFile
);
81 hMapFile
= CreateFileMapping(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, 1024 * 1024, "EditMatMappingObject");
85 CryLog("Can't create File Map");
90 bool SendMessage(int msg
, const XmlNodeRef
& node
)
99 int nDataSize
= sizeof(SMaterialMapFileHeader
) + strlen(node
->getXML().c_str());
101 //hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, nDataSize, "EditMatMappingObject");
103 HANDLE hMapFile
= OpenFileMapping(FILE_MAP_ALL_ACCESS
, FALSE
, "EditMatMappingObject");
106 void* pMes
= MapViewOfFile(hMapFile
, FILE_MAP_ALL_ACCESS
, 0, 0, nDataSize
);
109 memcpy(pMes
, &m_h
, sizeof(SMaterialMapFileHeader
));
110 strcpy(((char*)pMes
) + sizeof(SMaterialMapFileHeader
), node
->getXML().c_str());
111 UnmapViewOfFile(pMes
);
113 ::SendMessage(m_h
.GetMaxHWND(), WM_MATEDITSEND
, msg
, 0);
115 ::SendMessage(m_h
.GetEditorHWND(), WM_MATEDITSEND
, msg
, 0);
118 CloseHandle(hMapFile
);
121 CryLog("No File Map");
126 void SetupWindows(HWND hwndMax
, HWND hwndMatEdit
)
128 m_h
.SetMaxHWND(hwndMax
);
129 m_h
.SetEditorHWND(hwndMatEdit
);
137 const HANDLE hMapFile
= OpenFileMapping(FILE_MAP_ALL_ACCESS
, FALSE
, "EditMatMappingObject");
140 void* const pMes
= MapViewOfFile(hMapFile
, FILE_MAP_ALL_ACCESS
, 0, 0, 0);
144 memcpy(&m_h
, pMes
, sizeof(SMaterialMapFileHeader
));
145 const char* const pXml
= ((const char*)pMes
) + sizeof(SMaterialMapFileHeader
);
146 m_node
= XmlHelpers::LoadXmlFromBuffer(pXml
, strlen(pXml
));
147 UnmapViewOfFile(pMes
);
151 CloseHandle(hMapFile
);
158 SMaterialMapFileHeader m_h
;
165 #endif //__MaterialSender_h__