-
November 26th, 2011, 10:42 PM
#1
GDI+ and Rubberband/Selection Rectangle
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.
-
November 27th, 2011, 06:28 AM
#2
Re: GDI+ and Rubberband/Selection Rectangle
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:
Code:
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);
}
And here is another one
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);
}
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.
Last edited by ovidiucucu; November 27th, 2011 at 08:25 AM.
-
November 27th, 2011, 11:01 PM
#3
Re: GDI+ and Rubberband/Selection Rectangle
I for some reason didn't think you could mix GDI and GDI+
Curiosity then, this cannot be done using GDI+ alone?
-
November 28th, 2011, 03:43 AM
#4
Re: GDI+ and Rubberband/Selection Rectangle
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|