Jump to content
  • Advertisement
Sign in to follow this  
CyberSlag5k

MFC - Window Position

This topic is 4383 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 need to know the position of the window my MFC app lies in screen coordinates. Unfortunately, functions such as GetWindowPos and GetWindowPlacement seem to only refer to client coordinates, and when I try and call them on the main window (rather than a dialog within that window or something), they return 0,0 for the upper left-hand position (which is incorrect). I've tried calling ClientToScreen on the resulting RECT, but that didn't really help either. Is there another way to get the position of the main window of my MFC app? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Hi CyberSlag5k,

Have you tried GetWindowInfo? It takes a WINDOWINFO, which has both screen and client coordinates. And it looks like its a MFC has the same function under CWnd, so I would give that a try.

-brad

Share this post


Link to post
Share on other sites
Thanks for the suggestions, guys.

Both WINDOWINFO and GetWindowInfo come up as undeclared identifiers. Perhaps it's just my version of MFC (though I believe it is the latest, and it does show up under intellisense).

Also, GetWindowRect doesn't seem to take 2 parameters, though I thought there was a similar function that did, but I looked and didn't find it.

I did like both suggestions, though, so if there's something I can tweak to get either working, I'm game.

Thanks again!

Share this post


Link to post
Share on other sites
hmmm odd,

RECT rect;
::GetWindowRect(GetSafeHwnd(), &rect);

or

RECT rect;
GetWindowRect(&rect);

should work for MFC.

Share this post


Link to post
Share on other sites
Ah there we go. For some reason it would only work within the global namespace. Now I'm getting exactly what I wanted. Thank you very much.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!