Class_OD_Colors (für Holle)

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Class_OD_Colors (für Holle)

Post by just me » 19 Oct 2013, 09:01

:arrow: Update am 24.10.2013

Schon seit längerer Zeit beschäftigt sich Holle (aka Dr_Holle) mit dem Problem, einzelne Einträge in DDLs einzufärben. (Das ist allerdings nur eine Winzigkeit in einem Riesenprojekt, das mich ungläubig staunen lässt.) Ich habe mich nach Abstimmung mit ihm immer mal wieder damit beschäftigt, aber auch keine bessere Lösung gefunden.

Bei der Arbeit an Class_TransparentListBox.ahk bin ich dann auf die "Owner-Draw" Möglichkeit gestoßen, auch wenn ich sie in diesem Skript nicht eingesetzt habe. Allerdings dachte ich mir gleich, dass man das für den Zweck, einzelne Einträge in ListBoxen oder DropDownListen einzufärben, nutzen kann. Nach einigem Herumprobieren mit durchwachsenen Ergebnissen bin ich heute auf eine Lösung gestoßen, die - zumindest unter Win 7 - recht einfach funktioniert. Und weil das in erster Linie für Holle bestimmt ist, wird es in diesem Forum veröffenlicht:
OD_Colors.png
OD_Colors.png (24.83 KiB) Viewed 12775 times
Class_OD_Colors.ahk:

Code: Select all

; ======================================================================================================================
; AHK 1.1.13+
; ======================================================================================================================
; Namespace:   OD_Colors
; Function:    Helper class for colored items in ListBox and DropDownList controls.
; AHK version: 1.1.13.00 (U64)
; Tested on:   Win 7 Pro x64
; Language:    English
; Version:     1.0.01.00/2013-10-24/just me
; MSDN:        Owner-Drawn ListBox -> http://msdn.microsoft.com/en-us/library/hh298352(v=vs.85).aspx
; Credits:     THX, Holle. You never gave up trying to manage it. So I remembered your problem from time to time
;              and finally found this solution.
; ======================================================================================================================
; How to use:  To register a control call OD_Colors.Attach() passing two parameters:
;                 Hwnd   - HWND of the control
;                 Colors - Object which may contain the following keys:
;                          T - default text color.
;                          B - default background color.
;                          The one-based index of items with special text and/or background colors.
;                          Each of this keys contains an object with up to two key/value pairs:
;                             T - text colour.
;                             B - background colour.
;                          Color values have to be passed as RGB integer values (0xRRGGBB).
;                          If either T or B is not specified, the control's default colour will be used.
;              To update a control after content or colour changes call OD_Colors.Update() passing two parameters:
;                 Hwnd   - HWND of the control.
;                 Colors - see above.
;              To unregister a control call OD_Colors.Detach() passing one parameter:
;                 Hwnd  - see above.
; Note:        ListBoxes must have the styles LBS_OWNERDRAWFIXED (0x0010) and LBS_HASSTRINGS (0x0040),
;              DropDownLists CBS_OWNERDRAWFIXED (0x0010) and  CBS_HASSTRINGS (0x0200) set at creation time.
;              Before adding the control, you have to set OD_Colors.ItemHeight (see OD_Colors.MeasureItem).
; ======================================================================================================================
; This software is provided 'as-is', without any express or implied warranty.
; In no event will the authors be held liable for any damages arising from the use of this software.
; ======================================================================================================================

Class OD_Colors {
   ; ===================================================================================================================
   ; Class variables ===================================================================================================
   ; ===================================================================================================================
   ; WM_MEASUREITEM := 0x002C
   Static OnMessageInit := OnMessage(0x002C, "OD_Colors.MeasureItem")
   Static ItemHeight := 0
   Static Controls := {}
   ; ===================================================================================================================
   ; You must not instantiate this class! ==============================================================================
   ; ===================================================================================================================
   __New(P*) {
      Return False
   }
   ; ===================================================================================================================
   ; Public methods ====================================================================================================
   ; ===================================================================================================================
   Attach(HWND, Colors) {
      Static WM_DRAWITEM := 0x002B
      If !IsObject(Colors)
         Return False
      This.Controls[HWND] := {}
      ControlGet, Content, List, , , ahk_id %HWND%
      This.Controls[HWND].Items := StrSplit(Content, "`n")
      This.Controls[HWND].Colors := {}
      For Key, Value In Colors {
         If (Key = "T") {
            This.Controls[HWND].Colors.T := ((Value & 0xFF) << 16) | (Value & 0x00FF00) | ((Value >> 16) & 0xFF)
            Continue
         }
         If (Key = "B") {
            This.Controls[HWND].Colors.B := ((Value & 0xFF) << 16) | (Value & 0x00FF00) | ((Value >> 16) & 0xFF)
            Continue
         }
         If ((Item := Round(Key)) = Key) {
            If ((C := Value.T) <> "")
               This.Controls[HWND].Colors[Item, "T"] := ((C & 0xFF) << 16) | (C & 0x00FF00) | ((C >> 16) & 0xFF)
            If ((C := Value.B) <> "")
               This.Controls[HWND].Colors[Item, "B"] := ((C & 0xFF) << 16) | (C & 0x00FF00) | ((C >> 16) & 0xFF)
         }
      }
      If !OnMessage(WM_DRAWITEM)
         OnMessage(WM_DRAWITEM, "OD_Colors.DrawItem")
      WinSet, Redraw, , ahk_id %HWND%
      Return True
   }
   ; ===================================================================================================================
   Detach(HWND) {
      This.Controls.Remove(HWND, "")
      If (This.Controls.MaxIndex = "")
         OnMessage(WM_DRAWITEM, "")
      WinSet, Redraw, , ahk_id %HWND%
      Return True
   }
   ; ===================================================================================================================
   Update(HWND, Colors := "") {
      If This.Controls.HasKey(HWND)
         This.Detach(HWND)
      Return This.Attach(HWND)
   }
   ; ===================================================================================================================
   SetItemHeight(FontOptions, FontName) {
      Gui, OD_Colors_SetItemHeight:Font, %FontOptions%, %FontName%
      Gui, OD_Colors_SetItemHeight:Add, Text, 0x200 hwndHTX, Dummy
      VarSetCapacity(RECT, 16, 0)
      DllCall("User32.dll\GetClientRect", "Ptr", HTX, "Ptr", &RECT)
      Gui, OD_Colors_SetItemHeight:Destroy
      Return (OD_Colors.ItemHeight := NumGet(RECT, 12, "Int"))
   }
   ; ===================================================================================================================
   ; Called by system ==================================================================================================
   ; ===================================================================================================================
   MeasureItem(lParam, Msg, Hwnd) { ; first param 'wParam' is passed as 'This'.
      ; ----------------------------------------------------------------------------------------------------------------
      ; Sent once to the parent window of an OWNERDRAWFIXED ListBox or ComboBox when an the control is being created.
      ; When the owner receives this message, the system has not yet determined the height and width of the font used
      ; in the control. That is why OD_Colors.ItemHeight must be set to an appropriate value before the control will be
      ; created by Gui, Add, ... You either might call 'OD_Colors.SetItemHeight' passing the current font options and
      ; name to calculate the value or set it manually.
      ; WM_MEASUREITEM      -> http://msdn.microsoft.com/en-us/library/bb775925(v=vs.85).aspx
      ; MEASUREITEMSTRUCT   -> http://msdn.microsoft.com/en-us/library/bb775804(v=vs.85).aspx
      ; ----------------------------------------------------------------------------------------------------------------
      ; lParam -> MEASUREITEMSTRUCT offsets
      Static offHeight := 16
      NumPut(OD_Colors.ItemHeight, lParam + 0, offHeight, "Int")
      Return True
   }
   ; ===================================================================================================================
   DrawItem(lParam, Msg, Hwnd) { ; first param 'wParam' is passed as 'This'.
      ; ----------------------------------------------------------------------------------------------------------------
      ; Sent to the parent window of an owner-drawn ListBox or ComboBox when a visual aspect of the control has changed.
      ; WM_DRAWITEM         -> http://msdn.microsoft.com/en-us/library/bb775923(v=vs.85).aspx
      ; DRAWITEMSTRUCT      -> http://msdn.microsoft.com/en-us/library/bb775802(v=vs.85).aspx
      ; ----------------------------------------------------------------------------------------------------------------
      ; lParam / DRAWITEMSTRUCT offsets
      Static offItem := 8, offAction := offItem + 4, offState := offAction + 4, offHWND := offState + A_PtrSize
           , offDC := offHWND + A_PtrSize, offRECT := offDC + A_PtrSize, offData := offRECT + 16
      ; Owner Draw Type
      Static ODT := {2: "LISTBOX", 3: "COMBOBOX"}
      ; Owner Draw Action
      Static ODA_DRAWENTIRE := 0x0001, ODA_SELECT := 0x0002, ODA_FOCUS := 0x0004
      ; Owner Draw State
      Static ODS_SELECTED := 0x0001, ODS_FOCUS := 0x0010
      ; Draw text format flags
      Static DT_Flags := 0x24 ; DT_SINGLELINE = 0x20, DT_VCENTER = 0x04
      ; ----------------------------------------------------------------------------------------------------------------
      Critical ; may help in case of drawing issues
      HWND := NumGet(lParam + offHWND, 0, "UPtr")
      If OD_Colors.Controls.HasKey(HWND) && ODT.HasKey(NumGet(lParam + 0, 0, "UInt")) {
         ODCtrl := OD_Colors.Controls[HWND]
         Item := NumGet(lParam + offItem, 0, "Int") + 1
         Action := NumGet(lParam + offAction, 0, "UInt")
         State := NumGet(lParam + offState, 0, "UInt")
         HDC := NumGet(lParam + offDC, 0, "UPtr")
         RECT := lParam + offRECT
         If (Action = ODA_FOCUS)
            Return True
         If ODCtrl.Colors.HasKey("B")
            CtrlBgC := ODCtrl.Colors.B
         Else
            CtrlBgC := DllCall("Gdi32.dll\GetBkColor", "Ptr", HDC, "UInt")
         If ODCtrl.Colors.HasKey("T")
            CtrlTxC := ODCtrl.Colors.T
         Else
            CtrlTxC := DllCall("Gdi32.dll\GetTextColor", "Ptr", HDC, "UInt")
         BgC := ODCtrl.Colors[Item].HasKey("B") ? ODCtrl.Colors[Item].B : CtrlBgC
         Brush := DllCall("Gdi32.dll\CreateSolidBrush", "UInt", BgC, "UPtr")
         DllCall("User32.dll\FillRect", "Ptr", HDC, "Ptr", RECT, "Ptr", Brush)
         DllCall("Gdi32.dll\DeleteObject", "Ptr", Brush)
         Txt := ODCtrl.Items[Item], Len := StrLen(Txt)
         TxC := ODCtrl.Colors[Item].HasKey("T") ? ODCtrl.Colors[Item].T : CtrlTxC
         NumPut(NumGet(RECT + 0, 0, "Int") + 2, RECT + 0, 0, "Int")
         DllCall("Gdi32.dll\SetBkMode", "Ptr", HDC, "Int", 1) ; TRANSPARENT
         DllCall("Gdi32.dll\SetTextColor", "Ptr", HDC, "UInt", TxC)
         DllCall("User32.dll\DrawText", "Ptr", HDC, "Ptr", &Txt, "Int", Len, "Ptr", RECT, "UInt", DT_Flags)
         NumPut(NumGet(RECT + 0, 0, "Int") - 2, RECT + 0, 0, "Int")
         If (State & ODS_SELECTED)
            DllCall("User32.dll\DrawFocusRect", "Ptr", HDC, "Ptr", RECT)
         DllCall("Gdi32.dll\SetTextColor", "Ptr", HDC, "UInt", CtrlTxC)
         Return True
      }
   }
}
OD_Colors_sample.ahk:

Code: Select all

#NoEnv
SetBatchLines, -1
; ----------------------------------------------------------------------------------------------------------------------
; DDL styles
OD_DDL := "+0x0210" ; CBS_OWNERDRAWFIXED = 0x0010, CBS_HASSTRINGS = 0x0200
; ListBox styles
OD_LB  := "+0x0050" ; LBS_OWNERDRAWFIXED = 0x0010, LBS_HASSTRINGS = 0x0040
; Liste
Items := "Eins|Zwei|Drei|Vier|Fünf|Sechs|Sieben|Acht|Neun|Zehn"
; ----------------------------------------------------------------------------------------------------------------------
Gui, Margin, 20, 20
Gui, Add, Text, xm w200, Owner-Drawn DropDownList:
Gui, Add, Text, x+20 yp wp, Owner-Drawn ListBox:
Gui, Add, Text, x+20 yp wp, Common ListBox:
Gui, Font, % (FontOptions := "s10"), % (FontName := "Arial")
OD_Colors.SetItemHeight(FontOptions, FontName)
Gui, Add, DDL, xm y+5 w200 r6 hwndHDDL Choose4 %OD_DDL%, %Items%
Gui, Add, ListBox, x+20 yp wp r6 hwndHLB cGreen %OD_LB%, %Items%
Gui, Add, ListBox, x+20 yp wp r6, %Items%
Gui, Show, , OD_Colors
OD_Colors.Attach(HDDL, {T: 0x000080, B: 0xF0F0F0, 4: {T: 0xFFFFFF, B: 0xFF0000}, 6: {T: 0xFFFFFF, B: 0xFF0000}})
OD_Colors.Attach(HLB, {4: {T: 0xFFFFFF, B: 0x000080}, 6: {T: 0xFFFFFF, B: 0x008000}})
Return
; ----------------------------------------------------------------------------------------------------------------------
GuiClose:
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
#Include Class_OD_Colors.ahk
Das rötliche Auswahlrechteck in der DDL bekomme ich bisher nicht umgefärbt. Und ich bin mir auch nicht sicher, ob das unter XP und/oder Vista genauso funktioniert. Vielleicht kann das mal jemand testen.
Last edited by just me on 24 Oct 2013, 02:35, edited 1 time in total.

Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by Alibaba » 19 Oct 2013, 11:19

just me wrote:Vielleicht kann das mal jemand testen.
Gerade für XP getestet.
Funktioniert auch hier problemlos.

Gute Arbeit! :)
"Nothing is quieter than a loaded gun." - Heinrich Heine

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by just me » 19 Oct 2013, 11:23

Danke für den Test! ;)

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by just me » 24 Oct 2013, 02:28

Update am 24.10.2013:

Ich hatte gleich das Gefühl, dass es so einfach nicht sein kann. Wenn man größere Fonthöhen nutzt, merkt man schnell, dass man die WM_MEASUREITEM Nachricht doch nicht ignorieren kann. Ich habe deshalb Behandlung der WM_MEASUREITEM Nachricht nachgerüstet. Sie wird beim Start der Anwendung automatisch per OnMessage() zugewiesen. Dabei stellt sich folgendes Problem:
MSDN wrote:The system sends the WM_MEASUREITEM message to the owner window of combo boxes and list boxes created with the OWNERDRAWFIXED style before sending the WM_INITDIALOG message. As a result, when the owner receives this message, the system has not yet determined the height and width of the font used in the control; function calls and calculations requiring these values should occur in the main function of the application or library.
Das soll heißen: Die Anwendung muss die Höhe der Einträge irgendwie selbst berechnen, bevor das Control per Gui, Add, ... erstellt wird. Nach einigem Herumprobieren scheint es so, als ob die Höhe eines Eintrags mit einem gegebenen Font der Höhe eines einzeiligen Textfeldes mit demselben Font entspricht. Deshalb gibt es die neue Methode SetItemHeight(FontOptions, FontName). Sie muss vor dem Gui, Add, ... mit den aktuellen Werten des per Gui, Font, ... eingestellten Fonts aufgerufen werden. Für den Standardfont wird dabei einfach zweimal "" oder mit der aktuellen AHK Version gar nichts übergeben.

Außerdem habe ich noch mit controlspezifischen Fontfarben (z.B. cGreen) experimentiert. Das klappt gut bei einer ListBox, bei einer DropDownList aber nur für das Auswahlfeld. Ich habe deshalb das bei Attach() und Update() benötigte Objekt Colors um die Eigenschaften T (Standardtextfarbe) und B (Standardhintergrundfarbe) ergänzt.

Getestet ist das Ganze wieder nur mit Win 7 x64 / AHK U64.

User avatar
Holle
Posts: 187
Joined: 01 Oct 2013, 23:19

Re: Class_OD_Colors (für Holle)

Post by Holle » 29 Oct 2013, 07:58

Wow, vielen Dank!!!
Letzte Woche war ich im Urlaub, da hatte ich diesen Thread gar nicht bemerkt.

Ich weiß gar nicht wie ich dir danken soll, du hast mir schon so viel geholfen und nun sogar eine extra Class für mich geschrieben. Danke!!!

Allerdings habe ich da noch ein kleines Problem. Wenn ich das Test-Script ausführe bekomme ich noch eine Fehlermeldung:
"Class_OD_Colors.ahk (61) : ==> Call to nonexistent function."
"Specifically: StrSplit(Content, "
Edit: OK, wenn man die aktuelle Version von AHK benutzt klappts prima :lol:

Nochmal Edit:
:shock: Das ist PERFEKT !!! :shock:
Nun bin ich platt, das übertrifft alle meine Erwartungen. DANKE !!!!

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Class_OD_Colors (für Holle)

Post by KruschenZ » 22 Jan 2021, 02:28

Hallo just me,

also erst einmal vielen lieben Dank für diese sehr hilfreiche Klasse. Danke!

Mir ist jedoch aufgefallen, dass wenn eine DropDownList innerhalb einer Tab3 ist, dass diese dann nicht farbig wird.

PS: ich habe auch mal deine andere Klasse (Ctl_Colors) probiert, jedoch ist es da so, dass die farbige Unterstützung für DropDownLists nicht da ist und nur für ComboBoxen gilt, aber hier besteht auch der Sachverhalt, dass sobald die ComboBox in einem Tab3 ist, dass diese ebenfalls nicht farbig wird.

Hättest du hierfür einen Rat oder einen WorkAround?

Vielen lieben Dank.

Mit freundlichen Grüßen
KruschenZ
Last edited by KruschenZ on 22 Jan 2021, 07:46, edited 2 times in total.

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by just me » 22 Jan 2021, 05:41

Moin,

AHK's Tab3 Control ist ein besonderes Ding. Es ist tatsächlich ein Dialogfenster innerhalb des Gui-Fensters in das ein 'echtes' Tab Control eingebettet ist. Das 'Elternfenster' der enthaltenen Controls ist das Dialogfenster, und AHK ist darauf angewiesen, dass die an das Dialogfenster gesendeten Benachrichtigungen durchgereicht werden. Das scheint aber nicht immer zu klappen.

Wenn Du die Klasse(n) korrekt implementiert hast, würde ich auf einen solchen Fehler tippen.

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by just me » 22 Jan 2021, 06:43

Ich habe mir den AHK-Sourcecode angeschaut und aus der Vermutung ist Gewissheit geworden: Die WM_DRAWITEM Nachricht, auf der das Ganze basiert, wird vom Dialogfenster verschluckt.

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Class_OD_Colors (für Holle)

Post by KruschenZ » 22 Jan 2021, 07:09

Hallo just me,

vielen Dank für deine Antwort und Recherche.

Das ist leider sehr schade.
Zumal es bei z.B. Edit Fields wunderbar funktioniert.

Aber okay, dann ist es so, wie es ist.

Danke Dir.

Viele Grüße
KruschenZ

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by just me » 22 Jan 2021, 07:15

Warum muss es unbedingt ein Tab3 sein?

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Class_OD_Colors (für Holle)

Post by KruschenZ » 22 Jan 2021, 07:40

Hallo just me,

hab es mal eben mit einem Tab2 probiert, dann werden die Farben richtig dargestellt, jedoch, das erste was auffällt, ist, dass sich z.B. die Höhe nicht automatisch berechnet;
Das könnte ich noch bestimmt anpassen, daher okay.
Die Breite hat sich auch verändert, interessanter weise, okay, denke, das würde ich auch noch hinbekommen, weiß schon, woran das liegt :-)

Jetzt müssten nur alle Funktionen noch gehen, dazu muss ich das mal alles etwas länger durch testen.
Erster Eindruck => sieht gut aus.

Vermutlich kann ich Tab2 anstelle von Tab3 verwenden.

Danke Dir nochmal :-)

Viele Grüße
KruschenZ

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Class_OD_Colors (für Holle)

Post by KruschenZ » 08 Mar 2021, 05:35

Alle Tests erfolgreich abgeschlossen, fazit: Tab2 anstelle von Tab3 hilft total :D Danke Dir nochmal herzlich!

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by just me » 08 Mar 2021, 05:52

Bitte schön! ;)

User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Class_OD_Colors (für Holle)

Post by oldbrother » 18 Jan 2023, 07:58

Nice Lib! Thank you just me!

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class_OD_Colors (für Holle)

Post by jNizM » 28 Mar 2023, 07:40

Moin 'just me',

hast du OD_Colors zufällig schon irgendwo für v2 rumfliegen?

Ich kann zwar in v2 den Hintergrund einer (z.B. ListBox) verändern, soweit ich weiß aber nicht den "selected" Balken.

grüße
jNizM
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class_OD_Colors (für Holle)

Post by just me » 28 Mar 2023, 08:28

Moin @jNizM,

noch nicht, ich kann aber mal schauen was geht. Z.Zt. bin ich zu einer weiteren Reparatur im Krankenhaus. Es wird ein paar Tage dauern.

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Class_OD_Colors (für Holle)

Post by KruschenZ » 19 Apr 2023, 06:09

PS:
wenn man etwas rumspielt, kann man auch ein Hover-Highlight setzen mit den invertierten Farben von Hintergrund & Schrift.

Ich habe dazu nur "DrawItem()" angepasst:

Code: Select all

DrawItem(lParam, Msg, Hwnd)
	{
		; first param 'wParam' is passed as 'This'.
		; ----------------------------------------------------------------------------------------------------------------
		; Sent to the parent window of an owner-drawn ListBox or ComboBox when a visual aspect of the control has changed.
		; WM_DRAWITEM			-> http:;msdn.microsoft.com/en-us/library/bb775923(v=vs.85).aspx
		; DRAWITEMSTRUCT		-> http:;msdn.microsoft.com/en-us/library/bb775802(v=vs.85).aspx
		; ----------------------------------------------------------------------------------------------------------------
		; lParam / DRAWITEMSTRUCT offsets
		
		STATIC offItem := 8
		, offAction := offItem + 4
		, offState := offAction + 4
		, offHWND := offState + A_PtrSize
		, offDC := offHWND + A_PtrSize
		, offRECT := offDC + A_PtrSize
		, offData := offRECT + 16
		, ODT := {2: "LISTBOX", 3: "COMBOBOX"}
		, ODA_DRAWENTIRE := 0x0001
		, ODA_SELECT := 0x0002
		, ODA_FOCUS := 0x0004
		, ODS_SELECTED := 0x0001
		, ODS_FOCUS := 0x0010
		, DT_Flags := 0x24
		
		; ----------------------------------------------------------------------------------------------------------------
		
		Critical, 100 ; may help in case of drawing issues
		HWND := NumGet(lParam + offHWND, 0, "UPtr")
		
		If OD_Colors.Array_Controls.HasKey( HWND ) && ODT.HasKey(NumGet(lParam + 0, 0, "UInt"))
		{
			ODCtrl := OD_Colors.Array_Controls[ HWND ]
			, Item := NumGet(lParam + offItem, 0, "Int") + 1
			, Action := NumGet(lParam + offAction, 0, "UInt")
			, State := NumGet(lParam + offState, 0, "UInt")
			, HDC := NumGet(lParam + offDC, 0, "UPtr")
			, RECT := lParam + offRECT
			
			, Control_Color_Text := ODCtrl.Colors.T
			, Control_Color_Background := ODCtrl.Colors.B
			
			
			If (Action = ODA_FOCUS)
			{
				Return True
			}
			Else If (State & ODS_SELECTED)
			{
				;Highlight - Hover
				
				Color_Background := ODCtrl.Colors[ Item ].HasKey("B") ? ODCtrl.Colors[ Item ].B : Control_Color_Background
				, Color_Text := ODCtrl.Colors[ Item ].HasKey("T") ? ODCtrl.Colors[ Item ].T : Control_Color_Text
				, Brush := DllCall("Gdi32.DLL\CreateSolidBrush", "UInt", Color_Text, "UPtr")
				, DllCall("User32.DLL\FillRect", "Ptr", HDC, "Ptr", RECT, "Ptr", Brush)
				, DllCall("Gdi32.DLL\DeleteObject", "Ptr", Brush)
				, Text := ODCtrl.Items[ Item ]
				, Length := StrLen(Text)
				, NumPut(NumGet(RECT + 0, 0, "Int") + 4, RECT + 0, 0, "Int")
				, DllCall("Gdi32.DLL\SetBkMode", "Ptr", HDC, "Int", 1) ; TRANSPARENT
				, DllCall("Gdi32.DLL\SetTextColor", "Ptr", HDC, "UInt", Color_Background)
				, DllCall("User32.DLL\DrawText", "Ptr", HDC, "Ptr", &Text, "Int", Length, "Ptr", RECT, "UInt", DT_Flags)
				
				
				;DllCall("User32.DLL\DrawFocusRect", "Ptr", HDC, "Ptr", RECT)
			}
			Else
			{
				Color_Background := ODCtrl.Colors[ Item ].HasKey("B") ? ODCtrl.Colors[ Item ].B : Control_Color_Background
				, Color_Text := ODCtrl.Colors[ Item ].HasKey("T") ? ODCtrl.Colors[ Item ].T : Control_Color_Text
				, Brush := DllCall("Gdi32.DLL\CreateSolidBrush", "UInt", Color_Background, "UPtr")
				, DllCall("User32.DLL\FillRect", "Ptr", HDC, "Ptr", RECT, "Ptr", Brush)
				, DllCall("Gdi32.DLL\DeleteObject", "Ptr", Brush)
				, Text := ODCtrl.Items[ Item ]
				, Length := StrLen(Text)
				, NumPut(NumGet(RECT + 0, 0, "Int") + 4, RECT + 0, 0, "Int")
				, DllCall("Gdi32.DLL\SetBkMode", "Ptr", HDC, "Int", 1) ; TRANSPARENT
				, DllCall("Gdi32.DLL\SetTextColor", "Ptr", HDC, "UInt", Color_Text)
				, DllCall("User32.DLL\DrawText", "Ptr", HDC, "Ptr", &Text, "Int", Length, "Ptr", RECT, "UInt", DT_Flags)
				;, NumPut(NumGet(RECT + 0, 0, "Int") - 2, RECT + 0, 0, "Int")
			}
			
			;DllCall("Gdi32.DLL\SetTextColor", "Ptr", HDC, "UInt", Control_Color_Text)
			Return True
		}
	}
Viele Grüße
KruschenZ

Post Reply

Return to “Skripte und Funktionen”