Game Development Reference
In-Depth Information
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax,
UINT wRemoveMsg
);
According to the documentation
If a message is available, the return value is nonzero.
If no messages are available, the return value is zero.
This is the perfect function to decide if there are events waiting for our particular
application.
It's not very important to understand all the details of this C function. The im-
portant thing is how the function is called from C#. To call it from C#, the
function arguments need changing from C types to the equivalent C# types.
The first argument, lpMsg is a message type. This type isn't available in C#; it
needs to be imported. The second type is a Windows handle; this is just a refer-
ence to our form. The last three arguments are all unsigned integers, which are a
standard C# type. Here's the C message structure, which is the first argument.
typedef struct {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG, *PMSG;
The structure members aren't that important; here's how to import this C type
into C#. First, include the using statement using System.Runtime.In-
teropServices; at the top of the FastLoop.cs with the other using state-
ments. This library has useful functions for importing C types and structures.
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace GameLoop
{
[StructLayout(LayoutKind.Sequential)]
 
Search WWH ::




Custom Search