Jump to content
  • Advertisement
Sign in to follow this  
Cantos

fullscreen vs windows mouse coordinate discrepancy - win32

This topic is 2835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having trouble with mouse coordinates in a fullscreen win32/directx application. When I run windowed, the coordinates appear correct, that is, when I move the mouse to the top left corner, the coordinates are [0,0], and when I move the mouse over a button, the button goes to its mouseover/hover state as expected. When I run fullscreen though, I find that the vertical coordinate is out of sync. I can get to x,0 even when I can see my mouse is about 20-30 pixels below the top of the screen, and moving the mouse while above this line doesn't seem to generate WM_MOUSEMOVE messages at all. When I hover over my button, it wont go to mouseover, I need to hover the mouse about 20-30 pixels below where the button is displayed. I also cant get the vertical coordinate to get above 1052 (the screen size I'm using is 1920x1080) no matter how slowly I move the mouse down.

Here's how I'm Creating the Window.
hwnd = CreateWindow(wcl.lpszClassName,
Title.c_str(),
WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
screen_width,
screen_height,
NULL,
NULL,
GetModuleHandle(NULL),
this);


If it's not running in fullscreen I also do this


RECT r = {0,0,screen_width,screen_height};
AdjustWindowRectEx(&r,WS_CAPTION,FALSE,NULL);

uint32 w32_width = r.right - (r.left);
uint32 w32_height = r.bottom - (r.top);

SystemParametersInfo(SPI_GETWORKAREA,0,&r,0);
uint32 workspace_width = r.right - r.left;
uint32 workspace_height = r.bottom - r.top;

// is the window size less than the workspace size? Y:N
int left = (w32_width<workspace_width)? (workspace_width-w32_width)/2 : 0;
int top = (w32_height<workspace_height)? (workspace_height-w32_height)/2 : 0;
SetWindowPos( hwnd,
HWND_NOTOPMOST,
left,
top,
w32_width,
w32_height,
NULL );

//show the window again
ShowWindow(hwnd,SW_SHOW);



Is there something I'm doing wrong with these calls?

Share this post


Link to post
Share on other sites
Advertisement
Something I forgot to add: I copy pasted this code from an old project that ran fine on my old Windows 2000 machine compiled in VS2005 Express. I'm having trouble with it on my new Windows 7 machine compiled in VS 2010 Express. Could the NT6.x changes to the API be causing this?

Share this post


Link to post
Share on other sites
The 20-30 pixels part sounds suspicious, and suggests to me that something somewhere is asjusting for the presence of a title bar (that doesn't exist in your fullscreen mode). You may possibly wish to drop the use of the WS_SYSMENU style when creating fullscreen windows.

Share this post


Link to post
Share on other sites
Well, I figured it out. I went so far as to run my application on XP through VirtualBox to confirm that my code worked as I remember on older versions of windows. It did, so I went looking at how windowing libraries handled window creation. All I needed to change was to use WS_POPUP for my fullscreen window style instead of WS_SYSMENU and everything lines up. For some reason this behavior is different between Windows 7 and XP/2000.

Hopefully this helps anyone else who gets caught by this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!