Reputation: 5460
So, I'm trying to acquire the x-y coordinates of the CORNERS of my MFC window...
Here's what I have so far in my draw function:
// TODO: add draw code for native data here
RECT rect;
GetClientRect(&rect);
// Get window coordinates
int left = rect.left;
int right = rect.right;
int bottom = rect.bottom;
int top = rect.top;
// Print them out
CString l;
l.Format(L"%d", left);
pDC->TextOutW(0, 100, L"Left: " + l, _tcslen(l)+6);
CString r;
r.Format(L"%d", right);
pDC->TextOutW(0, 130, L"Right: " + r, _tcslen(r)+7);
CString b;
b.Format(L"%d", bottom);
pDC->TextOutW(0, 160, L"Bottom: " + b, _tcslen(b)+8);
CString t;
t.Format(L"%d", top);
pDC->TextOutW(0, 190, L"Top: " + t, _tcslen(t)+5);
Am I headed in the right direction? I was thinking I could find the midpoint of the two or something along those lines....
What else do I need to do?
Also: How would I acquire the x-y coordinates of the corners of my physical display as well?
Upvotes: 1
Views: 819
Reputation: 50778
Use the GetWindowRect function instead of the GetClientRect function.
You also may have a look at the ScreenToClient and the ClientToScreen functions.
Upvotes: 1
Reputation: 10415
Adding something to "Left: " is invalid. Use the Format statement to build the entire string to be displayed, and use the CString::GetLength() method if you need the length. (There is a version of TextOut that accepts a CString without the length parameter.)
Upvotes: 0