Sign in to follow this  
EnlightenedOne

Windows Window not updating top and left in message pump

Recommended Posts

Hi,

I am working on an application using Win7, C++ and DirectInput in order to grab the mouses clicking etc.

I have a program where I identify the mouses click and scale the mouses position accounting for the windowed windows Left and Top offset, header + border size etc (based on show cmd and WINDOWINFO). I do this so that I can do all the collision calculations in the program for collision between the mouse and the UI in screen space in fullscreen mode and have this work with upscaled mouse coordinates taken from clicks over the windowed window.

[font="Consolas"][size="2"][font="Consolas"][size="2"][font="Arial"][size="2"]Anyway this all works perfectly with one exception, in windows 7 if you have a window and you drag it heightwise down to the taskbar and wait it will stretch the window to fit the screen vertically, the same is true of their intuitive system of dragging windows to the side to make them take over half the screen. Unfortunately in my window message pump these changes are not given to me. [/size][/font]

If I do GetWindowPlacement(hWnd, &gWPHandle) in the message pump, when the window is readjusted to fit the space the top and left returned are not changed (presumably so you can exit this stretched mode easily using these values), how do I figure out when this mode is active and get the actual left and top? Without them being correct all my clicks when scaled are offset by the left and top despite these obviouly not being set to the actual left and top of the window and therefore my clicking is all off.

Am I wrong in thinking you would still have to identify where you had taken the mouse click from relative to the window in order to get a ray into the world? I have never done mouse clicks into a 3D world before, in an RTS mouse clicking must be a royal pain.

Anyone got any answers as to what will flag this counter intuitive adjustment Windows is making outside of my windows placement?

[/size][/font]Thanks, Enlightened[/size][/font]

Share this post


Link to post
Share on other sites
Alright, I may be completely confused by what you are asking, but why don't you just use [url="http://msdn.microsoft.com/en-us/library/dd162952(v=vs.85).aspx"]ScreenToClient()[/url]?

Also, why did you change font mid post?

Share this post


Link to post
Share on other sites
[quote name='Serapth' timestamp='1314022361' post='4852292']
Alright, I may be completely confused by what you are asking, but why don't you just use [url="http://msdn.microsoft.com/en-us/library/dd162952(v=vs.85).aspx"]ScreenToClient()[/url]?

Also, why did you change font mid post?
[/quote]


I was unaware of that function, thank you for the link I will experiment with it and see if I can remove some of my other code.

Internet explorer 9 does not work remotely with this forum, the "Insert Code Snippet" causes crazy errors and so when I copied in the function name I was refering too it changed the font and as even drag selection on certain fonts doesn't work I didn't attempt to rectify it.

Share this post


Link to post
Share on other sites
[quote name='EnlightenedOne' timestamp='1314049534' post='4852526']
[quote name='Serapth' timestamp='1314022361' post='4852292']
Alright, I may be completely confused by what you are asking, but why don't you just use [url="http://msdn.microsoft.com/en-us/library/dd162952(v=vs.85).aspx"]ScreenToClient()[/url]?

Also, why did you change font mid post?
[/quote]


I was unaware of that function, thank you for the link I will experiment with it and see if I can remove some of my other code.

Internet explorer 9 does not work remotely with this forum, the "Insert Code Snippet" causes crazy errors and so when I copied in the function name I was refering too it changed the font and as even drag selection on certain fonts doesn't work I didn't attempt to rectify it.
[/quote]


You can insert a code snippet manually by typing the "["code"]" and "/["code"]" tags

Share this post


Link to post
Share on other sites
You should not need to adjust mouse coordinates to compensate for the window's borders. Usually you will draw your graphics onto the window's client area (the area of the window that is not the borders), so use mouse coordinates in "client space". All mouse-related messages posted to your window procedure will have client-space mouse coordinates, such that (0,0) is the top left pixel of the client area. If you use GetCursorPos(), which returns screen-space mouse coordinates, then you can use ScreenToClient() as Serapth suggested to convert to client space.

When your window goes fullscreen for whatever reason, usually the window's style will be changed to have all borders removed, making the window consist of nothing but the client area, so any code which uses client-space mouse coordinates should work regardless of window style and placement.

Try searching these forums for myriad of posts about how to convert from 2D mouse coordinates to 3D rays.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this