Page 1 of 1

Drawing a selection rect on a window

Posted: Tue Dec 04, 2007 9:56 pm
by milan1612
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 :oops: )

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 
Could anybody (api gurus?) help me?
(please don't be rude to an api noob like me ) :?

Posted: Tue Dec 04, 2007 10:41 pm
by Sparkie
Run a search here for DrawFocusRect, and you should find what you are looking for. :)

Posted: Wed Dec 05, 2007 9:45 am
by milan1612
Thanks! I didn't know what to search for :lol:
http://www.purebasic.fr/english/viewtop ... wfocusrect
This is exactly what I wanted...