Demande assistance pour un code...

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Shadow
Messages : 1373
Inscription : mer. 04/nov./2015 17:39

Demande assistance pour un code...

Message par Shadow »

Bonsoir,

J'aurais besoin d'une personne pouvant me coder un petit code qui
permet de déplacer et redimensionner des gadgets sur une fenêtre.

Et si possible un groupe (sélection).

Non, ce n'est pas pour faire un éditeur de fenêtre.... enfin si mais pas un visual designer.
J'aimerais faire un programme qui ne face qu'actualiser en temps réel les modification des gadget (position et taille c'est tout).

Le programme se lance et lis le code PB que vous avez coder dans PB, ensuite vous
pourrez déplacer et redimensionner les gadgets (ceux que vous avez coder dans l’éditeur de PB)
puis ensuite le programme actualise votre code avec les nouvelle taille et position.

C'est pas un visual designer à proprement parlé, rien à voir, ya pas de création de gadget
ni personnalisation hormis la position et la taille des gadget, pas de sauvegarde ni chargement, ni annulation ni restauration, ni rien en faite ^^

Alors à quoi ça sert ?
Créer un designer trop dur, celui de PB et même PureForm qui est mieux, ne peuvent pas gérer
correctement certaine choses, PureForm rame plus ya de gadget en plus !

Le plus chiant dans la création d'interface graphique ce sont les positions et les tailles des gadget qu'il faut installer
et donc je veux juste créer un espèce de visualisateur mais qui permet de repositionner et redimensionner des gadget
puis le programme met juste à jour une partie du code, c'est pas dur ça !

J'ai juste la gestion des déplacements et redimensionnement le plus dur que je ne sais pas faire.
Est ce que une personne peut m'aider svp ?

Bhaaa je n'attends rien, sachant qu'il à très peut de chance que une personne veuille m'aider, mais j'aurais essayé !
Processeur: Intel Core I7-4790 - 4 Cœurs - 8 Thread: 3.60 Ghz.
Ram: 32 GB.
Disque: C: SDD 250 GB, D: 3 TB.
Vidéo: NVIDIA GeForce GTX 960: 2 GB DDR5.
Écran: Asus VX248 24 Pouces: 1920 x 1080.
Système: Windows 7 64 Bits.

PureBasic: 5.60 x64 Bits.
Mesa
Messages : 1097
Inscription : mer. 14/sept./2011 16:59

Re: Demande assistance pour un code...

Message par Mesa »

J'avais commencé ce genre de chose...

Code : Tout sélectionner

; Selection rectangle on window by Danilo, 24.11.2003 - german forum

; **********************************************
; * In the code below, 'WF' means Working Form *
; **********************************************

EnableExplicit
;- --- [WORKING FORMS]  INIT (On center of the screen) ---
;{ [WORKING FORMS] Enumeration
Enumeration Anchors
  ;Red anchors to resize the selected gadget
  #WF_AnchorN ;North
  #WF_AnchorE ;East
  #WF_AnchorS ;South
  #WF_AnchorW ;West
  #WF_AnchorNW;NW
  #WF_AnchorNE;NE
  #WF_AnchorSE;SE
  #WF_AnchorSW;SW
EndEnumeration
;}
;{ [WORKING FORMS] Global
;  Structures
Structure WF_SubClassGadget
  hWnd.l
  id.l
  x.l
  y.l
  w.l
  h.l
  oldWndProc.l
  mouseDown.l
  mouseOffX.l
  mouseOffY.l
  selected.b
  ;pt.Point
EndStructure

; Structure RectSelection
;   xi.l
;   yi.l
;   xf.l
;   yf.l
; EndStructure

; Global
Global NewList WF_gadgets.WF_SubClassGadget()
Global NewList WF_Forms()

Global DesktopRect.RECT; Get size of the desktop n°0
Global WF_GadgetsSelected.b=#False  
Global WF_GadgetSelectedID.l=-1, WF_GadgetSelectedXi=-1, WF_GadgetSelectedYi
Global WindowProc_MouseSelectRect.RECT
Global 	MouseX,	MouseY, SelectGadget.b
Global WorkingFormID
Global Global_DrawRectFunction ; 0= draw rect selection with mouse, 1=  draw layout box with mouse (dialog library)

; Anchor management
Global NewList WF_anchors.WF_SubClassGadget()
Global NewList WF_AnchorsSelectedGadgets() 
Global AnchorMouseX.l, AnchorMouseY.l
Global AnchorSize=5 ; Size anchor 
Global AnchorColor=RGB(255,0,0) ; Red anchors 
Global AnchorColorSelectedGadget=RGB(128, 128, 128) ; Grey anchors

;}
;  Shared 
Define WindowProc_MouseSelectStartX, WindowProc_MouseSelectLastX 
Define WindowProc_MouseSelectStartY, WindowProc_MouseSelectLastY 
Define WindowProc_MouseSelect

;{ [WORKING FORMS] Declare
Declare AnchorFocusedGadgetMove(IdGadget)
Declare AnchorFocusedGadgetHide(Value.b)
Declare AnchorSelectedGadgetCreate()
;Declare AnchorSelectedGadgetMove()
Declare AnchorSelectedGadgetHide(Value.b)
;}

; ::Red anchors  = 1 gadget has the focus
; ::Gray anchors = 1 or a group of gadgets are selected

;{- /// Procedure  [WORKING FORMS] Gadgets' Selection = put gray anchors around selected gadgets ///////////////////////
Procedure OnMouseSelection(x,y,width,height) 
  Protected w, h
  
  Select Global_DrawRectFunction
    Case 0
      ;Gadgets' Selection
      ;==================
      ;Only one instance in the callback WindowProc(hWnd,Msg,wParam,lParam)
      ;inside the #WM_LBUTTONUP event, after drawing a selection rectangle
      AnchorFocusedGadgetHide(#True)              ; Hide red anchors
      AnchorSelectedGadgetHide(#True)             ; Hide gray selected anchors
      ForEach WF_gadgets()                        ; Which gadgets selected ?
        If PtInRect_(WindowProc_MouseSelectRect,GadgetY(WF_gadgets()\id) << 32 + GadgetX(WF_gadgets()\id))=#True
          ;BOOL=PtInRect( _In_  const  *lprc.RECT, _In_   pt.POINT); 
          ; : TODO in  PtInRect_, replace GadgetY(WF_gadgets()\id) << 32 + GadgetX(WF_gadgets()\id) by WF_gadgets()\pt
          ; If position X, Y of each gadgets are in the selection rectangle, so the gadget is selected.
          WF_gadgets()\selected = #True
          AnchorSelectedGadgetCreate() ; And creation of its own grey selection anchors
          WF_GadgetsSelected=#True
        EndIf
      Next
      
    Case 1
      ;Draw a layout (Attention: Only with Dialog library !)
      ;=====================================================
      Debug "layout"
      ; : TODO Layout, use a containergadget ?
      
      StartDrawing(WindowOutput(WorkingFormID))
      DrawingMode(#PB_2DDrawing_Outlined )
      x=WindowProc_MouseSelectRect\left
      y=WindowProc_MouseSelectRect\top
      w=WindowProc_MouseSelectRect\right-x
      h=WindowProc_MouseSelectRect\bottom-y
      Box(x,y,w,h,$0000ff)
      DrawingMode(#PB_2DDrawing_Default )
      StopDrawing()
      
      
      
  EndSelect
  
EndProcedure
;}
;{- /// Procedure  [WORKING FORMS] Draw a selection rectangle with the Mouse in the WINDOW CALLBACK ///////////////////////
Procedure DrawMouseRectangleSelection(hWnd)
  ;Draw a selection rectangle in the window hWnd
  ;===============================================
  
  Shared WindowProc_MouseSelectStartX, WindowProc_MouseSelectLastX 
  Shared WindowProc_MouseSelectStartY, WindowProc_MouseSelectLastY 
  ;Shared WindowProc_MouseSelectRect.RECT ; It's a Global variable
  
  Protected hDC
  
  If WindowProc_MouseSelectStartX > WindowProc_MouseSelectLastX 
    WindowProc_MouseSelectRect\left   = WindowProc_MouseSelectLastX 
    WindowProc_MouseSelectRect\right  = WindowProc_MouseSelectStartX 
  Else 
    WindowProc_MouseSelectRect\left   = WindowProc_MouseSelectStartX 
    WindowProc_MouseSelectRect\right  = WindowProc_MouseSelectLastX 
  EndIf 
  If WindowProc_MouseSelectStartY > WindowProc_MouseSelectLastY 
    WindowProc_MouseSelectRect\top    = WindowProc_MouseSelectLastY 
    WindowProc_MouseSelectRect\bottom = WindowProc_MouseSelectStartY 
  Else 
    WindowProc_MouseSelectRect\top    = WindowProc_MouseSelectStartY 
    WindowProc_MouseSelectRect\bottom = WindowProc_MouseSelectLastY 
  EndIf
  
  ;Choose the thickness of the selection rectangle
  ;SystemParametersInfo_(#SPI_SETFOCUSBORDERWIDTH,0,5,0)
  ;SystemParametersInfo_(#SPI_SETFOCUSBORDERHEIGHT,0,2,0)
  hDC = GetDC_(hWnd)
  DrawFocusRect_(hDC,@WindowProc_MouseSelectRect)
  ReleaseDC_(hWnd,hDC)
  
EndProcedure
;}
;{- /// Procedure  [WORKING FORMS] WINDOW CALLBACK (To draw a selection rectangle with the Mouse) //////////////
Procedure WindowProc(hWnd,Msg,wParam,lParam) 
  ; : TODO Use Bindevent()
  ; Needed to draw a rectangle selection
  
  Shared WindowProc_MouseSelect 
  Shared WindowProc_MouseSelectStartX, WindowProc_MouseSelectLastX 
  Shared WindowProc_MouseSelectStartY, WindowProc_MouseSelectLastY 
  ;Shared WindowProc_MouseSelectRect.RECT ;It's a Global variable
  
  Protected winrect.RECT
  
  Select Msg 
      
    Case #WM_LBUTTONDOWN 
      ;If you click on the form (client area) but not on a gadget -> unselect gadgets
      If WF_GadgetsSelected=#True          ; Globaly, no gadgets are selected now  
        WF_GadgetsSelected=#False
        AnchorSelectedGadgetHide(#True) ; hide gray anchors
                                        ;AnchorFocusedGadgetHide(#True)
        ForEach WF_gadgets()            ; unselect gadgets
          WF_gadgets()\selected=#False
        Next
      EndIf
      ; -> Begin to draw a rectangle selection
      WindowProc_MouseSelect  = 1 
      WindowProc_MouseSelectStartX = lParam&$FFFF 
      WindowProc_MouseSelectStartY = (lParam>>16)&$FFFF 
      GetClientRect_(hWnd,winrect)      ; Size of the client area
      MapWindowPoints_(hWnd,0,winrect,2); 2 points are converted in screen coordinates 
      SetCapture_(hWnd)                 ; Capture the mouse
      ClipCursor_(winrect)              ; Confines the cursor to the client area
      ProcedureReturn 0
      
    Case #WM_MOUSEMOVE 
      ; Let's draw the rectangle selection
      If WindowProc_MouseSelect > 0 And wParam & #MK_LBUTTON 
        If WindowProc_MouseSelect > 1
          DrawMouseRectangleSelection(hWnd)
        Else
          WindowProc_MouseSelect + 1
        EndIf
        WindowProc_MouseSelectLastX = lParam&$FFFF 
        WindowProc_MouseSelectLastY = (lParam>>16)&$FFFF 
        DrawMouseRectangleSelection(hWnd)
        ;       SetCapture_(hWnd)
      EndIf 
      ProcedureReturn 0
      
      
    Case #WM_LBUTTONUP
      ; -> Draw the rectangle selection and select gadgets inside the rectangle
      If WindowProc_MouseSelect > 1 
        DrawMouseRectangleSelection(hWnd) ; Draw the rectangle selection
                                          ; Select gadget = add gray anchors on each gadget selected
        If WindowProc_MouseSelectRect\left <> WindowProc_MouseSelectRect\right And WindowProc_MouseSelectRect\top <> WindowProc_MouseSelectRect\bottom 
          OnMouseSelection(WindowProc_MouseSelectRect\left,WindowProc_MouseSelectRect\top,WindowProc_MouseSelectRect\right-WindowProc_MouseSelectRect\left,WindowProc_MouseSelectRect\bottom-WindowProc_MouseSelectRect\top)
          ;SetCapture_(0)
        EndIf 
        
      EndIf 
      ClipCursor_(0) ;If this parameter is NULL, the cursor is free to move anywhere on the screen. 
      WindowProc_MouseSelect = 0 
      ReleaseCapture_()
      ProcedureReturn 0
      
      ; 		Case #WM_RBUTTONUP
      
  EndSelect 
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure
;}
;{ Misc
; Procedure IsMouseOver(hWnd) 
; 		GetWindowRect_(hWnd,r.RECT) 
; 		GetCursorPos_(p.POINT) 
; 		Result = PtInRect_(r,p\y << 32 + p\x) 
; 		ProcedureReturn Result
; EndProcedure

; Procedure change_curseur(type)
; IDC_APPSTARTING : curseur standard + sablier
; IDC_ARROW : curseur standard
; IDC_CROSS : croix
; IDC_IBEAM : texte
; IDC_ICON : Seulement Windows NT : Icône vide
; IDC_NO : Cercle barré (sens interdit)
; IDC_SIZE : Seulement Windows NT: 4 flèches : nord sud est ouest
; IDC_SIZEALL : Même chose que IDC_SIZE
; IDC_SIZENESW : 2 flèches : nordest et sudouest
; IDC_SIZENS : 2 flèches : nord et sud
; IDC_SIZENWSE : 2 flèches : nordouest et sudest
; IDC_SIZEWE : 2 flèches : ouest et sud
; IDC_UPARROW : 1 flèche : nord
; IDC_WAIT : Sablier 
;     hcur=LoadCursor_(0, type )
;     SetCursor_(hcur );
; EndProcedure
;}

;{- /// Procedure  [WORKING FORMS] GADGETS CALLBACK -> Move gadgets ///////////////////////
Procedure GadgetCallback(hWnd,Msg,wParam,lParam)
  Protected x, y
  
  ;Each gadgets added on this form use this call back, see below the Procedure AddGadgetOnWorkingForm(hGadget)
  ;Debug hWnd
  ;Debug lParam
  ; Quel gadget ?
  ;Handle = RealChildWindowFromPoint_(WindowID(#Main), *Pointer\pt\x + *Pointer\pt\y << 32)
  ;Debug Handle
  Select Msg
    Case #WM_SETCURSOR
      ;Display Handle and gadgetID in the titlebar -> for debugging
      SetWindowTitle(WF_Forms(),"Handle= "+Str(wParam)+"   , "+"ID= "+Str(GetDlgCtrlID_(wParam)))
      
    Case #WM_LBUTTONDOWN
      ;{ info
      ;wParam:Indicates whether various virtual keys are down. ctrl, shift rbutton, mbutton
      ;lParam:coordonnate x,y
      ;lParam:The low-order word specifies the x-coordinate of the cursor. 
      ;       The high-order word specifies the y-coordinate of the cursor. 
      ;       The coordinates are relative to the upper-left corner of the client area.
      ;}
      ; If you click on a gadget -> prepare to move it or resize it
      AnchorFocusedGadgetHide(#True)                 ; Hide red anchors
      AnchorSelectedGadgetHide(#True)                ; Hide gray anchors
      
      ForEach WF_gadgets() ; In the list containing all gadgets on the working form
        If WF_gadgets()\hWnd = hWnd        ; Find the gadget in the list of gadgets added on the working form
          
          ; Coordonnate or the cursor in the gadget
          WF_gadgets()\mouseOffX = lParam & $FFFF  
          WF_gadgets()\mouseOffY = (lParam>>16) & $FFFF
          
          WF_gadgets()\mouseDown = 1       ; The mouse is down on it
          WF_gadgets()\selected=#False     ; It's not selected
          SelectGadget = #True             ; But a single gadget has the focus
          
          ;Needed to move the gadget
          WF_GadgetSelectedID=WF_gadgets()\id
          WF_GadgetSelectedXi=MouseX
          WF_GadgetSelectedYi=MouseY
          
          SetFocus_(hWnd)               ; The gadget get the focus
          SetCursor_(LoadCursor_(0,#IDC_SIZEALL)) ; Change the cursor into a double arrow
          ProcedureReturn 0
        Else
          SelectGadget = #False         ; If no gadget found then no gadget has the focus
        EndIf  
        
      Next
      
    Case #WM_MOUSEMOVE
      ; If the cursor is over a gadget without clicking -> change the cursor into a cross
      If wParam=0 ; No click
        ForEach WF_gadgets()
          If WF_gadgets()\hWnd = hWnd  ; Find the gadget
                                       ;SetFocus_(hWnd)
            SetCursor_(LoadCursor_(0,#IDC_CROSS)) ; Change the cursor          
            ProcedureReturn 0
          EndIf
        Next
        
        ; If the cursor is over a gadget with Left click -> Move gadget(s)  
      ElseIf wParam & #MK_LBUTTON
        ;{ info
        ; MK_CONTROL:The CTRL key is down.
        ; MK_LBUTTON:The left mouse button is down.
        ; MK_MBUTTON:The middle mouse button is down.
        ; MK_RBUTTON:The right mouse button is down.
        ; MK_SHIFT:The SHIFT key is down.
        ; Obtain the gadget id with ;debug GetWindowLongPtr_(hWnd,#GWL_ID)
        ;}
        ; Move a selection of gadgets
        ForEach WF_gadgets()
          If WF_gadgets()\hWnd = hWnd And WF_gadgets()\mouseDown ; Find the gadget under the mouse
            x = MouseX - WF_gadgets()\mouseOffX                  ; x = mouseX in the client area - mouseX in the gadget
            y = MouseY - WF_gadgets()\mouseOffY
            
            ; Truncated gadget is not allowed
            If x < 0 : x = 0 : EndIf  
            If y < 0 : y = 0 : EndIf
            If x + WF_gadgets()\w  > WindowWidth(WorkingFormID) 
              x = WindowWidth(WorkingFormID) - WF_gadgets()\w
            EndIf
            If y + WF_gadgets()\h > WindowHeight(WorkingFormID)
              y = WindowHeight(WorkingFormID) -  WF_gadgets()\h
            EndIf
            
            ; Move the gadget under the mouse
            ResizeGadget(WF_GadgetSelectedID,x,y,#PB_Ignore,#PB_Ignore)
            ; : TODO Don't show truncated selected gadgets
            ForEach WF_gadgets() ; and move all selected gadget
              If WF_gadgets()\selected=#True
                ResizeGadget(WF_gadgets()\id, WF_gadgets()\x + (MouseX-WF_GadgetSelectedXi) , WF_gadgets()\y + (MouseY-WF_GadgetSelectedYi), #PB_Ignore, #PB_Ignore)
              EndIf
            Next
            
            SetCursor_(LoadCursor_(0,#IDC_SIZEALL)) ; Change the cursor into a double arrow during the move
            SetCapture_(hWnd)                       ; Needed to move a gadget over an other
            
            ProcedureReturn 0
          EndIf
        Next
      EndIf      
      
      
    Case #WM_LBUTTONUP
      ; If the left click is UP -> Move red or grey anchors and update the structure of the list WF_gadgets()
      If WF_GadgetsSelected=#False ;#True = 1 gadget
        AnchorFocusedGadgetHide(#False)
        ForEach WF_gadgets()
          If WF_gadgets()\hWnd = hWnd
            WF_gadgets()\selected =#False
            WF_gadgets()\mouseDown = 0 
            WF_gadgets()\x = GadgetX(WF_gadgets()\id)
            WF_gadgets()\y = GadgetY(WF_gadgets()\id)
            AnchorFocusedGadgetMove(WF_GadgetSelectedID)
          EndIf 
        Next
        
      Else
        AnchorSelectedGadgetHide(#True)
        ForEach WF_gadgets()
          If WF_gadgets()\hWnd = hWnd
            WF_gadgets()\selected =#True
            WF_gadgets()\x = GadgetX(WF_gadgets()\id)
            WF_gadgets()\y = GadgetY(WF_gadgets()\id)
          Else
            WF_gadgets()\x = GadgetX(WF_gadgets()\id)
            WF_gadgets()\y = GadgetY(WF_gadgets()\id)
          EndIf
          AnchorSelectedGadgetCreate()
        Next
      EndIf
      
      SelectGadget=#False
      
      ;SetCapture_(0)
      ReleaseCapture_()
      ProcedureReturn 0
  EndSelect
  
  ForEach WF_gadgets()
    If WF_gadgets()\hWnd = hWnd
      ProcedureReturn CallWindowProc_(WF_gadgets()\oldWndProc,hWnd,Msg,wParam,lParam)
    EndIf
  Next
EndProcedure
;}
;{- /// Procedure  [WORKING FORMS] Prepare Gadgets to the gadget callback ////////
Procedure AddGadgetOnWorkingForm(hGadget)
  Protected id, hWnd
  
  If IsGadget(hGadget)
    hWnd = GadgetID(hGadget) ; for #PB_Any
  Else
    hWnd = hGadget
  EndIf
  If hWnd
    LastElement(WF_gadgets())
    AddElement(WF_gadgets())
    WF_gadgets()\hWnd = hWnd
    id=GetDlgCtrlID_(hWnd)
    WF_gadgets()\id=id
    ; Sets a new address for the "gadget-window" callback procedure
    WF_gadgets()\oldWndProc = SetWindowLongPtr_(hWnd,#GWLP_WNDPROC,@GadgetCallback())
    WF_gadgets()\x=GadgetX(id)
    WF_gadgets()\y=GadgetY(id)
    WF_gadgets()\w=GadgetWidth(id)
    WF_gadgets()\h=GadgetHeight(id)
  EndIf
  ProcedureReturn hGadget
EndProcedure
;}

;{- //// 5 procedures /////////////  [FORMS] ANCHORS MANAGEMENT  (grey and red anchors) ///////////////////////
; Global AnchorSize=5, AnchorColor=RGB(255,0,0), AnchorColorSelectedGadget=RGB(128, 128, 128)

Procedure AnchorSelectedGadgetCreate()
  ; Create and show 4 grey anchors around each selected gadget
  ; Those anchors are not active, they just indicate a selected gadget
  ; Each anchor is a canvasgadget
  Protected Left.i, Top.i, Width.i, Height.i, i, id
  
  If WF_gadgets()\selected=#True
    WF_GadgetsSelected=#True
    Left=GadgetX(WF_gadgets()\id)
    Top=GadgetY(WF_gadgets()\id)
    Width=GadgetWidth(WF_gadgets()\id)
    Height=GadgetHeight(WF_gadgets()\id) 
    For i= 0 To 3
      id=CanvasGadget(#PB_Any, 0, 0, AnchorSize, AnchorSize)
      AddElement(WF_AnchorsSelectedGadgets())
      WF_AnchorsSelectedGadgets()=id
      If StartDrawing(CanvasOutput(id))
        Box(0, 0, AnchorSize, AnchorSize, AnchorColorSelectedGadget)
        StopDrawing()
      EndIf
      Select i
        Case 0
          ResizeGadget(id, (Left+Width/2), Top-AnchorSize, AnchorSize, AnchorSize)
        Case 1
          ResizeGadget(id, Left+Width/2, Top+Height+AnchorSize/4, AnchorSize,AnchorSize) 
        Case 2
          ResizeGadget(id, Left+Width, Top+(Height-AnchorSize)/2, AnchorSize, AnchorSize)  
        Case 3 
          ResizeGadget(id, Left-AnchorSize, Top+(Height-AnchorSize)/2, AnchorSize, AnchorSize)          
      EndSelect      
    Next i   
  EndIf 
EndProcedure
Procedure AnchorSelectedGadgetHide(Value.b)
  ;Attention : Hide and DESTROY grey AnchorsSelected
  ;Note : Value.b is not really necessary for now but maybe later...
  ForEach WF_AnchorsSelectedGadgets()
    HideGadget(WF_AnchorsSelectedGadgets(),Value)
    FreeGadget(WF_AnchorsSelectedGadgets())
  Next
  
  ClearList(WF_AnchorsSelectedGadgets()) 
EndProcedure

Procedure AnchorFocusedGadgetCreate()
  ; Create and show 8 red anchors around the focused gadget
  ; Each anchor is a canvasgadget
  
  Protected i, hWnd 
  
  For i= 0 To 7
    hWnd=CanvasGadget(#WF_AnchorN+i, 0, 0, AnchorSize, AnchorSize)
    AddElement(WF_anchors())
    WF_anchors()\hWnd       = hWnd
    WF_anchors()\id=GetDlgCtrlID_(hWnd)
    If StartDrawing(CanvasOutput(#WF_AnchorN+i))
      Box(0, 0, AnchorSize, AnchorSize, AnchorColor)
      StopDrawing()
    EndIf   
  Next i
  ;Cursors
  SetGadgetAttribute(#WF_AnchorN,#PB_Canvas_Cursor,#PB_Cursor_UpDown)
  SetGadgetAttribute(#WF_AnchorS,#PB_Canvas_Cursor,#PB_Cursor_UpDown)
  SetGadgetAttribute(#WF_AnchorW,#PB_Canvas_Cursor,#PB_Cursor_LeftRight)
  SetGadgetAttribute(#WF_AnchorE,#PB_Canvas_Cursor,#PB_Cursor_LeftRight)
  SetGadgetAttribute(#WF_AnchorNW,#PB_Canvas_Cursor,#PB_Cursor_LeftDownRightUp)
  SetGadgetAttribute(#WF_AnchorNE,#PB_Canvas_Cursor,#PB_Cursor_LeftUpRightDown)
  SetGadgetAttribute(#WF_AnchorSW,#PB_Canvas_Cursor,#PB_Cursor_LeftDownRightUp)
  SetGadgetAttribute(#WF_AnchorSE,#PB_Canvas_Cursor,#PB_Cursor_LeftUpRightDown)
  
EndProcedure
Procedure AnchorFocusedGadgetHide(Value.b)
  ; Hide or show 8 red anchors around the focused gadget
  ; Each anchor is a canvasgadget
  HideGadget(#WF_AnchorN, Value)
  HideGadget(#WF_AnchorE, Value)
  HideGadget(#WF_AnchorS, Value) 
  HideGadget(#WF_AnchorW, Value)
  HideGadget(#WF_AnchorNW, Value)
  HideGadget(#WF_AnchorNE, Value)
  HideGadget(#WF_AnchorSE, Value) 
  HideGadget(#WF_AnchorSW, Value)
  ;AnchorHide=Value
EndProcedure
Procedure AnchorFocusedGadgetMove(IdGadget)
  ; Movew 8 red anchors around the focused gadget
  ; Each anchor is a canvasgadget
  Protected Left.i, Top.i, Width.i, Height.i
  Left=GadgetX(IdGadget)
  Top=GadgetY(IdGadget)
  Width=GadgetWidth(IdGadget)
  Height=GadgetHeight(IdGadget)
  
  ResizeGadget(#WF_AnchorN, (Left+Width/2), Top-AnchorSize, AnchorSize, AnchorSize)
  ResizeGadget(#WF_AnchorS, Left+Width/2, Top+Height+AnchorSize/4, AnchorSize,AnchorSize)
  ResizeGadget(#WF_AnchorE, Left+Width, Top+(Height-AnchorSize)/2, AnchorSize, AnchorSize)
  ResizeGadget(#WF_AnchorW, Left-AnchorSize, Top+(Height-AnchorSize)/2, AnchorSize, AnchorSize)
  ResizeGadget(#WF_AnchorNE, Left-AnchorSize, Top-AnchorSize, AnchorSize, AnchorSize)
  ResizeGadget(#WF_AnchorSE, Left+Width, Top+Height, AnchorSize,AnchorSize)
  ResizeGadget(#WF_AnchorSW, Left-AnchorSize, Top+Height, AnchorSize, AnchorSize)
  ResizeGadget(#WF_AnchorNW, Left+Width, Top-AnchorSize, AnchorSize, AnchorSize)
  
EndProcedure
;} End Anchors

;{- /// Procedure  [WORKING FORMS] ; Get size of the desktop n°0 //////
Procedure GetDesktopRect()
  
  If  ExamineDesktops()
    DesktopRect\bottom=DesktopHeight(0)
    DesktopRect\left= 0
    DesktopRect\right=DesktopWidth(0)
    DesktopRect\top= 0
    ProcedureReturn 1
  EndIf
  
EndProcedure
;}



Define choice, selection, ButtonCreate, TextCreate
Define ok1
Define event,  NumeroFenetre
Define anchorcatched, GadgetH, MouseYMove, GadgetW, MouseXMove

;//////////// Choice  //////////////
;===== test =======
choice=OpenWindow(#PB_Any,620,200,300,300,"Choice",#PB_Window_SystemMenu)
selection=OptionGadget(#PB_Any,0,0,50,30,"Sel")
ButtonCreate=OptionGadget(#PB_Any,60,0,100,30,"gadget")
TextCreate=OptionGadget(#PB_Any,180,0,60,30,"hBox")
SetGadgetState(selection, 1)

;//////////////////////////////////////////////////////////////////////

; [WORKING FORMS] Add a new form
WorkingFormID= OpenWindow(#PB_Any,200,200,400,300,"test",#PB_Window_SystemMenu);|#PB_Window_ScreenCentered
AddElement(WF_Forms())
WF_Forms()=WorkingFormID

; [WORKING FORMS] Create anchors and hide them
AnchorFocusedGadgetCreate()
AnchorFocusedGadgetHide(#True)

; [WORKING FORMS] Set Window Callback
SetWindowCallback(@WindowProc(),WF_Forms()); 
GetDesktopRect()



; [WORKING FORMS] Add gadgets
ok1=AddGadgetOnWorkingForm(ButtonGadget  (#PB_Any,10, 10,100,20,"Button"))
AddGadgetOnWorkingForm(TextGadget  (#PB_Any,10, 230,100,20,"text",#SS_NOTIFY))
; AddGadgetOnWorkingForm(TextGadget  (#PB_Any,10, 230,100,20,"text"))
CreateImage(0,200,40)
AddGadgetOnWorkingForm(ImageGadget(#PB_Any,10, 40,100,20,ImageID(0)));,"Checkbox"
                                                                     ;   AddGadgetOnWorkingForm(ComboBoxGadget(#PB_Any,10, 80,100,150))
                                                                     ;   AddGadgetOnWorkingForm(SpinGadget    (#PB_Any,10,120,100,20,0,100))
                                                                     ;   AddGadgetOnWorkingForm(StringGadget  (#PB_Any,10,160,100,20,"Stringfield"))
                                                                     ;   AddGadgetOnWorkingForm(TrackBarGadget(#PB_Any,10,200,100,20,0,100))
                                                                     ;ne marchent pas:
                                                                     ;ExplorerComboGadget
                                                                     ;ExplorerListGadget
                                                                     ;FrameGadget
                                                                     ;IPAddressGadget ?
                                                                     ;ImageGadget
                                                                     ;
                                                                     ;




;- --- [WORKING FORMS] Loop  
Repeat 
  
  ; [WORKING FORMS] MouseX MouseY (Mouse location)
  MouseX = WindowMouseX(WF_Forms())
  MouseY = WindowMouseY(WF_Forms())
  
  ; [WORKING FORMS] Events (On the Forms and on Red Anchors)
  event= WaitWindowEvent(10)
  NumeroFenetre = EventWindow();Le numéro de la fenêtre dans laquelle s'est produit l'évènement.
  
  Select NumeroFenetre 
    Case WorkingFormID     
      Select event
          ;{ Events On the Form (Not used yet)
          ;Case #PB_Event_RightClick ; On the Working Form but not on a Gadget
          ;Debug "#PB_Event_RightClick"
          ;         If WF_GadgetsSelected=#True
          ;           ;popmenu align gadgets
          ;         Else
          ;           ;other popmenu 
          ;         EndIf
          
          ;Case #PB_Event_LeftDoubleClick; On the Working Form but not on a Gadget 
          ;debug "#PB_Event_LeftDoubleClick"
          
          ;} 
          ;{ Events On Red Anchors
        Case #PB_Event_Gadget
          Select EventGadget()
              ;{ ANCHOR MANAGEMENT 
              ;-------------- ANCHOR MANAGEMENT (Red/Focus)
              ;ANCHOR S
            Case #WF_AnchorN 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  GadgetH=GadgetHeight(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseYMove=WindowMouseY(WF_Forms())                 
                    GadgetH=GadgetH+(GadgetY(WF_GadgetSelectedID)-MouseYMove)             
                    ResizeGadget(WF_GadgetSelectedID,#PB_Ignore,MouseYMove,#PB_Ignore,GadgetH)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect
              
              ;ANCHOR S
            Case #WF_AnchorS 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  GadgetH=GadgetHeight(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseYMove=WindowMouseY(WF_Forms())
                    GadgetH=MouseYMove-GadgetY(WF_GadgetSelectedID)
                    ResizeGadget(WF_GadgetSelectedID,#PB_Ignore,#PB_Ignore,#PB_Ignore,GadgetH)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect
              
              ;ANCHOR W
            Case #WF_AnchorW 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  GadgetW=GadgetWidth(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseXMove=WindowMouseX(WF_Forms())
                    GadgetW=GadgetW+(GadgetX(WF_GadgetSelectedID)-MouseXMove)
                    ResizeGadget(WF_GadgetSelectedID,MouseXMove,#PB_Ignore,GadgetW,#PB_Ignore)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect      
              
              ;ANCHOR E
            Case #WF_AnchorE 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  GadgetW=GadgetWidth(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseXMove=WindowMouseX(WF_Forms())
                    GadgetW=MouseXMove-GadgetX(WF_GadgetSelectedID)
                    ResizeGadget(WF_GadgetSelectedID,#PB_Ignore,#PB_Ignore,GadgetW,#PB_Ignore)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect  
              
              ;ANCHOR NE
            Case #WF_AnchorNE 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  GadgetW=GadgetWidth(WF_GadgetSelectedID)
                  GadgetH=GadgetHeight(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseXMove=WindowMouseX(WF_Forms())
                    MouseYMove=WindowMouseY(WF_Forms())
                    GadgetH=GadgetH+(GadgetY(WF_GadgetSelectedID)-MouseYMove)
                    GadgetW=GadgetW+(GadgetX(WF_GadgetSelectedID)-MouseXMove)               
                    ResizeGadget(WF_GadgetSelectedID,MouseXMove,MouseYMove,GadgetW,GadgetH)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect  
              
              ;ANCHOR SW
            Case #WF_AnchorSW 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  GadgetW=GadgetWidth(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseXMove=WindowMouseX(WF_Forms())
                    MouseYMove=WindowMouseY(WF_Forms())
                    GadgetH=MouseYMove-GadgetY(WF_GadgetSelectedID)
                    GadgetW=GadgetW+(GadgetX(WF_GadgetSelectedID)-MouseXMove)               
                    ResizeGadget(WF_GadgetSelectedID,MouseXMove,#PB_Ignore,GadgetW,GadgetH)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect                               
              
              ;ANCHOR SE
            Case #WF_AnchorSE 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  ;GadgetW=GadgetWidth(WF_GadgetSelectedID)
                  GadgetW=GadgetWidth(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseXMove=WindowMouseX(WF_Forms())
                    MouseYMove=WindowMouseY(WF_Forms())
                    GadgetH=MouseYMove-GadgetY(WF_GadgetSelectedID)
                    GadgetW=MouseXMove-GadgetX(WF_GadgetSelectedID)               
                    ResizeGadget(WF_GadgetSelectedID,#PB_Ignore,#PB_Ignore,GadgetW,GadgetH)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect                               
              
              ;ANCHOR NW
            Case #WF_AnchorNW 
              Select EventType() 
                Case #PB_EventType_MouseEnter
                  anchorcatched=#False
                  
                Case #PB_EventType_LeftButtonDown
                  GadgetH=GadgetHeight(WF_GadgetSelectedID)
                  anchorcatched=#True
                  
                Case #PB_EventType_MouseMove
                  If anchorcatched=#True
                    MouseXMove=WindowMouseX(WF_Forms())
                    MouseYMove=WindowMouseY(WF_Forms())
                    GadgetH=GadgetH+(GadgetY(WF_GadgetSelectedID)-MouseYMove)
                    GadgetW=MouseXMove-GadgetX(WF_GadgetSelectedID)               
                    ResizeGadget(WF_GadgetSelectedID,#PB_Ignore,MouseYMove,GadgetW,GadgetH)
                    AnchorFocusedGadgetMove(WF_GadgetSelectedID)
                  EndIf
              EndSelect                               
              
          EndSelect  ; End Case #PB_Event_Gadget
                     ;} END Anchor Management (Red/Focus)
                     ;}   
      EndSelect      ; End Select event
      
    Case choice
      ;{ 
      ;-------------------   CHOICE WINDOW   ------------------------
      Select event 
          
          ;     Case #PB_Event_RightClick 
          ;               ;Debug "#PB_Event_RightClick"
          ;       ;         If WF_GadgetsSelected=#True
          ;       ;           ;popmenu pour aligner les gadgets
          ;       ;         Else
          ;       ;           ;popmenu normal
          ;       ;         EndIf
          ;       
          ;     Case #PB_Event_LeftDoubleClick 
          ;       ;;debug "#PB_Event_LeftDoubleClick"
          
          
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
              ;---sel---------------------    
            Case selection
              Debug "sel"
              
              Global_DrawRectFunction=0
              
            Case ButtonCreate
              Debug"butt"
              
              
            Case TextCreate
              Debug "layout"
              Global_DrawRectFunction=1
              
          EndSelect ;eventgadget
      EndSelect     ;event
                    ;}
      
  EndSelect ; windows
Until event=#PB_Event_CloseWindow

; win message
; https://msdn.microsoft.com/en-us/library/windows/desktop/ms644927%28v=vs.85%29.aspx#system_defined
Mesa.
Mesa
Messages : 1097
Inscription : mer. 14/sept./2011 16:59

Re: Demande assistance pour un code...

Message par Mesa »

Tu peux télécharger ce zip qui contient plein d e codes utiles.

http://frazier.wood.free.fr/pb/Pure%20D ... signer.zip



M.
Shadow
Messages : 1373
Inscription : mer. 04/nov./2015 17:39

Re: Demande assistance pour un code...

Message par Shadow »

Merci Mesa :)
Processeur: Intel Core I7-4790 - 4 Cœurs - 8 Thread: 3.60 Ghz.
Ram: 32 GB.
Disque: C: SDD 250 GB, D: 3 TB.
Vidéo: NVIDIA GeForce GTX 960: 2 GB DDR5.
Écran: Asus VX248 24 Pouces: 1920 x 1080.
Système: Windows 7 64 Bits.

PureBasic: 5.60 x64 Bits.
Avatar de l’utilisateur
Guillot
Messages : 529
Inscription : jeu. 25/juin/2015 16:18

Re: Demande assistance pour un code...

Message par Guillot »

tiens
ça peu peut etre te servir
https://www.purebasic.fr/french/viewtop ... =6&t=16201

(j'avais une version plus recente, mais j'arrive pas à mettre la main dessus...)
Shadow
Messages : 1373
Inscription : mer. 04/nov./2015 17:39

Re: Demande assistance pour un code...

Message par Shadow »

Ah oui, pas grand chose à voir mais très utile quand même, je prends merci !
Processeur: Intel Core I7-4790 - 4 Cœurs - 8 Thread: 3.60 Ghz.
Ram: 32 GB.
Disque: C: SDD 250 GB, D: 3 TB.
Vidéo: NVIDIA GeForce GTX 960: 2 GB DDR5.
Écran: Asus VX248 24 Pouces: 1920 x 1080.
Système: Windows 7 64 Bits.

PureBasic: 5.60 x64 Bits.
Répondre