Sign in to follow this  
CyberSlag5k

MFC - Window Position

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

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