Reputation:
I have the code
HWND hWndTmp = pDX->m_pDlgWnd->GetSafeHwnd();
hWndTmp = GetDlgItem(hWndTmp, pDX->m_idLastControl);
CWnd *wnd;
wnd = wnd->FromHandle(hWndTmp);
RECT wndRect;
wnd->GetWindowRect(&wndRect);
Which gives me the rectangle around the control described in pDX.
What I would like to do is draw a rectangle around this control a few times to draw the users eyes to it. I have searched for a while on how I could do this but nothing seems to actually work for me.
I've tried this http://msdn.microsoft.com/en-us/library/sx8yykw8.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1
But it tells me "System" cannout be found or is not real.
Is there a simple way given the coordinates to draw a rectangle?
Upvotes: 0
Views: 2493
Reputation: 7309
If you can, go with Moo-Juice's solution. It separates concerns better, IMHO. But if you need a quick fix, try this
CClientDC drawingContext( pDX );
RECT wndRect;
wnd->GetWindowRect(&wndRect);
//Shrink wndRect before if needed
CPoint rectPoints[5];
rectPoints[0] = CPoint( wndRect.left, wndRect.top );
rectPoints[1] = CPoint( wndRect.right, wndRect.top );
rectPoints[2] = CPoint( wndRect.right, wndRect.bottom );
rectPoints[3] = CPoint( wndRect.left, wndRect.bottom );
rectPoints[4] = rectPoints[0];
CPen* oldPen = drawingContext.SelectStockObject(RED_PEN);
drawingContext.Polyline(rectPoints, 5);
drawingContext.SelectObject( oldPen );
If you don't see the rect, try shrinking it a little so it doesn't overlap with the dialog's border.
Upvotes: 0
Reputation: 38825
It may be better to get the screen rectangle of the control and convert it to your Dialog's client, and override OnPaint
for the dialog, and draw the rectangle there (slightly inflated). This will mean you'll definitely see it, and not interfere with the painting of the control itself.
Upvotes: 2