Merci
Code : Tout sélectionner
; ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
; Author: Christian
; Modified : Progi1984
; Date: 22. December 2004
;
;
; ToDo:
; *****
; - #PB_Button_Multiline
; - #PB_Button_Toggle
;
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; --> Constants
;#ODS_HOTLIGHT = 40
; --> This is needed for PB's drawing functions to work
 Structure PBDrawingStruct
  Type.l
  WindowHandle.l
  DC.l
  ReleaseProcedure.l
 EndStructure
 Global mydraw.PBDrawingStruct
 mydraw\Type = 1
 ;Global mydraw
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;                      Procedures
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; --> Get the styles of a Gadget
Procedure.l GetStyle(GadgetID.l)
  ProcedureReturn GetWindowLong_(GadgetID, #GWL_STYLE)
EndProcedure
; --> Windowcallback
Procedure myWindowCallback(hwnd, msg, wparam, lparam)
  result = #PB_ProcessPureBasicEvents
  Select msg
   Case #WM_DRAWITEM
     ; -- Get handle and DeviceContext
     *lpdis.DRAWITEMSTRUCT = lparam
     mydraw\WindowHandle = *lpdis\hwndItem
     hDC = GetDC_(mydraw\WindowHandle)
     Width = *lpdis\rcItem\right-*lpdis\rcItem\left
     Height = *lpdis\rcItem\bottom-*lpdis\rcItem\top
   
     ; -- Start with OwnerDrawing
     Select *lpdis\CtlType
      Case #ODT_BUTTON
        ; -- Draw disabled button
        If *lpdis\itemState & #ODS_DISABLED
           If StartDrawing(mydraw)
            Box(0,0,Width, Height,RGB(255,0,0))
           StopDrawing()
           EndIf
        ; -- Draw toogled button
        ElseIf *lpdis\itemState & #ODS_SELECTED
           If StartDrawing(mydraw)
            Box(0,0,Width, Height,RGB(0,255,0))
           StopDrawing()
           EndIf
        Else
           ; -- Draw normal button
           If StartDrawing(mydraw)
            Box(0,0,Width, Height,RGB(0,0,255))
           StopDrawing()
           EndIf
        EndIf
        If *lpdis\itemState & #ODS_FOCUS
            ; -- Draw the FocusRect
            *lpdis\rcItem\left + 3
            *lpdis\rcItem\top + 3
            *lpdis\rcItem\right - 3
            *lpdis\rcItem\bottom - 3
            DrawFocusRect_(hDC, *lpdis\rcItem)
        EndIf
     EndSelect
     result = #True
  EndSelect
  ProcedureReturn result
EndProcedure
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;                      Program
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If OpenWindow(0, 0, 0, 300, 200, "Christians OwnerDrawn Buttons",#PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  SetWindowCallback(@myWindowCallback())
  CheckBoxGadget(0, 50, 50, 200, 50, "Owner Drawn Button 1", #BS_OWNERDRAW)
  CheckBoxGadget(1, 50, 105, 200, 50, "Owner Drawn Button 2", #BS_OWNERDRAW)
;repeat : debug WaitwindowEvent() : forever
   Repeat
     event = WaitWindowEvent()
     Select event
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 0
            Debug "Button 1 pressed!"
            Debug GetGadgetState(0)
           Case 1
            Debug "Button 2 pressed!"
         EndSelect
     EndSelect
   Until event = #PB_Event_CloseWindow
EndIf
End