GUI Listbox help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Listbox help

Post by Hellbent » 18 Feb 2021, 23:14

Also to change the number of items in the list you also need to change the variable that tracks it.

Code: Select all

;ListMax is the length of the list / the max value of your list
ListControls[ Index ] := { Positions: New HB_Vector( x , y ) , Hwnd: Hwnd , Center: New HB_Vector( x + ( w / 2 ) , y + ( h / 2 ) ) , Value: out , ListMin: 1 , ListMax: 6 } 
;It is possible to have different lists for each control. 

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 00:07

Nice that is alot smoother and stays blue, highlighted.
Hellbent wrote:
18 Feb 2021, 23:02
iilabs wrote:
18 Feb 2021, 22:29
Sometimes it doesn't highlight the number but if you go back over it it does and highlights it as blue but some are stuck in the non-selected mode unless clicked and then scrolled again to desire value. Will it still send the variable on a Submit? or is the highlighting critcal to send stored variable? Slider works well! Eager to learn and try out that GDIP one. Ill try figuring out the error.
I did a bunch of testing on my end but I can't get it to not highlight it in blue. Try changing the hotkey section of the code with this.

Code: Select all

#If ( WinActive( "ahk_Id " GuiHwnd ) &&  Closest := Distance( ListControls , MaxDistance ) )

WheelUp::
WheelDown::
	( A_ThisHotkey = "WheelUp" ) ? ( ( temp := ListControls[ Closest ].Value  - 1 )  >= ListControls[ Closest ].ListMin ) ? ( ListControls[ Closest ].Value := temp )
	( A_ThisHotkey = "WheelDown" ) ? ( ( temp := ListControls[ Closest ].Value  + 1 )  <= ListControls[ Closest ].ListMax  ) ? ( ListControls[ Closest ].Value := temp )
	GuiControl, 1: Choose, % ListControls[ Closest ].Hwnd , % ListControls[ Closest ].Value
	GuiControl, 1: +Redraw, % ListControls[ Closest ].Hwnd 
	return

#If
That has it redrawing the control after changing it.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 00:13

Oh, totally walked right passed that. The magic in your math is beyond me. Great! So can each box now independently send a value. I was wondering how I can remove the loop and instead of grid make different patterns based on anatomy being viewed? I see in windows spy they are all listed as ListBox1. So a Control to get the value for say box 1,3 wont work?

or is "% ListControls[ Index ].Hwnd" the indvidual handle, meaning ListControls1.Hwnd, ListControls2,hwnd?
Hellbent wrote:
18 Feb 2021, 23:10
iilabs wrote:
18 Feb 2021, 22:41
I tried to add and extra "|" before 1 in the ListOptions := "1|2|3|4|5|6" to default to 1 with every new gui load but didn't default. I tried adding Gui, destroy but that also did not reset the values.
Change:

Code: Select all

Gui, 1:Add, ListBox, % "x" x " y" y " w" w " h" h " Choose3 hwndhwnd", % ListOptions  ; "Choose"
;to
Gui, 1:Add, ListBox, % "x" x " y" y " w" w " h" h " Choose1 hwndhwnd", % ListOptions

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Listbox help

Post by Hellbent » 19 Feb 2021, 00:31

iilabs wrote:
19 Feb 2021, 00:13
I see in windows spy they are all listed as ListBox1. So a Control to get the value for say box 1,3 wont work?
Everything is tracked by the "ListControl" Array

So to get the values from box 1 and box 3 it would be

Code: Select all

msgbox, % ListControl[1].Value . ListControl[3].Value

Code: Select all

1,2,3,4,5
6,7,8,9,10
11,12,13,14,15
16,17,18,19,20
21,22,23,24,25

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 00:37

Oh I see. Wow, I'm going to stare at the code for a while and try to implement it tomorrow. instead of a loop, I guess I can individually arrange the list boxes according to x,y placement that suits the anatomy rather than a 5x5 grid we have at the moment?

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 00:44

Ok got this to finally work. Very nice. This is more of the feel I was going for. More discrete. I read the instructions for the scroll wheel but no lines are being drawn close to any of the boxes so far. Try a different gdip?

Hellbent wrote:
18 Feb 2021, 19:54
Here is a POC for you. Take a look at this and let me know if this is something that works for you.

Required Libraries:

Layered Window Class: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=72588

GDIP: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517


How to use:

1: Run the script ( Be sure to #Include the required libs)

2: When you first run the script you will see nothing, but if you move your mouse to the top of the screen you should see a small button fade in at the top left corner (the position can easily be changed)
.
20210218194938.png
.

3: Move your cursor away from the top of the screen and the button should fade out.

4: Move your Cursor to the top of the screen and right click the button, that will cause it to be hidden for 5 seconds ( this is in the case that it is in the way of something under it.)

5: Press the button. This will cause some hotkeys to become active and show the HUD Window
.
20210218195107.png
.
6: Press The button Again. This will turn off the hotkeys and hide the HUD Window

7: With the HUD active, wheel up or down close to one of the squares. This will cause the distance from your cursor to the center of the squares to be calculated. If the distance to the closest square is less than some amount, a line will be draw showing that a action will be triggered on that control.
.
20210218195232.png
.
Give it a go, and if it works for you I can get a more flushed out prototype made up.

.

Code: Select all

;***************************************************************************************************
#Include <LayeredWindow Class>
#Include <My Altered Gdip Lib>
;***************************************************************************************************
#SingleInstance, force
SetBatchLines, -1
CoordMode, Mouse, Screen
OnMessage(0x0200,"MouseMovement")
global Active , Reveal := 1
Trans := 0
Direction := 1
Com := 0
TriggerWindow := New LayeredWindow(x := 0 , y := 0 , w := A_ScreenWidth , h := 50 , window := "Trigger" , title := " " , smoothing := 2 , options := "+AlwaysOnTop -DPIScale +ToolWindow" , autoShow := 1 , GdipStart := 1 , WinMover := { x: 0 , y: 0 , w: w , h: 20 } , BackgroundColor := "0x0122262a")

Gui, ActivateWindow:+AlwaysOnTop -DpiScale +OwnerTrigger hwndActivateWindowHwnd -Caption
Gui, ActivateWindow:Color, 22262a
Gui, ActivateWindow:Add, Text, cWhite x0 y0 w80 h25 Border Center 0x200 gToggleHUD, Activate 
Gui, ActivateWindow:Show, x0 y0 w80 h25
WinSet , Transparent , % Trans , % "ahk_id " ActivateWindowHwnd

HUDWindow := New LayeredWindow(x := 0 , y := 0 , w := A_ScreenWidth , h := A_ScreenHeight , window := 1 , title := " " , smoothing := 2 , options := "+AlwaysOnTop +OwnerTrigger +E0x20" , autoShow := 1 )

HUDWindow.Draw_Rectangle(Thickness:="2",PosObj:={x:100,y:100,w:15,h:15},Color1:=0xFF880000,Color2:="",PosObj2:="",update:=0)
HUDWindow.Draw_Rectangle(Thickness:="2",PosObj:={x:300,y:150,w:15,h:15},Color1:=0xFF880000,Color2:="",PosObj2:="",update:=0)
HUDWindow.Draw_Rectangle(Thickness:="2",PosObj:={x:500,y:150,w:15,h:15},Color1:=0xFF880000,Color2:="",PosObj2:="",update:=0)
HUDWindow.Draw_Rectangle(Thickness:="2",PosObj:={x:530,y:150,w:15,h:15},Color1:=0xFF880000,Color2:="",PosObj2:="",update:=0)
HUDWindow.Draw_Rectangle(Thickness:="2",PosObj:={x:250,y:200,w:15,h:15},Color1:=0xFF880000,Color2:="",PosObj2:="",update:=0)
Button := []
Button[1] := New HB_Vector( 108 , 108 )
Button[2] := New HB_Vector( 308 , 158 )
Button[3] := New HB_Vector( 508 , 158 )
Button[4] := New HB_Vector( 538 , 158 )
Button[5] := New HB_Vector( 258 , 208 )
Gui, 1:Hide
return
GuiClose:
GuiContextMenu:
*ESC::ExitApp

#If (HUD)

WheelUP::
WheelDown::
	Distance := 1000000
	MouseGetPos, tx, ty
	MousePos := New HB_Vector(tx,ty)
	Loop, % Button.Length(){
		if( MousePos.Dist( Button[A_Index] ) < Distance ) 
			Distance := MousePos.Dist( Button[A_Index] ) , index := A_Index
	}
	if(Distance < 150){
		HUDWindow.Draw_Line(Thickness:="2",{x1:MousePos.X,y1:MousePos.Y,x2:Button[Index].X,y2:Button[Index].Y},Color1:="0xFF000000",Color2:="",Update:=1)
	}
	return

#If

ActivateWindowGuiContextMenu:
	SetTimer, Reveal, -5000
	Gui, ActivateWindow:Hide
	Reveal := 0
	return
	
Reveal:
	Gui, ActivateWindow:Show
	Reveal := 1
	WinSet , Transparent , % Trans := 0 , % "ahk_id " ActivateWindowHwnd
	return


Transition:
	if( Direction && !Com ){
		if( ( Trans += 20 ) < 255 ){
			WinSet , Transparent , % Trans , % "ahk_id " ActivateWindowHwnd
		}else{
			WinSet , Transparent , % Trans := 255 , % "ahk_id " ActivateWindow.Hwnd
			++Com
		}
		return
	}else if( !Direction && !Com ){
		if( ( Trans -= 20 ) > 0 ){
			WinSet , Transparent , % Trans , % "ahk_id " ActivateWindowHwnd
		}else{
			WinSet , Transparent , % Trans := 0 , % "ahk_id " ActivateWindowHwnd
			SetTimer, Transition, Off
			Direction := 1
			Active := 0
		}
		return
	}
	MouseGetPos,,my
	if(my>150){
		Direction := 0 , Com := 0
	}
	return

ToggleHUD:
	if( HUD := !HUD ){
		Gui, 1:Show
		HUDWindow.UpdateWindow()
	}else 
		Gui, 1:Hide
	return

MouseMovement(){
	if( A_Gui != "Trigger" && A_Gui != "ActivateWindow")
		return
	if( !Active && Reveal && Active := 1 ){
		SetTimer, Transition, 60
	}
}

Class HB_Vector	{
	__New(x:=0,y:=0){
		This.X:=x
		This.Y:=y
	}
	Add(Other_HB_Vector){
		This.X+=Other_HB_Vector.X
		This.Y+=Other_HB_Vector.Y
	}
	Sub(Other_HB_Vector){
		This.X-=Other_HB_Vector.X
		This.Y-=Other_HB_Vector.Y
	}
	mag(){
		return Sqrt(This.X*This.X + This.Y*This.Y)
	}
	magsq(){
		return This.Mag()**2
	}	
	setMag(in1){
		m:=This.Mag()
		This.X := This.X * in1/m
		This.Y := This.Y * in1/m
		return This
	}
	mult(in1,in2:="",in3:="",in4:="",in5:=""){
		if(IsObject(in1)&&in2=""){
			This.X*=In1.X 
			This.Y*=In1.Y 
		}else if(!IsObject(In1)&&In2=""){
			This.X*=In1
			This.Y*=In1
		}else if(!IsObject(In1)&&IsObject(In2)){
			This.X*=In1*In2.X
			This.Y*=In1*In2.Y
		}else if(IsObject(In1)&&IsObject(In2)){
			This.X*=In1.X*In2.X
			This.Y*=In1.Y*In2.Y
		}	
	}
	div(in1,in2:="",in3:="",in4:="",in5:=""){
		if(IsObject(in1)&&in2=""){
			This.X/=In1.X 
			This.Y/=In1.Y 
		}else if(!IsObject(In1)&&In2=""){
			This.X/=In1
			This.Y/=In1
		}else if(!IsObject(In1)&&IsObject(In2)){
			This.X/=In1/In2.X
			This.Y/=In1/In2.Y
		}else if(IsObject(In1)&&IsObject(In2)){
			This.X/=In1.X/In2.X
			This.Y/=In1.Y/In2.Y
		}	
	}
	dist(in1){
		return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
	}
	dot(in1){
		return (This.X*in1.X)+(This.Y*In1.Y)
	}
	cross(in1){
		return This.X*In1.Y-This.Y*In1.X
	}
	Norm(){
		m:=This.Mag()
		This.X/=m
		This.Y/=m
	}
}

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Listbox help

Post by Hellbent » 19 Feb 2021, 00:48

iilabs wrote:
19 Feb 2021, 00:37
Oh I see. Wow, I'm going to stare at the code for a while and try to implement it tomorrow. instead of a loop, I guess I can individually arrange the list boxes according to x,y placement that suits the anatomy rather than a 5x5 grid we have at the moment?
you can still use a loop, you just need to create an array of positions to pass as it loops.

Code: Select all

PositionsArray := []
PositionsArray[1] := { X: 100 , Y: 100 }
PositionsArray[2] := { X: 150 , Y: 100 }
PositionsArray[n] := ...

Loop, % PositionsArray.Length(){
	Gui, 1:Add, ListBox, % "x" PositionsArray[ A_Index ].X " y" PositionsArray[ A_Index ].Y " w15 h15 hwndhwnd choose1" , % List  ; or perhaps List[ A_Index ]
}


User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 08:26

Awesome, arrays is this is exactly what I want to learn as well. This is going to help a lot.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 11:23

Not sure if I did this correctly.

This is how I implemented the new snippet. I changed
  • % List
to
  • % ListOptions
and added the line in the previous loop. Seems to work.

However, after a few minutes of not fiddling with it, if I go back, then it scrolls but loses the blue highlighting.

So I made the orange progress bar by control since I think it has to do with the transparency i set learned from one of your tutorials.
So now it works if I grab the orange box first and then make adjustments. Anyway to make it so if your close to the orange progress that it win activates this script and keeps the blue highlighted text. If not I can work with this by reloading or moving thr gui around to activate it.

Also you mentioned in the script that I can have different lists for each control. Much like the array and make for listoptions?

Code: Select all

ListOptions := []
ListOptions[1] := "0|1|2|3|4|5|6"
ListOptions[2] := "a|b|c|d|e|f|g"

	Gui, 1:Add, ListBox, % "x" PositionsArray[ A_Index ].X " y" PositionsArray[ A_Index ].Y " w15 h15 hwndhwnd choose1", % ListOptions [ A_Index ]
Somehow this didn't work. ill keep hacking at it.


Any ideas why your other layered script using GDIP doesn't work? It seems like that would work better in long run but I can work with this list one for sure. Still miles ahead compared to before. Thanks HellBent!
Attachments
image.png
image.png (1.6 KiB) Viewed 756 times

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 22:27

image.png
image.png (105.64 KiB) Viewed 745 times
I was able to help with the highlighting problem by putting a progress at top of the counter box. if I select it, the GUI is activated and stays blue on scrolls. This actually works pretty good since I scan scroll the images without worrying that its adjusting values if I get close to it and if I want to input values, I reactivate it by clicking on one of the orange tabs (progress) at top and can move the entire GUI as well.

Thanks, I think this will work out great. I will keep at it and let you know my progress. Thanks Hellbent!

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 19 Feb 2021, 22:53

image.png
image.png (41.92 KiB) Viewed 722 times
Is it possible to add another variable that if a user is under one of those progress colors and scroll to change number it also adds Right, Left, or Bilateral when Gui, submits? For example, second box from left if i,m changing the number and under the orange progress bar it sends, 3, Bilateral?

i was thinking some kind of mouse get position or use your coding used for scrolling the numbers to the color progress bars?

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Listbox help

Post by Hellbent » 19 Feb 2021, 23:45

I haven't had a chance to read over your last comments yet so i'll have to circle back to them in a bit.

In the meantime I have worked on the GDIP solution a bit and here is where it stands for the moment.

I'll put off going over all the in's and outs for the moment, I just want to see if you can get it working for now.

Run this, then press numpad1 to allow the values to be changed by using your mouse wheel.

Code: Select all

;***************************************************************************************************
#Include <My Altered Gdip Lib>
#Include <LayeredWindow Class>
;***************************************************************************************************

#SingleInstance, Force
SetControlDelay, -1
SetBatchLines, -1
#NoEnv

HUD := New LayeredWindow(x := 0 , y := 0 , w := A_ScreenWidth , h := A_ScreenHeight , window := "1" , title := "HUDWINDOW" , smoothing := 2 , options := "+AlwaysOnTop -DPIScale +E0x20 +ToolWindow" , autoShow := 1 , GdipStart := 1 )

TargetListGraphics.UpdateDefaults( {MaxIndex: 30 , Width: 25 , Value: 5} )
TargetList.DebugState := "0x550099FF"
TargetList.MaxDistance := 50
x:= 0
Loop, 10	{
	TargetList.Add( { X: x+=110 , Y: A_ScreenHeight / 2 , Name: "Somevalue " A_Index} )
}
TargetList.Add({X:300 , BackgroundColor: "0xFF3399FF" , FontSize: 16 , FontColor: "0xFF000000" , BorderColor: "0xFF000000" , Width: 25 , Height: 25 , MaxIndex: 15, Value: 8})
TargetList.Debug( HUD.G )
TargetList.Draw( HUD.G )
HUD.UpdateWindow()

return
GuiClose:
GuiContextMenu:
*ESC::ExitApp

Numpad1::
	Active := !Active
	return

#If (Active)
WheelUp::
WheelDown::
	if( !SelectedTarget := TargetList.CheckTarget() )
		return
	TargetList.IncrementValue( (A_ThisHotkey = "WheelUp") ? ( 0 ) : ( 1 ) , SelectedTarget )
	HUD.ClearWindow()
	if( TargetList.DebugState )
		TargetList.Debug( HUD.G )
	TargetList.Draw( HUD.G )
	HUD.UpdateWindow()
	return
#If

Class TargetList	{
	static Targets := [] , Index := 0 , MaxDistance := 150
	Add(obj){
		TargetList.Index++
		TargetList.Targets[ TargetList.Index ] := New TargetListGraphics( obj )
	}
	IncrementValue( Dir := 1 , SelectedTarget := 1 ){
		local temp
		if(Dir){
			if( ( temp := TargetList.Targets[SelectedTarget].Value + 1 ) <= TargetList.Targets[SelectedTarget].MaxIndex ){
				TargetList.Targets[SelectedTarget].Value := temp
			}
		}else{
			if( ( temp := TargetList.Targets[SelectedTarget].Value - 1 ) >= 1 ){
				TargetList.Targets[SelectedTarget].Value := temp
			}
		}
	}
	CheckTarget(){
		local Distance := 1000000 , Dist , x , y , Mouse := {} , SelectedTarget
		CoordMode, Mouse, Screen
		MouseGetPos, x , y
		Mouse := New HB_Vector( x , y )
		Loop, % TargetList.Index	{
			if( ( Dist := Mouse.Dist( TargetList.Targets[ A_Index ].Center ) ) < Distance )
				Distance := Dist , SelectedTarget := A_Index
		}
		if( Distance <= TargetList.MaxDistance )
			Return SelectedTarget
		return 0
	}
	Debug( G ){
		Loop, % TargetList.Index	{
			TargetList.Targets[ A_Index ].Debug( G )
		}
	}
	Draw( G ){
		Loop, % TargetList.Index	{
			TargetList.Targets[ A_Index ].Draw( G )
		}
	}
}

Class TargetListGraphics	{
	static Updated 
	UpdateDefaults( obj ){
		TargetListGraphics.Updated := 1
		TargetListGraphics.Defaults := {}
		This._SetDefults()
		This._GetCenter()
		for k, v in This
			TargetListGraphics.Defaults[ k ] := v
		for k, v in obj
			TargetListGraphics.Defaults[ k ] := v
	}
	__New( obj := "" ){
		This._SetDefults()
		if( TargetListGraphics.Updated )
			for k, v in TargetListGraphics.Defaults
				This[ k ] := v
		for k, v in obj
			This[ k ] := v
		This._GetCenter()
	}
	_GetCenter(){
		This.Center := New HB_Vector( This.X + ( This.Width / 2 ) , This.Y + ( This.Height / 2 ) )
	}
	_SetDefults(){
		This.Value := 1 , This.X := 50 , This.Y := 50 , This.Width := 15 , This.Height := 15 , This.CanUpdate := 1
		This.Font := "Segoe UI" , This.FontColor := "0xFFA2A6AA" , This.FontSize := 12 , This.FontOptions := "Center vcenter"
		This.MaxIndex := 5 , This.BackgroundColor := "0xFF22262A" , This.BorderColor := "0xFFa2a6aa"
	}
	Debug( G ){
		Brush := Gdip_BrushCreateSolid( TargetList.DebugState )
		Gdip_FillEllipse( G , Brush, This.Center.X - TargetList.MaxDistance , This.Center.Y - TargetList.MaxDistance, TargetList.MaxDistance * 2 , TargetList.MaxDistance * 2 )
		Gdip_DeleteBrush( Brush )
	}
	Draw(G){
		Brush := Gdip_BrushCreateSolid( This.BackgroundColor ) , Pen := Gdip_CreatePen( This.BorderColor , 2 )
		Gdip_FillRectangle( G , Brush , This.Center.X - ( This.Width / 2 ) , This.Center.Y - ( This.Height / 2 ) , This.Width , This.Height )
		Gdip_DrawRectangle( G , Pen, This.Center.X - ( This.Width / 2 ) , This.Center.Y - ( This.Height / 2 ) , This.Width , This.Height )
		Gdip_DeleteBrush( Brush )
		Brush := Gdip_BrushCreateSolid( This.FontColor )
		Gdip_TextToGraphics( G , This.Value , " s" This.FontSize " " This.FontOptions " c" Brush " x" This.Center.X - ( This.Width / 2 ) " y" This.Center.Y - ( This.Height / 2 ) + 1 , This.Font , This.Width , This.Height )
		Gdip_DeleteBrush( Brush ) , Gdip_DeletePen( Pen )
	}
}

Class HB_Vector	{
	__New(x:=0,y:=0){
		This.X:=x , This.Y:=y
	}
	dist(in1){
		return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
	}
}
20210220013247.png
20210220013247.png (77.88 KiB) Viewed 665 times
Last edited by Hellbent on 20 Feb 2021, 01:34, edited 1 time in total.

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Listbox help

Post by Hellbent » 20 Feb 2021, 01:23

iilabs wrote:
19 Feb 2021, 22:53
image.png

Is it possible to add another variable that if a user is under one of those progress colors and scroll to change number it also adds Right, Left, or Bilateral when Gui, submits? For example, second box from left if i,m changing the number and under the orange progress bar it sends, 3, Bilateral?

i was thinking some kind of mouse get position or use your coding used for scrolling the numbers to the color progress bars?
Would it work for you to have another list beside ( Buddy ) that has it's own range of values? For example "R|L|B"

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 20 Feb 2021, 08:37

Thank you Hellbent! Sorry to bombard you will all this. Has been an amazing week with your help. I’ll slow down and learn from the code. This has been a tremendous help.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 20 Feb 2021, 09:07

The GDIP one worked like a charm. Seems more stable and less flickering than the native listbox! Thank you for spending the time!

Really liked the blue bubble/cloud idea.

I wonder if you can help me make that blue circle it into a clock face? If I can scroll based on where I am on the clock when I scroll would be awesome. For example if i'm at the 6'oclck and scroll it can send value as well as clock position so I can map it out to say, "Central disc bulge causing moderate canal stenosis." Moderate would be like a 3 from a range of (1-5) for example and 6' O'Clock would be "Central"

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 20 Feb 2021, 11:23

Yes that will work as well with a R,C,L as you suggested. I tried playing with letters on the ListBox script you wrote but it didn't scroll, but if I used different patterns of numbers it did work. Maybe something to do with numbers versus strings?

Are you using your HB Bitmap Maker for those transparent dials?

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

Re: GUI Listbox help

Post by just me » 22 Feb 2021, 08:33

Rather late but nontheless: A proof of concept for common list boxes (seems to work stable here):

Code: Select all

#NoEnv
#SingleInstance, Force
SetBatchLines, -1

ListBoxes := 13
Global CurrentLB := 0

Gui, +HwndGuihwnd
Gui, +AlwaysOnTop +ToolWindow +LastFound -Caption ; +E0x08000000
Gui, Color, 000111
WinSet, Transcolor, 000111
Gui, Margin, 0, 0
Gui, Add, Edit, w0 h0 +Readonly  ; this control will get the focus
Gui, Add, Progress, x152 y95  w10  h10  BackgroundCC6633 Disabled
; -0x300000 : -HScroll -VScroll, always choose the last item
Gui, Add, ListBox,  x150 y110 w20  h20  -0x300000 Choose6 vLB1  hwndHLB1,  T1|12|23|34|45|5S ; h15
Gui, Add, CheckBox, x150 y0   w15  h20
Gui, Add, CheckBox, x150 y20  w15  h20
Gui, Add, ListBox,  x170 y40  w15  h20  -0x300000 Choose5 vLB2  hwndHLB2,  0|1|2|3|4|5
Gui, Add, ListBox,  x130 y40  w15  h20  -0x300000 Choose5 vLB3  hwndHLB3,  0|1|2|3|4|5
Gui, Add, ListBox,  x150 y40  w15  h20  -0x300000 Choose5 vLB4  hwndHLB4,  0|1|2|3|4|5
Gui, Add, ListBox,  x0   y70  w15  h20  -0x300000 Choose5 vLB5  hwndHLB5,  0|1|2|3|4|5
Gui, Add, ListBox,  x20  y70  w15  h20  -0x300000 Choose5 vLB6  hwndHLB6,  0|1|2|3|4|5
Gui, Add, ListBox,  x40  y70  w15  h20  -0x300000 Choose5 vLB7  hwndHLB7,  0|1|2|3|4|5
Gui, Add, ListBox,  x130 y70  w15  h20  -0x300000 Choose5 vLB8  hwndHLB8,  0|1|2|3|4|5
Gui, Add, ListBox,  x150 y70  w15  h20  -0x300000 Choose5 vLB9  hwndHLB9,  0|1|2|3|4|5
Gui, Add, ListBox,  x170 y70  w15  h20  -0x300000 Choose5 vLB10 hwndHLB10, 0|1|2|3|4|5
Gui, Add, CheckBox, x150 y140 w15  h20
Gui, Add, ListBox,  x50 y150  w15  h20  -0x300000 Choose5 vLB11 hwndHLB11, 0|1|2|3|4|5
Gui, Add, ListBox,  x70 y150  w15  h20  -0x300000 Choose5 vLB12 hwndHLB12, 0|1|2|3|4|5
Gui, Add, ListBox,  x90 y150  w15  h20  -0x300000 Choose5 vLB13 hwndHLB13, 0|1|2|3|4|5

; ~MButton & RButton::
; MouseGetPos, xpos, ypos
; xpos := xpos - 155
; ypos := ypos  - 100
; Gui, Show, Autosize x%xpos% y%ypos%

Gui, Show, , Test
GoSub, ResetIt
; SetTimer, HideIt, 5000
; SetTimer, SendIt, 5000
; Gosub, SendIt
; msgbox, %listbox9%
OnMessage(0x020A, "WM_MOUSEWHEEL")
Return

^+r::
ResetIt:
   Loop, %ListBoxes%
      GuiControl, Choose, LB%A_Index%, 1
Return

SendIt:
   Gui, Submit, NoHide
   Values := ""
   Loop, %ListBoxes%
      Values .= "LB" . A_Index . ": " . LB%A_Index% . "`n"
   ToolTip, %Values%
Return

Numpad1::
   If (Active := !Active)
      SetTimer, SendIt, 5000
   Else
      SetTimer, SendIt, Off
Return

HideIt:
   Gui, Hide
Return

GuiClose:
GuiEscape:
ExitApp

WM_MOUSEWHEEL(W, L, M, H) {
   ; LB_GETCOUNT = 0x018B, LB_GETCURSEL = 0x0188, LB_GETTOPINDEX = 0x018E, LB_SETCURSEL = 0x0186
   ; WM_VSROLL = 0x0115, SB_LINEUP = 0, SB_LINEDOWN = 1
   Static VKD := GetKeyVK("Down"), SCD := GetKeySC("Down") << 15
        , VKU := GetKeyVK("Up"),   SCU := GetKeySC("Up") << 15
   ; Critical
   If (A_GuiControl ~= "^LB\d+$") {
      If (W & 0x80000000)
         DllCall("SendMessage", "Ptr", H, "UInt", 0x100, "Ptr", VKD, "Ptr", SCD)
      Else
         DllCall("SendMessage", "Ptr", H, "UInt", 0x100, "Ptr", VKU, "Ptr", SCU)
   }
   Return 0
}

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Listbox help

Post by Hellbent » 22 Feb 2021, 09:03

just me wrote:
22 Feb 2021, 08:33
Rather late but nontheless: A proof of concept for common list boxes (seems to work stable here):
That's very nice just me, works well as far as I can tell. Is there a way that it can:

1: Scroll when the gui isn't active.
2: Scroll the closest control to the cursor and not the control that has focus. (or the control that is directly under the cursor (using the hwnd likely))

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: GUI Listbox help

Post by Hellbent » 22 Feb 2021, 10:41

@just me

I have this which does what I was asking about, but iilabs had mentioned that it sometime glitches the graphics for the control and I'm not sure if the code you have fixes any graphical glitches.

.
20210222103852.png
20210222103852.png (10.25 KiB) Viewed 574 times
.

Code: Select all

#SingleInstance, force
SetBatchLines, -1
global GuiHwnd
Gui, 1: +AlwaysOnTop -DPIScale HwndGuiHwnd
Gui, 1: Color, 22262A
MaxDistance := 50
ListControls := []
ListOptions := "1|2|3|4|5"
y := 10 , w := 15 , h := 15 , Index := 1
Loop, 5	{
	x := 10	
	Loop, 5	{
		Gui, 1:Add, ListBox, % "x" x " y" y " w" w " h" h " Choose3 hwndhwnd", % ListOptions
		GuiControlGet, out, 1:, % hwnd
		ListControls[ Index ] := { Positions: New HB_Vector( x , y ) , Hwnd: Hwnd , Center: New HB_Vector( x + ( w / 2 ) , y + ( h / 2 ) ) , Value: out , ListMin: 1 , ListMax: 5 }
		x += 100 , Index++
	}
	y += 100
}
Gui, 1:Add, Text, x0 y0 w0 h0 hwndFhwnd
GuiControl, Focus, % Fhwnd
Gui, Show, y100
return
GuiClose:
GuiContextMenu:
*ESC::ExitApp
Distance( obj , MaxDistance ){
	local x, y, Dist, Distance := 1000000, Target
	CoordMode, Mouse, Screen
	WinGetPos, wx, wy ,,, % "ahk_Id " GuiHwnd
	MouseGetPos, x, y
	MousePosition := New HB_Vector(x-(wx+5),y-(wy+24))
	loop, % obj.Length()	{
		if( ( Dist := MousePosition.Dist( obj[ A_Index ].Center ) ) < Distance && Distance := Dist ){
			Target := A_Index
		}
	}
	if( Distance < MaxDistance )
		return Target
	else 
		return 0
}
#If ( Closest := Distance( ListControls , MaxDistance ) )
WheelUp::
WheelDown::
	if( A_ThisHotkey = "WheelUp" ){
		if( ( temp := ListControls[ Closest ].Value  - 1 )  >= ListControls[ Closest ].ListMin  && ListControls[ Closest ].Value := temp )
			GuiControl, 1: Choose, % ListControls[ Closest ].Hwnd , % ListControls[ Closest ].Value
	}else{
		if( ( temp := ListControls[ Closest ].Value  + 1 )  <= ListControls[ Closest ].ListMax  && ListControls[ Closest ].Value := temp )
			GuiControl, 1: Choose, % ListControls[ Closest ].Hwnd , % ListControls[ Closest ].Value
	}
	Gui, 1:Submit, NoHide
	return
#If
Class HB_Vector	{
	__New(x:=0,y:=0){
		This.X:=x,This.Y:=y
	}
	dist(in1){
		return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
	}
}
I can't get the same glitch to happen on my end though. I am pretty sure that it is just a graphical issue, but can't say for sure.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: GUI Listbox help

Post by iilabs » 22 Feb 2021, 11:12

Thanks for testing it out, Just me!

Hellbent working on A GDIP version that seems to be more stable. Trying to learn gdip in the meanwhile.

Over the weekend I was wondering if there is a different way to accomplish what I need from this crafty HUD? Maybe I’m boxing the creativity for you GUI experts since I have limited know-how?


Ideally, I would-like to scroll through anatomy ( currently displayed like a picture book, 1 image at a time in a stack, and flipped using scroll wheel.) If I see an abnormality say on a spine MRI like foraminal narrowing (tunnel where the nerve exits from the spinal cord) and If I wanted to say Moderate, Right foraminal narrowing I would like to create a menu that I can access maybe that shows up when scroll is stopped, then I scroll near the GUI control either right or left of it, to a counter number that is set for moderate ( 1 for mild, 2 for mild to moderate, 3 for moderate etc). I would like to use the same for canal stenosis stenosis and access it by placing mouse at a different coordinates on the screen (more center of screen) since canal more central versus foramen more lateral on the body. Maybe have different dials like Hellbent’s on a clock face for location (right, left, central, superior, inferior, etc.) a counter for severity using scroll?

This has been fascinating!

Post Reply

Return to “Ask for Help (v1)”