MOIS in winforms crashes

Vectrex

06-01-2010 12:48:18

Hi, when I try and create a MOIS keyboard or mouse with Ogre embedded in winforms it crashes. This only happens when my Ogre render window is part of the .net winforms window and not if the Ogre window is seperated. When the window is seperate it doesn't crash but I don't seem to get the input events either..

Has anyone used MOIS with winforms in this way? Care to paste a few lines?


public void Initialise()
{
MOIS.ParamList pl = new MOIS.ParamList();
IntPtr windowHnd;
Renderer.Instance.RenderWindow.GetCustomAttribute("WINDOW", out windowHnd);
pl.Insert("WINDOW", windowHnd.ToString());

inputManager = MOIS.InputManager.CreateInputSystem(pl);

// CRASHES HERE if embedded. 'RenderWindow' and windowHnd seem to have ok values
InputMouse = (MOIS.Mouse)inputManager.CreateInputObject(MOIS.Type.OISMouse, true);
InputKeyboard = (MOIS.Keyboard)inputManager.CreateInputObject(MOIS.Type.OISKeyboard, true);

// These events don't seem to get called either
InputKeyboard.KeyPressed += new KeyListener.KeyPressedHandler(InputKeyboard_KeyPressed);
InputMouse.MouseMoved += new MouseListener.MouseMovedHandler(InputMouse_MouseMoved);
}

smiley80

06-01-2010 13:55:53

MOIS doesn't like control handles, use the form handle instead:
pl.Insert("WINDOW", myForm.Handle.ToString());

Vectrex

08-01-2010 12:52:37

Thanks, that solved one problem :)
I still can't get events to trigger or state to do anything, like x,y mouse or keypressed type stuff.
I'm calling capture in the mainloop

inputKeyboard.Capture();
inputMouse.Capture();

zorocke

10-04-2010 23:58:39

MOIS doesn't like control handles, use the form handle instead:
pl.Insert("WINDOW", myForm.Handle.ToString());


Sorry to bring up such an old thread.. But i think I may be having the same problem. Though when i edit my code to the above, i get something like

Error 1 An object reference is required for the non-static field, method, or property 'System.Windows.Forms.Control.Handle.get' C:\Documents and Settings\steven\My Documents\My Dropbox\D-Race\LevelEditor\LevelEditor\Form1.cs 103 31 LevelEditor

I don't know if i'm reading this right, but it appears myForm(Form1 in my case) does not have a Handle function or parameter or what ever "Handle" is...
Sorry, i'm very new to C#..

Can anyone explain what is happening here?

smiley80

11-04-2010 01:39:26

That's called a 'Property'.

The error means you're trying to access 'Handle' through the type ('Form1.Handle'), that's not possible for non-static members, you'll need an instance of that type.

If you've put the 'Initialise' method inside your 'Form1' class, you can use the 'this' keyword ('this.Handle').
Otherwise, you've probably instantiated your class ('Form1 myForm1 = new Form1()') somewhere, in which case you've to use that instance ('myForm1.Handle').