SetBlitz3DEventCallback and SetBlitz3DHWND Bug

Blitz3D SDK Forums/Blitz3D SDK Bug Reports/SetBlitz3DEventCallback and SetBlitz3DHWND Bug

Ok, just created a UserControl and derived it from Panel and implemented IMessageFilter. This allows you to capture events i.e. Pre-filter them before dispatch.
I have pasted some example code below that shows how to implement this. This won't work out-of-the-box but it shows how to do it.


Code for the user control that implements the IMessageFilter, the PreFilterMessage function is called by the OS to filter the messages before dispatch.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace MyApplication
{

    public partial class RenderPanel : Panel, IMessageFilter
    {

        /// <summary>
        ///  Construction
        /// </summary>
        public RenderPanel()
        {
            InitializeComponent();
        }


        /// <summary>
        /// This is just a property to allow the parent control to see the last message that was filtered
        /// </summary>
        public string LastEvent
        {
            get { return m_s_last_event; }
        }private string m_s_last_event;


        /// <summary>
        /// The interface method, which is called to err.. pre filter messages :)
        /// </summary>
        /// <param name="m">reference to the message object</param>
        /// <returns>true to filter the message and stop it from being dispatched; 
        ///         false to allow the message to continue to the next filter or control.</returns>
        public bool PreFilterMessage(ref Message m)
        {
            // set the debug property to the message id
            m_s_last_event = m.Msg.ToString();

            return false;
        }
    }
}



This code shows how to actually register the object with the application message filters, if this is not done it will not work. You need to add a RenderPanel control to the main form in the normal way. Next, you need to add the following code somewhere in an initialisation function such as Form.Load to register the message filter.
Application.AddMessageFilter( My_RenderControl );