ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Définir une sélection à l'aide d'un rectangle de sélection   



L'auteur

Robert Plagnard
France France
Membre Simple
# 0000000031
enregistré le 15/10/2004

http://www.ingelog.fr
PLAGNARD Robert
75015 PARIS
de la société IngéLog
Fiche personnelle


Note des membres
pas de note

Contributions > 05 - API et appels systèmes

Définir une sélection à l'aide d'un rectangle de sélection
# 0000000410
ajouté le 28/02/2007 17:10:58 et modifié le 03/03/2007
consulté 8379 fois
Niveau initié

Version(s) Foxpro :
VFP 9.0
VFP 8.0
VFP 7.0
VFP 6.0
VFP 5.0
VFP 3.0

Description
Je montre comment définir effectivement une sélection dans une fenêtre.
Les pricipaux concepts ont été présentés dans l'article d'hier.
Code source :
*/* SelectionRect.prg
*   Using DrawFocusRect API function to draw a selection rect
*   Run this prg
*   Robert Plagnard feb 25, 2007

#define SM_CYCAPTION            4
#define SM_CXSIZEFRAME         32
#define SM_CYSIZEFRAME         33
#define SM_CYMENU              15

   declare integer DrawFocusRect    in win32api integerstring @
   declare integer GetWindowDC      in win32api integer
   declare integer ReleaseDC        in win32api integerinteger
   declare integer GetSystemMetrics in win32api integer

   public gfrmSelectionRect

   gfrmSelectionRect = CreateObject"CFormSelectionRect" )

   gfrmSelectionRect.Show

define class CFormSelectionRect as Form

   caption = "Click and drag the mouse on the form"

   hidden nXClientOrigin     && X Origin of client zone in window coordinates
   hidden nYClientOrigin     && Y Origin of client zone in window coordinates
   hidden lMouseDown         && true when mouse is down
   hidden lFocusRect         && true when a rect has been drawn
   hidden nXStart            && Start corner X in client coordinates (vfp)
   hidden nYStart            && Start corner Y in client coordiantes (vfp)
   hidden nXEnd              && End corner X in window coordinates
   hidden nYEnd              && End corner Y in window coordinates

   nXEnd = 0
   nYEnd = 0

   procedure Init( lMenu )
      this.nXClientOrigin = GetSystemMetrics( SM_CXSIZEFRAME )
      this.nYClientOrigin = GetSystemMetrics( SM_CYSIZEFRAME )+;
                     GetSystemMetrics( SM_CYCAPTION   )
      if m.lMenu
         this.nYClientOrigin = this.nYClientOrigin + GetSystemMetrics( SM_CYMENU )
      endif
   endproc

   procedure MouseDown( nButton, nShift, nXCoord, nYCoord )
      with this
         .nXStart = m.nXCoord
         .nYStart = m.nYCoord
         .lMouseDown = .T.
      endwith
   endproc

   procedure MouseMove( nButton, nShift, nXCoord, nYCoord )
      with this
         if .lMouseDown then
            .DrawClientFocusRect( .nXStart, .nYStart, nXCoord - .nXStart, nYCoord - .nYStart )
         endif
      endwith
   endproc

   procedure MouseUp( nButton, nShift, nXCoord, nYCoord )
      with this
         .lMouseDown = .F.
         .EndClientFocusRect()
      endwith
   endproc

   hidden procedure DrawClientFocusRect(x,y,w,h)
      local R      && Rectangle
      local hDC    && handle of device context
      with this
         .EndClientFocusRect()
         .nXEnd = .nXClientOrigin + m.x + m.w
         .nYEnd = .nYClientOrigin + m.y + m.h
         R = Rect( .nXStart + .nXClientOrigin, .nYStart + .nYClientOrigin, .nXEnd, .nYEnd )
         hDC = GetWindowDc( thisform.HWnd )
         DrawFocusRect( m.hDC, @R )
         ReleaseDC( thisform.HWnd, m.hDC )
         .lFocusRect = .T.
      endwith
   endproc

   hidden procedure EndClientFocusRect()
      local R      && Rectangle
      local hDC    && handle of device context
      with this
         if .lFocusRect
            R = Rect( .nXStart + .nXClientOrigin, .nYStart + .nYClientOrigin, .nXEnd, .nYEnd)
            hDC = GetWindowDc( thisform.HWnd )
            DrawFocusRect( m.hDC, @R )
            ReleaseDC( thisform.HWnd, m.hDC )
            .lFocusRect = .F.
         endif
      endwith
   endproc

enddefine

function Rectlefttoprightbottom ) as String
   SwapIfNotOrdered( @left, @right  )
   SwapIfNotOrdered( @top,  @bottom )
   return BinToC(m.left,'4RS')+BinToC(m.top'4RS')+BinToC(m.right'4RS')+BinToC(m.bottom'4RS')
endfunc

procedure SwapIfNotOrdered( x, y ) && arguments must be referenced (@)
   local z
   if x > y then
      z = m.x
      x = m.y
      y = m.z
   endif
endproc

Commentaires
le 16/03/2007, laurent.dellacherie2 a écrit :
Bonjour Robert,

J'ai testé ton programme, il donne un bel effet. Cependant j'aimerais allé un peu plus loin avec celà, pour qu'il est une utilité, mais je n'arrive pas à placer mon code pour récupéré les objets de la feuille qui sont présent dans la carré de selection. Pourrais-tu m'aider?

Cordialement,
Laurent

le 17/03/2007, Robert Plagnard a écrit :
Au moment du MousUp tu peux avoir le dernier rectangle dans le repère de coordonnées de VFP avec :
with this
left = .nXStart
top = .nYStart
right = .nXEnd - .nXClientOrigin
bottom = .nYEnd - .nYClientOrigin
SwapIfNotOrdered( @left, @right)
SwapIfNotOrdered( @top, @bottom)
endwith
Ensuite il faut intersecter ce rectangle avec les rectangles circonscrits aux objets que tu veux sélectionner. Et on a le choix entre intersection non vide et inclus dans.


Publicité

Les pubs en cours :

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2024.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3