0
votes

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?

2
The link you've provided is for managed C++.Moo-Juice
Thats probably why it didnt work. And I really am not sure of the differences between all the I guess "dialects". I hear MFC, managed, Win32, CLI. I never learned any of this, only the language itself. I have tried to learn it many times but all the tutorials speak about each thing specifically and nothing gives an entire overview.user1311286
If that dialog is yours (i.e. not third party, i.e. you have its code) you should do that kinda stuff by overriding OnPaintdario_ramos
About your confusion with the Windows GUI toolkits, a brief overview: Win32 is the basic, unmanaged api. MFC is an unmanaged, object oriented layer over that. In Windows jargon, unmanaged means not controlled by the .NET virtual machine. Unmanaged code compiles to native assembly code. Managed code compiles to MSIL, which is similar to the Java bytecode, except that this runs on .NET's virtual machine. And finally, managed C++, aka C++/CLI, is a language which extends C++ in order to write wrappers between unmanaged and managed code.dario_ramos
The DlgItem it gets can be of many different types. This code is in a validation function, I want to inform the user that this control cannot be validated by flickering something over the control. EDIT: Thanks for that rundown.user1311286

2 Answers

2
votes

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.

0
votes

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.