MFC - Window Position

Started by
4 comments, last by CyberSlag5k 17 years, 9 months ago
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!
Without order nothing can exist - without chaos nothing can evolve.
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
-brad
does GetWindowRect(GetSafeHwnd(), &rect) work?
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!
Without order nothing can exist - without chaos nothing can evolve.
hmmm odd,

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

or

RECT rect;
GetWindowRect(&rect);

should work for MFC.
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.
Without order nothing can exist - without chaos nothing can evolve.

This topic is closed to new replies.

Advertisement