Drawing a selection rect on a window

Windows specific forum
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Drawing a selection rect on a window

Post 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 ) :?
Windows 7 & PureBasic 4.4
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Run a search here for DrawFocusRect, and you should find what you are looking for. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post 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...
Windows 7 & PureBasic 4.4
Post Reply