I cannot find how to draw a simple selection rectangle (rubberband) using
GDI+.
This should be a simple thing, but I'm beginning to wonder if it is even possible.
Printable View
I cannot find how to draw a simple selection rectangle (rubberband) using
GDI+.
This should be a simple thing, but I'm beginning to wonder if it is even possible.
It's so simple then is not needed GDI+ for doing it (although you are using GDI+ for other stuff).
Here is an example using "classic" GDI functions:
And here is another oneCode:void _DrawRubberBand(HWND hWnd, RECT& rc)
{
HDC hDC = ::GetDC(hWnd);
HBRUSH hBrush = (HBRUSH)::GetStockObject(NULL_BRUSH);
HBRUSH hOldBrush = (HBRUSH)::SelectObject(hDC, hBrush);
::SetROP2(hDC, R2_NOT);
::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
::SelectObject(hDC, hOldBrush);
::ReleaseDC(hWnd, hDC);
}
Of course, you have to further handle WM_LBUTTONDOWN, WM_MOUSEMOVE and WM_LBUTTONUP messages, in order to draw a selection rectangle on user action.Code:void _DrawRubberBand(HWND hWnd, int left, int top, int right, int bottom)
{
HDC hDC = ::GetDC(hWnd);
::SetROP2(hDC, R2_NOT);
::MoveToEx(hDC, left, top, NULL);
POINT pt[4] = {{right, top}, {right, bottom}, {left, bottom}, {left, top}};
::PolylineTo(hDC, pt, 4);
::ReleaseDC(hWnd, hDC);
}
I for some reason didn't think you could mix GDI and GDI+
Curiosity then, this cannot be done using GDI+ alone?
Like any other library, GDI+ could not implement everything our muscles want. ;)
If something is missing in there, then one ultimate solution is to use native Windows API.