Seite 1 von 1

Lieber Weihnachtsmann: GetWindowColor + GetGadgetColor

Verfasst: 18.12.2019 15:52
von hjbremer
Lieber Weihnachtsmann:

Ich wünsche mir das GetWindowColor + GetGadgetColor

endlich auch ohne einen SetColor Befehl die richtigen Farbwerte zurück geben.

Und nicht -1

Auch StartDrawing() ist unzuverlässig, siehe auf Button drücken

Code: Alles auswählen

OpenWindow(0, 0, 0, 322, 200, "Lieber Weihnachtsmann", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ContainerGadget(1, 8, 8, 150, 180, #PB_Container_Flat)
CloseGadgetList()

PanelGadget(2, 165, 8, 150, 180)      
   AddGadgetItem (2, -1, "Panel 1")
   ButtonGadget(3, 20, 50, 80, 30, "drücken")
   AddGadgetItem (2, -1, "Panel 2")
   CloseGadgetList()

Debug "Background-Farben ohne SetColor"
Debug GetWindowColor(0)
Debug Hex(GetWindowColor(0))

Debug GetGadgetColor(1, #PB_Gadget_BackColor)
Debug Hex(GetGadgetColor(1, #PB_Gadget_BackColor))

Debug GetGadgetColor(2, #PB_Gadget_BackColor)
Debug Hex(GetGadgetColor(2, #PB_Gadget_BackColor))

Debug ""
Debug "Background-Farbe mit StartDrawing()"

StartDrawing(WindowOutput(0))
   Debug Hex(Point(1,1))
StopDrawing()


Repeat : Event = WaitWindowEvent()
   
   Select Event
         
      Case #PB_Event_Gadget
         Select EventGadget()
            Case 3
               SetWindowColor(0, #Green)   
               SetGadgetColor(1, #PB_Gadget_BackColor, #Blue)
               
               Debug ""
               Debug "Background-Farben nach SetColor"
               Debug GetWindowColor(0)
               Debug Hex(GetWindowColor(0))               
               Debug GetGadgetColor(1, #PB_Gadget_BackColor)
               Debug Hex(GetGadgetColor(1, #PB_Gadget_BackColor))  
               
               StartDrawing(WindowOutput(0))
                  Debug Hex(Point(1,1)) + " <--- Buh"
               StopDrawing()
               
         EndSelect
         
   EndSelect
Until Event = #PB_Event_CloseWindow


Re: Lieber Weihnachtsmann: GetWindowColor + GetGadgetColor

Verfasst: 18.12.2019 19:53
von ccode_new
TADA!

Code: Alles auswählen

Procedure.s GUICtrlGetBkColor(win.i, gad.i)
  Protected.i hwnd, hdc, icolor
  Protected.s scolor
 
  If IsGadget(gad)
    UpdateWindow_(WindowID(win))
   
    StartDrawing(WindowOutput(win))
    icolor = Point(GadgetX(gad)+1, GadgetY(gad)+1)
    StopDrawing()
   
    Red = Red(iColor)
    Green = Green(iColor)
    Blue = Blue(iColor)
    scolor = RSet(Hex(Red), 2, "0") + RSet(Hex(Green), 2, "0") + RSet(Hex(Blue), 2, "0")
   
    ProcedureReturn sColor
  Else
    ProcedureReturn "Error"
  EndIf
EndProcedure

Procedure.s GUIGetBkColor(win.i)
  Protected.i hwnd, hdc, icolor
  Protected.s scolor
 
  If IsWindow(win)
    UpdateWindow_(WindowID(win))
   
    hwnd = WindowID(win)
   
    hdc = GetDC_(hwnd)
    iColor = GetPixel_(hdc, 0, 0)
    ReleaseDC_(hwnd, hdc)
    Red = Red(iColor)
    Green = Green(iColor)
    Blue = Blue(iColor)
    scolor = RSet(Hex(Red), 2, "0") + RSet(Hex(Green), 2, "0") + RSet(Hex(Blue), 2, "0")
   
    ProcedureReturn sColor
  Else
    ProcedureReturn "Error"
  EndIf
EndProcedure

Procedure KnopfGedrueckt()
  SetWindowColor(0, #Green)   
  SetGadgetColor(1, #PB_Gadget_BackColor, #Blue)
 
;   Debug ""
;   Debug "Background-Farben nach SetColor"
;   Debug GetWindowColor(0)
;   Debug Hex(GetWindowColor(0))               
;   Debug GetGadgetColor(1, #PB_Gadget_BackColor)
;   Debug Hex(GetGadgetColor(1, #PB_Gadget_BackColor))
;   
;   ;   StartDrawing(WindowOutput(0))
;   ;   Debug Hex(Point(1,1))
;   ;   StopDrawing()
;   
  Debug GUIGetBkColor(0)
  Debug GUICtrlGetBkColor(0, 1)
EndProcedure


OpenWindow(0, 0, 0, 322, 200, "Lieber Weihnachtsmann", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ContainerGadget(1, 8, 8, 150, 180, #PB_Container_Flat)
CloseGadgetList()

PanelGadget(2, 165, 8, 150, 180)     
AddGadgetItem (2, -1, "Panel 1")
ButtonGadget(3, 20, 50, 80, 30, "drücken")
AddGadgetItem (2, -1, "Panel 2")
CloseGadgetList()

; Debug ""
; Debug "Background-Farbe mit StartDrawing()"
;
; Debug "Background-Farben ohne SetColor"
; Debug GetWindowColor(0)
;
; Debug Hex(GetWindowColor(0))
;
; Debug GetGadgetColor(1, #PB_Gadget_BackColor)
; Debug Hex(GetGadgetColor(1, #PB_Gadget_BackColor))
;
; Debug GetGadgetColor(2, #PB_Gadget_BackColor)
; Debug Hex(GetGadgetColor(2, #PB_Gadget_BackColor))
;
; ; StartDrawing(WindowOutput(0))
; ; Debug Hex(Point(1,1))
; ; StopDrawing()

Debug GUIGetBkColor(0)
Debug GUICtrlGetBkColor(0, 1)

BindGadgetEvent(3, @KnopfGedrueckt())


Repeat : Event = WindowEvent()
 
Until Event = #PB_Event_CloseWindow