Skip to main content
GameDev.net gamedev.net
🔒 Locked

Mouse position

Started by smittix Oct 15, 2005 at 8:17 AM 6 replies 550+ views
Original Post
smittix
smittix
I need to find the X and Y position of the mouse in respect to its window, but the current method I am using includes the width and height of the title bar and side of the window into the position: xPos = (LOWORD(lParam)); yPos = (HIWORD(lParam)); How do I find the position of the mouse within the actual window area, not including the title bar or sides of the window? Thanks, Chris
SiCrane
SiCrane
Which message are you using for that code?
SiCrane
SiCrane
And which message are you processing when you run that code?
smittix
smittix
It is caught like this:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_DESTROY:
::PostQuitMessage(0);
break;
case WM_KEYDOWN:
if( wParam == VK_ESCAPE)
::DestroyWindow(hwnd);
break;
}

xLast = xPos;
yLast = yPos;
xPos = (LOWORD(lParam));
yPos = (HIWORD(lParam));

return ::DefWindowProc(hwnd, msg, wParam, lParam);
}
xeddiex
xeddiex
WM_MOUSEMOVE :xPos = LOWORD(lParam);yPos = HIWORD(lParam);
one..
Endar
Endar
I've never actually seen someone use the "::" global namespace specifier.

I mean, I'm not critisicing, but, when you don't specify any other namespace, isn't the global namespace kind of implied?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
risingdragon3
risingdragon3
No.

The lookup process looks at the namespace that the scope is currently in first. There are other various cases, like Koenig lookup and stuff, but that's really complicated. Still, the main point is that the namespace you are in is looked up first.

#include <iostream>void print() {  std::cout << "NO!!!\n";}namespace a {  void print() {    std::cout << "Hi!\n";  }  void DoStuff() {    print();    ::print();  }}int main() {  a::DoStuff();}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.