Drawing a selection rect on a window
Posted: Tue Dec 04, 2007 9:56 pm
Hi mates,
I'm totally stuck at the moment
I want to draw a simple selection rectangle on a window:
on click on the form save mouse position, on mousemove draw a
rectangle from old position to the new mouse position.
This is what I've already achieved (if you can call it like that
)
Could anybody (api gurus?) help me?
(please don't be rude to an api noob like me )
I'm totally stuck at the moment
I want to draw a simple selection rectangle on a window:
on click on the form save mouse position, on mousemove draw a
rectangle from old position to the new mouse position.
This is what I've already achieved (if you can call it like that
Code: Select all
Procedure FO_CallBack(WindowID, Message, wParam, lParam)
Protected hdc
Protected hPen, hOldPen, hBrush, hOldBrush, nDrawMode
Protected rect.RECT
Select Message
Case #WM_LBUTTONDOWN
GetWindowRect_(WindowID(Form), @pos)
WinX = pos\left
WinY = pos\top
Case #WM_MOUSEMOVE
If wParam = #MK_LBUTTON
hdc = GetWindowDC_(WindowID(Form))
hPen = CreatePen_(#PS_DASH, 0, 0)
hOldPen = SelectObject_(hdc, hPen)
hBrush = GetStockObject_(#NULL_BRUSH)
hOldBrush = SelectObject_(hdc, hBrush)
nDrawMode = SetROP2_(hdc, #R2_NOT)
Rectangle_(hdc, WinX, WinY, LoWord(lParam), HiWord(lParam))
SetROP2_(hdc, nDrawMode)
SelectObject_(hdc, hOldBrush)
SelectObject_(hdc, hOldPen)
ReleaseDC_(WindowID(Form), hdc)
DeleteObject_(hPen)
EndIf
Case #WM_ERASEBKGND
ProcedureReturn 0
EndSelect
ProcedureReturn CallWindowProc_(OldProc, WindowID, Message, wParam, lParam)
EndProcedure (please don't be rude to an api noob like me )