Using mouse via WinAPI?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
igorvlassov
Halfling
Posts: 89
Joined: Thu Apr 22, 2004 11:22 am
Contact:

Using mouse via WinAPI?

Post by igorvlassov » Tue Dec 30, 2008 9:39 am

Hello,

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

Thanks,
Igor
0 x

User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US

Re: Using mouse via WinAPI?

Post by xavier » Tue Dec 30, 2008 4:42 pm

Ogre and input are orthogonal.

Also, what do you mean by "WinAPI mouse system"?
0 x
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.

igorvlassov
Halfling
Posts: 89
Joined: Thu Apr 22, 2004 11:22 am
Contact:

Re: Using mouse via WinAPI?

Post by igorvlassov » Mon Jan 05, 2009 4:06 pm

xavier wrote: Also, what do you mean by "WinAPI mouse system"?
Sorry for late reply.
Classical WM_MOUSE* Windows messages processing.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Using mouse via WinAPI?

Post by jacmoe » Mon Jan 05, 2009 6:02 pm

Does this forum look like a Win32 programming forum?
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US

Re: Using mouse via WinAPI?

Post by xavier » Mon Jan 05, 2009 7:09 pm

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.
0 x
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7152
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 19

Re: Using mouse via WinAPI?

Post by Kojack » Mon Jan 05, 2009 7:31 pm

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
0 x

User avatar
Azgur
Goblin
Posts: 264
Joined: Thu Aug 21, 2008 4:48 pm

Re: Using mouse via WinAPI?

Post by Azgur » Tue Jan 06, 2009 9:08 am

What's wrong with IOS? :)
0 x

igorvlassov
Halfling
Posts: 89
Joined: Thu Apr 22, 2004 11:22 am
Contact:

Re: Using mouse via WinAPI?

Post by igorvlassov » Tue Jan 06, 2009 11:38 am

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.
0 x

igorvlassov
Halfling
Posts: 89
Joined: Thu Apr 22, 2004 11:22 am
Contact:

Re: Using mouse via WinAPI?

Post by igorvlassov » Tue Jan 06, 2009 11:46 am

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.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7152
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 19

Re: Using mouse via WinAPI?

Post by Kojack » Tue Jan 06, 2009 12:22 pm

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. :)
0 x

igorvlassov
Halfling
Posts: 89
Joined: Thu Apr 22, 2004 11:22 am
Contact:

Re: Using mouse via WinAPI?

Post by igorvlassov » Tue Jan 06, 2009 7:21 pm

Wow, Kojack,
thanks a lot!
Going to play with your code!!!
0 x

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Using mouse via WinAPI?

Post by Beauty » Thu Jan 15, 2009 9:14 pm

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.
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Using mouse via WinAPI?

Post by Beauty » Thu Jan 15, 2009 9:22 pm

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
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7152
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 19

Re: Using mouse via WinAPI?

Post by Kojack » Fri Jan 16, 2009 6:23 am

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.
0 x

User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
Contact:

Re: Using mouse via WinAPI?

Post by Beauty » Fri Jan 16, 2009 1:18 pm

Thanks :D

I added a link to your code with note to the OIS page of wiki.
0 x
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.

User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1889
Joined: Sun Mar 08, 2009 5:25 am
x 36

Re: Using mouse via WinAPI?

Post by mkultra333 » Tue Apr 13, 2010 1:55 pm

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!
0 x
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

PauloMedia
Gnoblar
Posts: 9
Joined: Thu Feb 24, 2011 4:03 pm
Contact:

Re: Using mouse via WinAPI?

Post by PauloMedia » Thu Oct 20, 2011 8:56 pm

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 :(
0 x

PauloMedia
Gnoblar
Posts: 9
Joined: Thu Feb 24, 2011 4:03 pm
Contact:

Re: Using mouse via WinAPI?

Post by PauloMedia » Sat Jan 28, 2012 8:59 pm

Cant remember now.

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

swuth
Bronze Sponsor
Bronze Sponsor
Posts: 53
Joined: Wed Mar 25, 2015 10:01 pm

Re: Using mouse via WinAPI?

Post by swuth » Fri May 08, 2015 6:25 am

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
0 x

Post Reply