Drei Möglichkeiten eigene Gadgets zu erstellen

Für allgemeine Fragen zur Programmierung mit PureBasic.
Benutzeravatar
mk-soft
Beiträge: 3695
Registriert: 24.11.2004 13:12
Wohnort: Germany

Drei Möglichkeiten eigene Gadgets zu erstellen

Beitrag von mk-soft »

Ich habe mal drei Methoden zum erstellen von eigene Gadgets geschrieben.

1. Standardaufruf
2. Verwendung von Modulen
3. Objektorientiert

Für das dritte Bespiel wird noch die Include 'Modul_BaseClassSmall.pb' benötigt um vereinfacht Objekte zu erstellen.
Diese findet ihr hier: https://www.purebasic.fr/english/viewto ... 12&t=64305

Mal schauen welche ihr favorisiert.
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
Benutzeravatar
mk-soft
Beiträge: 3695
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: Drei Möglichkeiten eigene Gadgets zu erstellen

Beitrag von mk-soft »

Standard

Code: Alles auswählen

;-TOP
; Comment : ButtonColorGadget Number 42 ;)
; Author  : mk-soft
; Version : v1.03
; Create  : 30.04.2019

; OS      : All

EnableExplicit

; *****************************************************************************

Structure udtGadgetBase ; and Resources for easy free gadget
  Gadget.i
  Image.i
  Image2.i
EndStructure

Structure udtButtonColorGadget Extends udtGadgetBase
  Text.s
  FontID.i
  FrontColor.i
  BackColor.i
  LineColor.i
EndStructure

; ----

Procedure DrawButtonColorGadget(*data.udtButtonColorGadget)
  Protected Width, Height
  
  With *data
    Width = GadgetWidth(\Gadget)
    Height = GadgetHeight(\Gadget)
    If ImageWidth(\Image) <> Width Or ImageHeight(\Image) <> Height
      FreeImage(\Image)
      \Image = CreateImage(#PB_Any, Width, Height, 32)
    EndIf
    If StartDrawing(ImageOutput(\Image))
      Box(0, 0, Width, Height, \LineColor)
      Box(1, 1, Width - 2 , Height - 2, \BackColor)
      DrawingFont(\FontID)
      DrawText(Width / 2 - TextWidth(\Text) /2, Height / 2 - TextHeight(\Text) / 2, \Text, \FrontColor, \BackColor)
      StopDrawing()
      SetGadgetAttribute(\Gadget, #PB_Button_Image, ImageID(\Image))
    EndIf  
  EndWith
  
EndProcedure

; ----

Procedure SetButtonText(Gadget, Text.s)
  Protected *data.udtButtonColorGadget
  
  With *data
    *data = GetGadgetData(Gadget)
    If *data And *data\Gadget = Gadget
      \Text = Text
      DrawButtonColorGadget(*data)
    EndIf
  EndWith
EndProcedure

; ----

Procedure SetButtonFont(Gadget, FontID = #PB_Default)
  Protected *data.udtButtonColorGadget
  
  With *data
    *data = GetGadgetData(Gadget)
    If *data And *data\Gadget = Gadget
      \FontID = FontID 
      DrawButtonColorGadget(*data)
    EndIf
  EndWith
EndProcedure

; ----

Procedure SetButtonColor(Gadget, ColorType, Color)
  Protected *data.udtButtonColorGadget
  
  With *data
    *data = GetGadgetData(Gadget)
    If *data And *data\Gadget = Gadget
      Select ColorType
        Case #PB_Gadget_FrontColor
          \FrontColor = Color
        Case #PB_Gadget_BackColor
          \BackColor = Color
        Case #PB_Gadget_LineColor
          \LineColor = Color
      EndSelect
      DrawButtonColorGadget(*data)
    EndIf
  EndWith
EndProcedure

; ----

Procedure SetButtonSize(Gadget, x, y, Width, Height)
  Protected *data.udtButtonColorGadget
  
  With *data
    ResizeGadget(Gadget, x, y, Width, Height)
    *data = GetGadgetData(Gadget)
    If *data And *data\Gadget = Gadget
      DrawButtonColorGadget(*data)
    EndIf
  EndWith
EndProcedure

; ----

Procedure ButtonColorGadget(Gadget, x, y, Width, Height, Text.s, FrontColor, BackColor, Flags = 0)
  Protected result, *data.udtButtonColorGadget
  
  With *data
    result = ButtonImageGadget(Gadget, x, y, Width, Height, 0, Flags)
    If result
      If Gadget = #PB_Any
        Gadget = result
      EndIf
      *data = AllocateStructure(udtButtonColorGadget)
      If *data
        \Gadget = Gadget
        \Text = Text
        \FontID = #PB_Default
        \FrontColor = FrontColor
        \BackColor = BackColor
        \LineColor = #Gray
        \Image = CreateImage(#PB_Any, Width, Height, 32, #Gray)
        If StartDrawing(ImageOutput(\Image))
          Box(1, 1, Width - 2 , Height - 2, BackColor)
          DrawingFont(\FontID)
          DrawText(Width / 2 - TextWidth(Text) /2, Height / 2 - TextHeight(Text) / 2, Text, FrontColor, BackColor)
          StopDrawing()
          SetGadgetAttribute(Gadget, #PB_Button_Image, ImageID(\Image))
          SetGadgetData(Gadget, *data)
          ProcedureReturn result
        EndIf
      EndIf
    EndIf
    ; Rollback
    If *data
      If \Image
        FreeImage(\Image)
      EndIf
      FreeStructure(*data)
    EndIf
    If result
      FreeGadget(Gadget)
    EndIf
    ProcedureReturn 0
  EndWith
  
EndProcedure

; ----

Procedure DestroyGadget(Gadget)
  Protected *data.udtGadgetBase
  With *data
    *data = GetGadgetData(Gadget)
    If *data And *data\Gadget = Gadget
      If \Image
        FreeImage(\Image)
      EndIf
      If \Image2
        FreeImage(\Image2)
      EndIf
      FreeStructure(*data)
    EndIf
    FreeGadget(Gadget)
  EndWith
EndProcedure

; *****************************************************************************

;- Example

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration Windows
    #Main
  EndEnumeration
  
  Enumeration Gadgets
    #Button
  EndEnumeration
  
  Enumeration Status
    #MainStatusBar
  EndEnumeration

  LoadFont(0, "Courier", 20, #PB_Font_Bold)
  
  Procedure Main()
    
    If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 480, 320, "Standard ButtonColorGadget Number 42 ;)" , #PB_Window_SystemMenu)
      ButtonColorGadget(#Button, 10, 10, 120, 30, "My Button", #Yellow, #Red)
      
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Break
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #Button
                If GadgetWidth(#Button) <= 120
                  SetButtonSize(#Button, #PB_Ignore, #PB_Ignore, 240, 60)
                  SetButtonText(#Button, "My Big Button")
                  SetButtonFont(#Button, FontID(0))
                  SetButtonColor(#Button, #PB_Gadget_BackColor, #Green)
                  SetButtonColor(#Button, #PB_Gadget_FrontColor, #Black)
                  SetButtonColor(#Button, #PB_Gadget_LineColor, #Red)
                Else
                  SetButtonSize(#Button, #PB_Ignore, #PB_Ignore, 120, 30)
                  SetButtonText(#Button, "My Button")
                  SetButtonFont(#Button, #PB_Default)
                  SetButtonColor(#Button, #PB_Gadget_BackColor, #Red)
                  SetButtonColor(#Button, #PB_Gadget_FrontColor, #Yellow)
                  SetButtonColor(#Button, #PB_Gadget_LineColor, #Gray)
                EndIf
            EndSelect
            
        EndSelect
      ForEver
      
      DestroyGadget(#Button)
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
Benutzeravatar
mk-soft
Beiträge: 3695
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: Drei Möglichkeiten eigene Gadgets zu erstellen

Beitrag von mk-soft »

Module

Code: Alles auswählen

;-TOP
; Comment : Module ButtonColorGadget Number 42 ;)
; Author  : mk-soft
; Version : v1.03
; Create  : 30.04.2019

; OS      : All

EnableExplicit

; *****************************************************************************

DeclareModule ButtonColorGadget
  Declare Create(Gadget, x, y, Width, Height, Text.s, FrontColor, BackColor, Flags = 0)
  Declare Free(Gadget)
  Declare Resize(Gadget, x, y, Width, Height)
  Declare SetText(Gadget, Text.s)
  Declare SetFont(Gadget, FontID)
  Declare SetColor(Gadget, ColorType, Color)
EndDeclareModule

Module ButtonColorGadget
  
  Structure udtButtonColorGadget
    Gadget.i
    Image.i
    Text.s
    FontID.i
    FrontColor.i
    BackColor.i
    LineColor.i
  EndStructure
  
  ; ----
  
  Procedure DrawButton(*data.udtButtonColorGadget)
    Protected Width, Height
    
    With *data
      Width = GadgetWidth(\Gadget)
      Height = GadgetHeight(\Gadget)
      If ImageWidth(\Image) <> Width Or ImageHeight(\Image) <> Height
        FreeImage(\Image)
        \Image = CreateImage(#PB_Any, Width, Height, 32)
      EndIf
      If StartDrawing(ImageOutput(\Image))
        Box(0, 0, Width, Height, \LineColor)
        Box(1, 1, Width - 2 , Height - 2, \BackColor)
        DrawingFont(\FontID)
        DrawText(Width / 2 - TextWidth(\Text) /2, Height / 2 - TextHeight(\Text) / 2, \Text, \FrontColor, \BackColor)
        StopDrawing()
        SetGadgetAttribute(\Gadget, #PB_Button_Image, ImageID(\Image))
      EndIf  
    EndWith
    
  EndProcedure
  
  ; ----
  
  Procedure SetText(Gadget, Text.s)
    Protected *data.udtButtonColorGadget
    
    With *data
      *data = GetGadgetData(Gadget)
      If *data And *data\Gadget = Gadget
        \Text = Text
        DrawButton(*data)
      EndIf
    EndWith
  EndProcedure
  
  ; ----
  
  Procedure SetFont(Gadget, FontID)
    Protected *data.udtButtonColorGadget
    
    With *data
      *data = GetGadgetData(Gadget)
      If *data And *data\Gadget = Gadget
        \FontID = FontID 
        DrawButton(*data)
      EndIf
    EndWith
  EndProcedure
  
  ; ----
  
  Procedure SetColor(Gadget, ColorType, Color)
    Protected *data.udtButtonColorGadget
    
    With *data
      *data = GetGadgetData(Gadget)
      If *data And *data\Gadget = Gadget
        Select ColorType
          Case #PB_Gadget_FrontColor
            \FrontColor = Color
          Case #PB_Gadget_BackColor
            \BackColor = Color
          Case #PB_Gadget_LineColor
            \LineColor = Color
        EndSelect
        DrawButton(*data)
      EndIf
    EndWith
  EndProcedure
  
  ; ----
  
  Procedure Resize(Gadget, x, y, Width, Height)
    Protected *data.udtButtonColorGadget
    
    With *data
      ResizeGadget(Gadget, x, y, Width, Height)
      *data = GetGadgetData(Gadget)
      If *data And *data\Gadget = Gadget
        DrawButton(*data)
      EndIf
    EndWith
  EndProcedure
  
  ; ----
  
  Procedure Create(Gadget, x, y, Width, Height, Text.s, FrontColor, BackColor, Flags = 0)
    Protected result, *data.udtButtonColorGadget
    
    With *data
      result = ButtonImageGadget(Gadget, x, y, Width, Height, 0, Flags)
      If result
        If Gadget = #PB_Any
          Gadget = result
        EndIf
        *data = AllocateStructure(udtButtonColorGadget)
        If *data
          \Gadget = Gadget
          \Text = Text
          \FontID = #PB_Default
          \FrontColor = FrontColor
          \BackColor = BackColor
          \LineColor = #Gray
          \Image = CreateImage(#PB_Any, Width, Height, 32, #Gray)
          If StartDrawing(ImageOutput(\Image))
            Box(1, 1, Width - 2 , Height - 2, BackColor)
            DrawingFont(\FontID)
            DrawText(Width / 2 - TextWidth(Text) /2, Height / 2 - TextHeight(Text) / 2, Text, FrontColor, BackColor)
            StopDrawing()
            SetGadgetAttribute(Gadget, #PB_Button_Image, ImageID(\Image))
            SetGadgetData(Gadget, *data)
            ProcedureReturn result
          EndIf
        EndIf
      EndIf
      ; Rollback
      If *data
        If \Image
          FreeImage(\Image)
        EndIf
        FreeStructure(*data)
      EndIf
      If result
        FreeGadget(Gadget)
      EndIf
      ProcedureReturn 0
    EndWith
    
  EndProcedure
  
  ; ----
  
  Procedure Free(Gadget)
    Protected *data.udtButtonColorGadget
    With *data
      *data = GetGadgetData(Gadget)
      If *data And *data\Gadget = Gadget
        If \Image
          FreeImage(\Image)
        EndIf
        FreeStructure(*data)
      EndIf
      FreeGadget(Gadget)
    EndWith
  EndProcedure
  
EndModule

; *****************************************************************************

;- Example

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration Windows
    #Main
  EndEnumeration
  
  Enumeration Gadgets
    #Button
  EndEnumeration
  
  Enumeration Status
    #MainStatusBar
  EndEnumeration

  LoadFont(0, "Courier", 20, #PB_Font_Bold)
  
  Procedure Main()
    
    If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 480, 320, "Module ButtonColorGadget Number 42 ;)" , #PB_Window_SystemMenu)
      ButtonColorGadget::Create(#Button, 10, 10, 120, 30, "My Button", #Yellow, #Red)
      
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Break
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #Button
                If GadgetWidth(#Button) <= 120
                  ButtonColorGadget::Resize(#Button, #PB_Ignore, #PB_Ignore, 240, 60)
                  ButtonColorGadget::SetText(#Button, "My Big Button")
                  ButtonColorGadget::SetFont(#Button, FontID(0))
                  ButtonColorGadget::SetColor(#Button, #PB_Gadget_BackColor, #Green)
                  ButtonColorGadget::SetColor(#Button, #PB_Gadget_FrontColor, #Black)
                  ButtonColorGadget::SetColor(#Button, #PB_Gadget_LineColor, #Red)
                Else
                  UseModule ButtonColorGadget
                  Resize(#Button, #PB_Ignore, #PB_Ignore, 120, 30)
                  SetText(#Button, "My Button")
                  SetFont(#Button, #PB_Default)
                  SetColor(#Button, #PB_Gadget_BackColor, #Red)
                  SetColor(#Button, #PB_Gadget_FrontColor, #Yellow)
                  SetColor(#Button, #PB_Gadget_LineColor, #Gray)
                  UnuseModule ButtonColorGadget
                EndIf
            EndSelect
            
        EndSelect
      ForEver
      
      ButtonColorGadget::Free(#Button)
      
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
Benutzeravatar
mk-soft
Beiträge: 3695
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: Drei Möglichkeiten eigene Gadgets zu erstellen

Beitrag von mk-soft »

Objektorientiert

Bugfix

Code: Alles auswählen

;-TOP
; Comment : Object ButtonColorGadget Number 42 ;)
; Author  : mk-soft
; Version : v1.04
; Create  : 01.05.2019

; OS      : All

; Link BaseClass : https://www.purebasic.fr/english/viewtopic.php?f=12&t=64305
IncludeFile "Modul_BaseClassSmall.pb"

EnableExplicit

; *****************************************************************************

DeclareModule ButtonColorGadget
  
  UseModule BaseClass
  
  Interface iButtonColorGadget Extends iBaseClass
    Resize(x, y, Width, Height)
    SetText(Text.s)
    SetFont(FontID)
    SetColor(ColorType, Color)
    GetID()
    GetText.s()
    GetColor(ColorType)
  EndInterface
  
  UnuseModule BaseClass
  
  Declare Create(Gadget, x, y, Width, Height, Text.s, FrontColor, BackColor, Flags = 0)
  
EndDeclareModule

Module ButtonColorGadget
  
  EnableExplicit
  
  UseModule BaseClass
  
  NewClass(iButtonColorGadget)
  
  Structure sButtonColorGadget Extends sBaseClass
    Gadget.i
    ; Params
    x.i
    y.i
    Width.i
    Height.i
    Text.s
    FrontColor.i
    BackColor.i
    Flags.i
    ; Data
    Image.i
    FontID.i
    LineColor.i
  EndStructure
  
  ; ----
  
  Procedure DrawButton(*this.sButtonColorGadget)
    With *this
      If ImageWidth(\Image) <> \Width Or ImageHeight(\Image) <> \Height
        FreeImage(\Image)
        \Image = CreateImage(#PB_Any, \Width, \Height, 32)
      EndIf
      If StartDrawing(ImageOutput(\Image))
        Box(0, 0, \Width, \Height, \LineColor)
        Box(1, 1, \Width - 2 , \Height - 2, \BackColor)
        DrawingFont(\FontID)
        DrawText(\Width / 2 - TextWidth(\Text) /2, \Height / 2 - TextHeight(\Text) / 2, \Text, \FrontColor, \BackColor)
        StopDrawing()
        SetGadgetAttribute(\Gadget, #PB_Button_Image, ImageID(\Image))
      EndIf  
    EndWith
    
  EndProcedure
  
  ; ----
  
  Procedure SetText(*this.sButtonColorGadget, Text.s)
    With *this
      \Text = Text
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(SetText)
  
  ; ----
  
  Procedure SetFont(*this.sButtonColorGadget, FontID)
    With *this
      \FontID = FontID 
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(SetFont)
  
  ; ----
  
  Procedure SetColor(*this.sButtonColorGadget, ColorType, Color)
    With *this
      Select ColorType
        Case #PB_Gadget_FrontColor
          \FrontColor = Color
        Case #PB_Gadget_BackColor
          \BackColor = Color
        Case #PB_Gadget_LineColor
          \LineColor = Color
      EndSelect
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(SetColor)
  
  ; ----
  
  Procedure Resize(*this.sButtonColorGadget, x, y, Width, Height)
    With *this
      ResizeGadget(\Gadget, x, y, Width, Height)
      If x <> #PB_Ignore
        \x = x
      EndIf
      If y <> #PB_Ignore
        \y = y
      EndIf
      If Width <> #PB_Ignore
        \Width = Width
      EndIf
      If Height <> #PB_Ignore
        \Height = Height
      EndIf
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(Resize)
  
  ; ----
  
  Procedure GetID(*this.sButtonColorGadget)
    ProcedureReturn *this\Gadget
  EndProcedure : AsMethode(GetID)
  
  ; ----
  
  Procedure.s GetText(*this.sButtonColorGadget)
    ProcedureReturn *this\Text
  EndProcedure : AsMethode(GetText)
  
  ; ----
  
  Procedure GetColor(*this.sButtonColorGadget, ColorType)
    Protected color
    With *this
      Select ColorType
        Case #PB_Gadget_FrontColor
          color = \FrontColor
        Case #PB_Gadget_BackColor
          color = \BackColor
        Case #PB_Gadget_LineColor
          color = \LineColor
      EndSelect
      ProcedureReturn color
    EndWith
  EndProcedure : AsMethode(GetColor)
  
  ; ----
  
  Procedure Initialize(*this.sButtonColorGadget)
    Protected result
    
    With *this
      result = ButtonImageGadget(\Gadget, \x, \y, \Width, \Height, 0, \Flags)
      If result
        If \Gadget = #PB_Any
          \Gadget = result
        EndIf
        \FontID = #PB_Default
        \LineColor = #Gray
        \Image = CreateImage(#PB_Any, \Width, \Height, 32, #Gray)
        DrawButton(*this)
      EndIf
    EndWith
  EndProcedure : AsInitializeObject(Initialize)
  
  ; ----
  
  Procedure Dispose(*this.sButtonColorGadget)
    With *this
      If \Image
        FreeImage(\Image)
      EndIf
      If IsGadget(\Gadget)
        FreeGadget(\Gadget)
      EndIf
    EndWith
  EndProcedure : AsDisposeObject(Dispose)
  
  ; ----
  
  Procedure Create(Gadget, x, y, Width, Height, Text.s, FrontColor, BackColor, Flags = 0)
    Protected *object.sButtonColorGadget
    
    With *object
      AllocateObject(*object, sButtonColorGadget)
      If *object
        \Gadget = Gadget
        \x = x
        \y = y
        \Width = Width
        \Height = Height
        \Text = Text
        \FrontColor = FrontColor
        \BackColor = BackColor
        \Flags = Flags
      EndIf
      InitializeObject(*object)
      ProcedureReturn *object
    EndWith
  EndProcedure
  
  ; ----
  
  CheckInterface()
  
EndModule

; *****************************************************************************

;- Example

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration Windows
    #Main
  EndEnumeration
  
  Enumeration Gadgets
    #Button
  EndEnumeration
  
  Enumeration Status
    #MainStatusBar
  EndEnumeration

  LoadFont(0, "Courier New", 20, #PB_Font_Bold)
  
  Procedure Main()
    ; Define button object
    Protected btn.ButtonColorGadget::iButtonColorGadget
    Protected btnID
      
    If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 480, 320, "Object ButtonColorGadget Number 42 ;)" , #PB_Window_SystemMenu)
      btn = ButtonColorGadget::Create(#Button, 10, 10, 120, 30, "My Button", #Yellow, #Red)
      
      btnID = btn\GetID()
      
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Break
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #Button
                If GadgetWidth(#Button) <= 120
                  btn\Resize(#PB_Ignore, #PB_Ignore, 240, 60)
                  btn\SetText("My Big Button")
                  btn\SetFont(FontID(0))
                  btn\SetColor(#PB_Gadget_BackColor, #Green)
                  btn\SetColor(#PB_Gadget_FrontColor, #Black)
                  btn\SetColor(#PB_Gadget_LineColor, #Red)
                Else
                  btn\Resize(#PB_Ignore, #PB_Ignore, 120, 30)
                  btn\SetText("My Button")
                  btn\SetFont(#PB_Default)
                  btn\SetColor(#PB_Gadget_BackColor, #Red)
                  btn\SetColor(#PB_Gadget_FrontColor, #Yellow)
                  btn\SetColor(#PB_Gadget_LineColor, #Gray)
                EndIf
            EndSelect
            
        EndSelect
      ForEver
      
      btn\Release()
      
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
Benutzeravatar
Kurzer
Beiträge: 1614
Registriert: 25.04.2006 17:29
Wohnort: Nähe Hamburg

Re: Drei Möglichkeiten eigene Gadgets zu erstellen

Beitrag von Kurzer »

Vielen Dank für deine drei Beispiele. :allright: Ich schätze deine qualitativ hochwertigen Codes schon länger.

Bzgl. Customgadgets bevorzuge ich die reine "Modulbauweise", auch wenn ich selbst erst sehr wenig in Richtung Customgadget programmiert habe. Möglicherweise habe ich mir dabei sogar das Grundgerüst von dir "ausgeliehen" :), denn ich stelle fest , dass auch du die Daten der Gadget-Instanzen in einem strukturieten, allokierten Speicherbereich ablegst.

Es gibt andere Customgadgets, bei denen diese Verwaltungsdaten in einer Liste gespeichert werden (z.B. die aktuelle "Modulwelle" ;) von Thorsten1867). Ob es bei dem ein oder anderen Verfahren Vor- oder Nachteile gibt, kann ich nicht beurteilen, aber ich finde die Umsetzung als Modul und die Verwaltung mit Hilfe von strukturiertem Speicher sehr smart. Von daher nutze ich diesen Ansatz ebenfalls.

Früher als es das Canvasgadget noch nicht gab habe ich bereits die Erstellung von Customgadgets angesehen, aber da gab es ne Menge WinAPI in den Lösungen und ich bin ehrlich gesagt auch heute noch kein Held, wenn es um die Windows internen Strukturen und Funktionen geht. :mrgreen:
"Never run a changing system!" | "Unterhalten sich zwei Alleinunterhalter... Paradox, oder?"
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520
Useralter in 2023: 56 Jahre.
Benutzeravatar
mhs
Beiträge: 224
Registriert: 11.01.2009 16:30
Wohnort: Graben
Kontaktdaten:

Re: Drei Möglichkeiten eigene Gadgets zu erstellen

Beitrag von mhs »

Ganz klar Variante 3.

Nutze ich auch selbst, nicht nur für Custom Gadgets, sondern für die gesamte GUI und Eventhandling.
Michael Hack

Michael Hack Software :: Softwareentwicklung | Webentwicklung | IT-Dienstleistungen
www.michaelhacksoftware.de :: www.mh-s.de :: www.michael-hack.de
Antworten