Game Development Reference
In-Depth Information
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
EditorForm form = new EditorForm();
MessageHandler messageHandler = form.GetMessageHandler();
Application.AddMessageFilter(messageHandler);
Application.Idle +=
new EventHandler(messageHandler.Application_Idle);
Application.Run(form);
}
}
}
The first two lines are typical of C# Windows Forms applications, and they ensure
that the window, buttons, menus, and other visual components draw as you would
expect them to. The next line creates the EditorForm , which contains all of the
user interface elements of the editor.
The next three lines are critical to shepherding Windows messages, like WM_MOUSE ,
from the C# application to the C++ side of
things. Lastly,
the
call
to
Application.Run(form) gets everything running.
MessageHandler Class
To get Windows messages from the C# application to C++, you need to set up a spe-
cial helper class. If a mouse button is clicked on the rendered image of the game, the
message shouldn
t go to the placeholder panel on the C# Windows Form, but rather
it should be trapped and sent to the C++ game engine. Luckily, there
'
s an interface
class for exactly that, the IMessageFilter interface. As messages are trapped, they
are converted to Windows messages that the C++ game engine can consume, and
they are sent in to the WndProc() free function defined in the DLL. It is called by
using the NativeMethods class, which imports all of the exposed DLL functions.
'
using System;
using System.Collections.Generic;
 
 
Search WWH ::




Custom Search