[CLASS] CtlColors - color your controls (2017-10-30)

Post your working scripts, libraries and tools for AHK v1.1 and older
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [CLASS] CtlColors - color your controls (2017-10-30)

24 Dec 2018, 03:23

Hatsuko wrote:
23 Dec 2018, 07:08
Hi,

unfortunately I have no idea why colouring stops working. Apparently the hotkeys are triggered, logs are written and CtlColors.Change() is called. The garbled tooltips are an additional mystery.

You might try to call the UpdateWindow() function directly after each call of InvalidateRect().

Code: Select all

      ...
      DllCall("User32.dll\InvalidateRect", "Ptr", HWND, "Ptr", 0, "Int", 1)
      DllCall("User32.dll\UpdateWindow", "Ptr", HWND) ; <--- added
      ...
The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue.
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: [CLASS] CtlColors - color your controls (2017-10-30)

24 Dec 2018, 13:10

Portwolf wrote:
10 Dec 2018, 12:03
And i failed miserably..
I cannot understand how to do it..(...)
How do i set that up? i already added the hwndHTX but, cannot get it working.
I'm seeing a lot of code there that i almost dont understand..
Like many here, im pretty new to this.
Ok, i failed miserably because i was a dumbass....
Code was correct, but i was coloring it on the wrong order.
As the code went along, it was coloring the wrong elements.

Thank for the help boys :D
It was a question of error 16: dumbass user.

:trollface: :trollface:
Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

Re: [CLASS] CtlColors - color your controls (2017-10-30)

19 Jul 2019, 13:27

I am trying to change the background color of some edit controls. This works great if the control's parent is the window, but it doesn't seem to work if their parent is another control on the window. FWIW, I can't get CColor to work either. I can create the edit controls as children of the window, color them, then change their parent to the other control; however, after changing their parent, I can no longer change the color. Any ideas how I might work around this issue?

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

Re: [CLASS] CtlColors - color your controls (2017-10-30)

20 Jul 2019, 02:53

The class relies on WM_CTLCOLOR... notifications which are always send to the control's parent window. The message handler registered for the class does not receive the notifications. If you nevertheless want to use the class, subclassing the parent and calling CtlColors_OnMessage() directly for incoming WM_CTLCOLOR... messages or forwarding the message to the original parent might work.

Regards, just me
User avatar
lmstearn
Posts: 688
Joined: 11 Aug 2016, 02:32
Contact:

Re: [CLASS] CtlColors - color your controls (2017-10-30)

12 Sep 2019, 10:41

CtlColors is more portable than majkinetor's CColor, although that was documented to also support ListView, TreeView and RichEdit.
Originally tried for a listbox, SKAN's modified version of RegisterCallback from the docs, In that case, if there was more than one control in the script, a new RegisterCallback had to be coded per listbox, or else the script failed when attempting to apply the original callback on another control.
This is so much better, thanks. :)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
jsong55
Posts: 222
Joined: 30 Mar 2021, 22:02

Re: [CLASS] CtlColors - color your controls (2017-10-30)

30 Mar 2021, 22:13

I'm using the above class and the visual results are great.

However when I look at the last run lines it shows this

Code: Select all

289: if CtlColors.IsAttached(HWND)  
280: Return,This.Attached.HasKey(HWND)
299: }
288: Critical
289: if CtlColors.IsAttached(HWND)  
280: Return,This.Attached.HasKey(HWND)
299: } (0.06)
288: Critical
289: if CtlColors.IsAttached(HWND)  
280: Return,This.Attached.HasKey(HWND)
299: }
288: Critical
289: if CtlColors.IsAttached(HWND)  
280: Return,This.Attached.HasKey(HWND)
299: } (0.06)
288: Critical
289: if CtlColors.IsAttached(HWND)  
280: Return,This.Attached.HasKey(HWND)
299: }
288: Critical
289: if CtlColors.IsAttached(HWND)  
280: Return,This.Attached.HasKey(HWND)
299: } (0.81)
Hence I can't check my actual last run lines.

Here's a copy of my usage

Code: Select all

Gui, ab: Add, Edit, vRemarks x+section w500 hwndabcde r%remarks_row%, % Remarks
CtlColors.Attach(abcde,"B5838D","White")
jsong55
Posts: 222
Joined: 30 Mar 2021, 22:02

Re: [CLASS] CtlColors - color your controls (2017-10-30)

24 Apr 2021, 06:27

@justme if you can help with the above too will be good! :)
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [CLASS] CtlColors - color your controls (2017-10-30)

24 Apr 2021, 10:51

Don't know how to help you. The listed lines are the actually the most recently executed lines.
jsong55
Posts: 222
Joined: 30 Mar 2021, 22:02

Re: [CLASS] CtlColors - color your controls (2017-10-30)

24 Apr 2021, 13:08

Is it set to a timer or something? Because even if I run something, the isattached function runs latest. Is there no way to color the controls once and that's it?
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [CLASS] CtlColors - color your controls (2017-10-30)

25 Apr 2021, 06:55

CtlColors depends on the processing of CTL_COLOR... messages sent by the controls whenever they need to be redrawn. All listed lines you posted are related to controls not attached to the class. Unfortunately the OnMessage() function of AHK 1.1 cannot filter messages by HWND.
pv007
Posts: 93
Joined: 20 Jul 2020, 23:50

Re: [CLASS] CtlColors - color your controls (2017-10-30)

10 Jun 2021, 02:59

@just me is possible to control the transparency of the background? i mean with the option "trans" set the background transparency 50% or any value instead 100% transparent.
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [CLASS] CtlColors - color your controls (2017-10-30)

10 Jun 2021, 06:17

No! The function must return a GDI brush and GDI does not support semi-transparent brushes.
kauan014
Posts: 55
Joined: 18 Feb 2021, 20:03

Re: [CLASS] CtlColors - color your controls (2017-10-30)

02 Jul 2021, 19:20

Code: Select all

Gui, Add, Edit, w100 h100 hWndEdit, Testing Text
CtlColors.Attach(Edit, "Trans", "Aqua")
Gui, Show,  w300 h200, TEST
Return
@just me
Am i doing something wrong or the option Trans is not working?
Im using the current source in your github.
Spoiler
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [CLASS] CtlColors - color your controls (2017-10-30)

09 Jul 2021, 04:56

@kauan014:
Transparency is not really supported. If you change existing contents in an edit control it won't be 'cleared' because a transparent brush is used to draw the background.
kauan014
Posts: 55
Joined: 18 Feb 2021, 20:03

Re: [CLASS] CtlColors - color your controls (2017-10-30)

10 Jul 2021, 19:21

@just me is possible to change the shape of this brush? maybe create it with rounded border?
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [CLASS] CtlColors - color your controls (2017-10-30)

11 Jul 2021, 04:38

@kauan014, GDI brushes don't have 'shapes'. They are normally used to fill shapes.
kauan014
Posts: 55
Joined: 18 Feb 2021, 20:03

Re: [CLASS] CtlColors - color your controls (2017-10-30)

11 Jul 2021, 20:56

@just me I was searching for your script and i see your imagebutton lib, i wonder if in any of your scripts do you have an example of changing the shape of an edit control to rounded borders?
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [CLASS] CtlColors - color your controls (2017-10-30)

21 Jul 2021, 08:42

Is it possible to color DateTime Controls (just the Edit Control in DateTime) too?


Edit: maybe it is not possible with WM_CTLCOLOR
The WM_CTLCOLOR message from 16-bit Windows has been replaced by more specific notifications. These replacements include the following:

WM_CTLCOLORBTN
WM_CTLCOLOREDIT
WM_CTLCOLORDLG
WM_CTLCOLORLISTBOX
WM_CTLCOLORSCROLLBAR
WM_CTLCOLORSTATIC


This dont work correct for DateTime
https://www.autohotkey.com/boards/viewtopic.php?p=250851#p250851

more ref links:
https://stackoverflow.com/questions/67110084/how-to-change-the-background-color-of-the-datetime-picker-control
https://stackoverflow.com/questions/33930037/how-to-change-background-color-of-sysdatetimepick32-or-cdatetimectrl
https://stackoverflow.com/questions/67110084/how-to-change-the-background-color-of-the-datetime-picker-control
https://www.codeproject.com/Articles/30660/A-DateTimePicker-with-working-BackColor
https://comp.os.ms-windows.programmer.win32.narkive.com/0H8cHhw1/setting-color-for-sysdatetimepick32-control
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [CLASS] CtlColors - color your controls (2017-10-30)

22 Jul 2021, 08:38

Is this a bug or does I missed something in my code? Even with ReDraw the control lose the color after RightClick the ListView to open a Menu.
It is just the focused Edit Control who lose the color.

Image

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#NoEnv
#SingleInstance Force
#Persistent

SetBatchLines -1


; MENU ==========================================================================================================================

Menu, EditMenu, Add, % "Select All", MenuSelect
Menu, EditMenu, Add, % "Edit", MenuEdit
Menu, EditMenu, Add, % "Export", MenuExport
Menu, EditMenu, Add, % "Copy", MenuCopy
Menu, MenuBar, Add, Edit, :EditMenu


; GUI ===========================================================================================================================

Gui, Margin, 10, 10
Gui, Font, s10 normal, Segoe UI

Gui, Add, Edit, xm ym w300 hWndhEdt01
CtlColors.Attach(hEdt01, "EBF5EB", "")

Gui, Add, Edit, xm y+10 w300 hWndhEdt02
CtlColors.Attach(hEdt02, "EBF5EB", "")

Gui, Add, ListView, xm y+10 w300 r5 vLV01, % "A|B|C"
loop 3
	LV_Add("", "A_" A_Index, "B_" A_Index, "C_" A_Index)
LV_ModifyCol()

Gui, Show, AutoSize
Gui, +LastFound
WinSet, ReDraw
return


; WINDOW EVENTS =================================================================================================================

GuiClose:
GuiEscape:
	Gui, Destroy
	CtlColors.Free()
ExitApp


GuiContextMenu:
	if !(InStr(A_GuiControl, "LV01"))
		return
	Menu, EditMenu, Show, % A_GuiX, % A_GuiY
	Gui, %A_Gui%:+LastFound
	WinSet, ReDraw
return


MenuCopy:
	ControlGet, List, List, Selected, SysListView321
	Clipboard := List
return


MenuEdit:
return


MenuSelect:
	Gui, ListView, LV01
	LV_Modify(0, "Select")
return


MenuExport:
return


; INCLUDES ======================================================================================================================

#Include Class_CtlColors.ahk


; ===============================================================================================================================
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 151 guests