Class TransparentListBox

Post your working scripts, libraries and tools
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Class TransparentListBox

03 Oct 2013, 00:33

Update on 2015-01-17:
  • Added ability for scrolling by keys without having a vertical scroll bar.
  • Moved scripts to GitHub.

Update on 2013-10-05:
  • Added options to choose a background color for the selected item(s) and the transparency of this color.
  • Added scripts to the posting since we have spoilers now (THX).


Well, my first and exclusive contribution to the new forums.

I started to write this script by reason of this request. Another request can be found here. Both are pointing to the same example on CodeProject using an owner drawn ListBox.

When trying to port the code to AHK, I didn't find any advantage using the LBS_OWNERDRAWFIXED style. The whole painting has to be done by subclassing the control with AHK, so 'owner drawing' has to be done in either case.

This is what I've got so far. Sometimes you may notice some flickering. I didn't find a way to suppress all of it. Just a few other restrictions are documented in the class header.

:arrow: View sources on GitHub
:arrow: Download sources from GitHub
Last edited by just me on 17 Jan 2015, 04:20, edited 4 times in total.
Remaining with AHK 1.1.25.02 until v2 will become beta.
tmplinshi
Posts: 1092
Joined: 01 Oct 2013, 14:57

Re: Class TransparentListBox

03 Oct 2013, 05:38

Thanks. Will use it someday. :)
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
GitHub: Aatoz

Re: Class TransparentListBox

04 Oct 2013, 09:28

Not much to say besides this looks great! The current limitations, such as no smooth scrolling, is not a big deal to me. I'm going to start changing my current scripts to use this, such as CFlyout (which hasn't been ported to the new forum as of yet).

One comment/question. Depending on the background picture, it can be difficult to easily spot which item is selected. Is is feasible to give an option to set the selected text background color? I messed with this idea a little bit, and it was easy enough to set the background color for the selected text. The two problems I couldn't fix were:

1. Partial transparency for background color. I don't even know of something like that is possible, and maybe it isn't a big deal. I just wanted to see how it would look.
2. Background color needs to be drawn over the entire width of the ListBox, not the selected text.
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class TransparentListBox

05 Oct 2013, 03:38

Verdlin wrote: 1. Partial transparency for background color. I don't even know of something like that is possible, and maybe it isn't a big deal. I just wanted to see how it would look.
2. Background color needs to be drawn over the entire width of the ListBox, not the selected text.

Well, I tried my best. I've updated the first post, give it a try. ;)
Remaining with AHK 1.1.25.02 until v2 will become beta.
tmplinshi
Posts: 1092
Joined: 01 Oct 2013, 14:57

Re: Class TransparentListBox

05 Oct 2013, 08:03

Thanks, just me! I like the background color.

Image
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Class TransparentListBox

06 Oct 2013, 05:18

when i run, it complains about this line in Class_TransparentListBox.ahk: :lol:
This.Items := StrSplit(Content, "`n")
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Class TransparentListBox

06 Oct 2013, 05:40

added this and seems it took care of the prob. :lol:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Class TransparentListBox

06 Oct 2013, 05:53

where should i add code and how so that when i select a number (Five, for example) for content from the list, then i can run some action?: :lol:
if content = Five
then
run, some action
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Class TransparentListBox

06 Oct 2013, 06:32

is this how i should do this: :lol:
Selection:
GuiControlGet, LB
ToolTip, Selected: %LB%`nA_GuiEvent: %A_GuiEvent%`nA_EventInfo: %A_EventInfo%
SetTimer, KillTT, -750


If (LB == "Five")
MsgBox, Run Something...
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class TransparentListBox

06 Oct 2013, 07:11

Yes, the g-Label is working as for common ListBox controls.
Remaining with AHK 1.1.25.02 until v2 will become beta.
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
GitHub: Aatoz

Re: Class TransparentListBox

07 Oct 2013, 15:23

just me wrote:
Verdlin wrote: 1. Partial transparency for background color. I don't even know of something like that is possible, and maybe it isn't a big deal. I just wanted to see how it would look.
2. Background color needs to be drawn over the entire width of the ListBox, not the selected text.

Well, I tried my best. I've updated the first post, give it a try. ;)


Oh-ho, yes! This is awesome.
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
GitHub: Aatoz

Re: Class TransparentListBox

15 Oct 2013, 21:11

I've been wondering about the possibility of wrapping items in the ListBox. Since the class handles drawing, isn't this pretty doable?
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class TransparentListBox

16 Oct 2013, 06:59

It should be feasible, but not with this class. You have to set the the LBS_OWNERDRAWVARIABLE style and to processs the WM_MEASUREITEM and WM_DRAWITEM messages.
Remaining with AHK 1.1.25.02 until v2 will become beta.
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class TransparentListBox

17 Jan 2015, 04:15

Update on 2015-01-17 because of this request.
Remaining with AHK 1.1.25.02 until v2 will become beta.
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
GitHub: Aatoz

Re: Class TransparentListBox

11 May 2016, 05:05

So happy to see the scrolling update! I had been spending a lot of time trying to make that work and didn't think to check for an update until now :)

Sometime the border around the ListBox doesn't get redrawn (until MouseOver) happens. I fixed this bug by adding the code below right before "Return 0" in bloc that processes WM.Paint

; Must redraw rectangle around list box.
SendMessage, WM_NCPAINT:=133, 0, 0,, ahk_id %hWnd%
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
GitHub: Aatoz

Re: Class TransparentListBox

13 May 2016, 06:15

I would also recommend putting this at the beginning of WM.Paint right before the call to BitBlt

Code: [Select all] [Download] GeSHi © Codebox Plus

	; Update this.width and this.height in case a scrollbar was added or removed.
VarSetCapacity(RECT, 16, 0)
DllCall("User32.dll\GetClientRect", "Ptr", This.HLB, "Ptr", &RECT)
This.Width := W := NumGet(RECT, 8, "Int")
This.Height := H := NumGet(RECT, 12, "Int")
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class TransparentListBox

13 May 2016, 09:37

Hello Verdlin,

thanks for your suggestions. I'm working on it. The original design of the class was rather 'static'. So there might be more issues.
Remaining with AHK 1.1.25.02 until v2 will become beta.
carno
Posts: 83
Joined: 20 Jun 2014, 16:48

Re: Class TransparentListBox

13 May 2016, 12:45

Wow! Beautiful.
just me
Posts: 4865
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class TransparentListBox

16 May 2016, 04:18

Hello Verdlin,

I revised the class code trying to make it faster and maybe fixed a bug in SetRedraw(). Would you please test whether the non-client drawing issues still happen?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Regards, just me
Remaining with AHK 1.1.25.02 until v2 will become beta.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: ArdaS and 14 guests