Page 1 of 1

Using mouse via WinAPI?

Posted: Tue Dec 30, 2008 9:39 am
by igorvlassov
Hello,

Is there some description or sample how to use WinAPI mouse system with Ogre?

Thanks,
Igor

Re: Using mouse via WinAPI?

Posted: Tue Dec 30, 2008 4:42 pm
by xavier
Ogre and input are orthogonal.

Also, what do you mean by "WinAPI mouse system"?

Re: Using mouse via WinAPI?

Posted: Mon Jan 05, 2009 4:06 pm
by igorvlassov
xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Sorry for late reply.
Classical WM_MOUSE* Windows messages processing.

Re: Using mouse via WinAPI?

Posted: Mon Jan 05, 2009 6:02 pm
by jacmoe
Does this forum look like a Win32 programming forum?

Re: Using mouse via WinAPI?

Posted: Mon Jan 05, 2009 7:09 pm
by xavier
igorvlassov wrote:
xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Sorry for late reply.
Classical WM_MOUSE* Windows messages processing.
You process them the same as you do for any other Win32 application. The problem you will run into with Ogre, is that the Win32 message dispatching is done in an internal class (WindowEventUtilities) so you'll probably want to make your own Win32 window and embed the Ogre render window in that, so that you have complete control over the message processing. Note, however, what sorts of things the Ogre code does in various scenarios, because you'll need to duplicate it.

Of course, you can always subclass the window class and call the Ogre WndProc when yours is done.

Re: Using mouse via WinAPI?

Posted: Mon Jan 05, 2009 7:31 pm
by Kojack
Depending on what you are doing and how adventurous you are, you may want to take a look at WM_INPUT instead of WM_MOUSE.
(I've just spent the last hour or so playing with it).
WM_MOUSE is good for simple cursor stuff, but it can't handle high precision mice (apparently it clamps them to a max of 400dpi). It works at screen res only.
WM_INPUT goes to the raw hid level, gives you mouse data at full precision, and other fun stuff. The code is harder and a lot longer though (but still less code than directinput mouse).

Here's some MSDN info on 3 ways of reading the mouse: http://msdn.microsoft.com/en-us/library ... S.85).aspx

Re: Using mouse via WinAPI?

Posted: Tue Jan 06, 2009 9:08 am
by Azgur
What's wrong with IOS? :)

Re: Using mouse via WinAPI?

Posted: Tue Jan 06, 2009 11:38 am
by igorvlassov
xavier wrote:
igorvlassov wrote:
xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Sorry for late reply.
Classical WM_MOUSE* Windows messages processing.
You process them the same as you do for any other Win32 application. The problem you will run into with Ogre, is that the Win32 message dispatching is done in an internal class (WindowEventUtilities) so you'll probably want to make your own Win32 window and embed the Ogre render window in that, so that you have complete control over the message processing. Note, however, what sorts of things the Ogre code does in various scenarios, because you'll need to duplicate it.

Of course, you can always subclass the window class and call the Ogre WndProc when yours is done.
Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.

Re: Using mouse via WinAPI?

Posted: Tue Jan 06, 2009 11:46 am
by igorvlassov
Azgur wrote:What's wrong with IOS? :)
I'm creating hunting game for specialized input equipment (laser riffle). I know it work like mouse but it change cursor position when shot only. As I know older games used windows mouse processing system and all was OK. I created 2 games using old 3d engine. It handled mouse processing by itself and I have a lot of troubles to make it work correctly. The problem also that I haven't direct access to riffle. So I can try to use IOS but I'm afraid to get new problems with.

Re: Using mouse via WinAPI?

Posted: Tue Jan 06, 2009 12:22 pm
by Kojack
Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.
I just wrote some code to intercept messages before the ogre winproc about an hour ago. Here's what I did:
(Note: this was part of a quick hacked together test for several random things I'm working on, so ignore crappiness)

Code: Select all

// A global to store ogre's winproc. 
// I could just use WindowEventUtilities::_WndProc directly, but this way preserves chaining in case something else did this first.
WNDPROC g_ogreWinProc = NULL;

// Your winproc code, which calls ogre's one when finished.
LRESULT APIENTRY SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		// handle your WM_**** stuff here
	}
	return CallWindowProc(g_ogreWinProc, hwnd, uMsg, wParam, lParam);
}


// insert this code somewhere in your initialisation:
HWND hwnd;
m_window->getCustomAttribute("WINDOW", (void*)&hwnd);
g_ogreWinProc = (WNDPROC) SetWindowLong(hwnd, GWL_WNDPROC, (LONG) SubclassProc); 
Now you get to handle your stuff and ogre still handles stuff like window move events, etc. At least it does for me so far. :)

Re: Using mouse via WinAPI?

Posted: Tue Jan 06, 2009 7:21 pm
by igorvlassov
Wow, Kojack,
thanks a lot!
Going to play with your code!!!

Re: Using mouse via WinAPI?

Posted: Thu Jan 15, 2009 9:14 pm
by Beauty
xavier wrote:
igorvlassov wrote:
xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Sorry for late reply.
Classical WM_MOUSE* Windows messages processing.
You process them the same as you do for any other Win32 application. The problem you will run into with Ogre, is that the Win32 message dispatching is done in an internal class (WindowEventUtilities) so you'll probably want to make your own Win32 window and embed the Ogre render window in that, so that you have complete control over the message processing. Note, however, what sorts of things the Ogre code does in various scenarios, because you'll need to duplicate it.

Of course, you can always subclass the window class and call the Ogre WndProc when yours is done.
igorvlassov wrote:Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.
I don't like quotes of quotes of quotes ...
Please don't use quotes if not needed.
If you use quotes, please use only the related part of text


@igorvlassov
Maybe you can edit your post end remove the quotes?
This would be nice for overview.

Re: Using mouse via WinAPI?

Posted: Thu Jan 15, 2009 9:22 pm
by Beauty
Kojack wrote:I just wrote some code
Nice, maybe this we can add it to the wiki.

By the way - what is the (dis)advantage to use OIS instead?
I did not understand.
http://www.ogre3d.org/wiki/index.php/OIS

Re: Using mouse via WinAPI?

Posted: Fri Jan 16, 2009 6:23 am
by Kojack
OIS uses direct input for mouse and keyboard handling (they are planning on changing that sometime). Microsoft recommend not to do that because it is less efficient.
When you tell directinput to read the keyboard and mouse, it spawns a thread that sits there reading WM_INPUT to get mouse and keyboard events. So they say it's better to just read WM_INPUT yourself, especially since it's smaller and easier code than directinput.
Also, directinput is incapable of distinguishing between multiple mice and keyboards, they are all merged together into just 2 system object, whereas WM_INPUT gives you an id number for each device, so you could have your game fully support multiple devices.

Of course that's mostly only of interest to people who don't mind writing their own input library. For most people who don't have specific requirements like multiple mice and keyboards, OIS is awesome.

Re: Using mouse via WinAPI?

Posted: Fri Jan 16, 2009 1:18 pm
by Beauty
Thanks :D

I added a link to your code with note to the OIS page of wiki.

Re: Using mouse via WinAPI?

Posted: Tue Apr 13, 2010 1:55 pm
by mkultra333
Apologies for the thread necromancy, I just wanted to say Kojack's above code for intercepting and processing windows messages is gold. It's just what I needed for a windows program I'm adapting to use Ogre. I'd never have been able to come up with that, so thanks!

Re: Using mouse via WinAPI?

Posted: Thu Oct 20, 2011 8:56 pm
by PauloMedia
Kojack wrote:Yes that is I wondered: entry point for my callback message processing func and where to put dispatchmessage etc. stuff.

I just wrote some code to intercept messages before the ogre winproc about an hour ago. Here's what I did:
(Note: this was part of a quick hacked together test for several random things I'm working on, so ignore crappiness)

Code: Select all

// A global to store ogre's winproc. 
// I could just use WindowEventUtilities::_WndProc directly, but this way preserves chaining in case something else did this first.
WNDPROC g_ogreWinProc = NULL;

// Your winproc code, which calls ogre's one when finished.
LRESULT APIENTRY SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		// handle your WM_**** stuff here
	}
	return CallWindowProc(g_ogreWinProc, hwnd, uMsg, wParam, lParam);
}


// insert this code somewhere in your initialisation:
HWND hwnd;
m_window->getCustomAttribute("WINDOW", (void*)&hwnd);
g_ogreWinProc = (WNDPROC) SetWindowLong(hwnd, GWL_WNDPROC, (LONG) SubclassProc); 
Now you get to handle your stuff and ogre still handles stuff like window move events, etc. At least it does for me so far. :)
I put this code to my Sourcecode, but I get an error:
\Escape_Main.cpp|383|error: invalid use of member (did you forget the '&' ?)|
in this line:

Code: Select all

ogreWndProc = (WNDPROC) SetWindowLongA(hwnd, GWL_WNDPROC,(LONG) EscapeWndProc);
(I renamed some of the variables.)

I dont know, what my compiler wants to tell me :(

Re: Using mouse via WinAPI?

Posted: Sat Jan 28, 2012 8:59 pm
by PauloMedia
Cant remember now.

It was long ago since i worked on my program but i think i found a different solution

Re: Using mouse via WinAPI?

Posted: Fri May 08, 2015 6:25 am
by swuth
Thanks for that Code SNippet Kojak! I am porting a game from d3D to Ogre and was having a helluva time getting the winproc to fire. Many Thanks
:D