简体   繁体   中英

Window Corner Coordinates in MFC

So, I'm trying to acquire the xy 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 xy coordinates of the corners of my physical display as well?

Use the GetWindowRect function instead of the GetClientRect function.

You also may have a look at the ScreenToClient and the ClientToScreen functions.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM