Sign in to follow this  
Followers 0
Particle

Port Database Slider

9 posts in this topic

hello. i'm trying to write a port database to where it runs from a slider. the more u slide the slider to the right, the higher the number goes(max 65535). also whenever the slider is on a certain port number it will display some gui label of a description about the port. how can i make this all happen?

honestly all i got is this for u guys to work with(snipit from the whole program):

$portnumb = 1
GuiCtrlCreateTabItem("Port Database")
GuiCtrlCreateLabel("Slider:", 40, 40)
GuiCtrlCreateLabel($portnumb, 430, 40)
GuiCtrlCreateSlider(70, 40, 350, 20)
GuiCtrlSetData(-1, 0)

Share this post


Link to post
Share on other sites



Sounds lengthy...one problem is the slider control doesnt like to hold 65535 tick marks :)

If you break it into smaller chucks per slider maybe it's easier... here's an example using a simple .ini file as your database (only has the first 5 ports):

#include <guiconstants.au3>
Opt("GUIoneventmode",1)
GUICreate("GUI",950,350)
GUICtrlCreateLabel("0-99",10,10,50)
GUICtrlCreateLabel("100-199",10,40,50)
$slider=GUICtrlCreateSlider(60,10,850,20)
GUICtrlSetLimit (-1, 99)
GUICtrlSetOnEvent (-1, "update")
$slider2=GUICtrlCreateSlider(60,40,850,20)
GUICtrlSetLimit (-1, 199,100)
GUICtrlSetOnEvent (-1, "update")
GUISetOnEvent($GUI_EVENT_CLOSE, "Aclose")
GUISetState(@SW_SHOW)
$label=GUICtrlCreateLabel("",10,70,500)
while 1
WEnd
func update()
        $read=GUICtrlRead(@GUI_CTRLID)
        $val=IniRead(@ScriptDir&"\db.ini","desc",$read,"None")
        GUICtrlSetData($label,"Port "&$read&": "&$val)
EndFunc
func aclose()
    Exit
EndFunc

ini file-

[desc]
0=Reserved
1=TCP Port ServiceMultiplexer
2=Management Utility
3=Compression Process
4=Unassigned
5=Remote Job Entry

Share this post


Link to post
Share on other sites

A slight variation...

now it just needs the Math to convert -32768 To +32767 To 0 To 65535

edited from a post by MsCreatoR, example of using GUIRegisterMsg for slider

with addition of readonly input edit to eliminate gui label flicker

#include <guiconstants.au3>
Opt("GUIoneventmode",1)
#include <GuiSlider.au3>

Global Const $WM_HSCROLL = 0x0114
Global Const $WM_VSCROLL = 0x0115

GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL")
;GUIRegisterMsg($WM_VSCROLL, "WM_HVSCROLL") ; for vertical slider

GUICreate("GUI",950,350)
GUICtrlCreateLabel("Port",10,10,50)

$slider=GUICtrlCreateSlider(80,10,850,40,$TBS_AUTOTICKS)
GUICtrlSetLimit($slider, 32767, -32768)
GUICtrlSetData($slider, -32768)

$h_slider = GUICtrlGetHandle($slider)
_GUICtrlSliderSetLineSize($h_slider, 1)
_GUICtrlSliderSetPageSize($h_slider, 50)
_GUICtrlSliderSetTicFreq($h_slider, 1000)

$input = GUICtrlCreateInput("-32768", 35, 10, 40, 20, $ES_READONLY, $WS_EX_TRANSPARENT)

GUISetOnEvent($GUI_EVENT_CLOSE, "Aclose")
GUISetState(@SW_SHOW)
$label=GUICtrlCreateLabel("",10,70,500)

while 1
    Sleep(10)
WEnd

Func aclose()
    Exit
EndFunc

; WM_HSCROLL and WM_VSCROLL event handler, intercepts Slider/Trackbar messages
Func WM_HVSCROLL($hWndGUI, $MsgID, $WParam, $LParam)
    Switch $LParam
        Case GUICtrlGetHandle($slider)
             $read=GUICtrlRead($slider)
             GUICtrlSetData($input, $read)
        $val=IniRead(@ScriptDir&"\db.ini","desc",$read,"None")
        GUICtrlSetData($label,"Port "&$read&": "&$val)
    EndSwitch
EndFunc

I see fascists...

Share this post


Link to post
Share on other sites

evilertoaster is right. You will never get that many ticks on a slider. Even if you did the user would never be able to get it to stop on a particular port. I would use an Updown control. That way you can choose between scrolling through the ports or manually entering a port.

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)
$GUI=GUICreate("updown",300,200,-1,-1, $WS_SIZEBOX)
GUISetOnEvent($GUI_EVENT_CLOSE, "Xit")
$input = GUICtrlCreateInput ("10",20,20)
$updown = GUICtrlCreateUpdown($input)
GUICtrlSetPos($input, 10,10, 200, 25 )
GUICtrlSetOnEvent($input, "info")
; Add your labels
GUISetState (@SW_SHOW)
While 1
Sleep(50000);GUIOnEventMode has precedence over sleep time
Wend

Func info()
msgbox(0,"Updown",GUICtrlRead(@GUI_CTRLID))
; Database stuff
Return
EndFunc

Func Xit()
Exit
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

evilertoaster is right. You will never get that many ticks on a slider. Even if you did the user would never be able to get it to stop on a particular port. I would use an Updown control. That way you can choose between scrolling through the ports or manually entering a port.

EDIT Updated with code example of slider with 65535 positions

don't need to see the ticks

any of the arrow keys will move the slider 1 tick, (1 port) for fine adjustment

and the gui is instantly updated smoothly as the slider is moved

pg/up down keys work as well

also the input edit box used as a label could have the readonly style removed and be used to input

port numbers directly, then on Enter the slider position could be updated.

and the GUICtrlCreateUpdown ctrl can be added.

just tried adding the up/dn box and editable input, all works.

just needs the math for the slider numbers, don't know if thats possible....

done..

working 0 to 65535 ports slider

tried with rough port list

Up/Dn needs work setting slider to input value with buttons but overall

proof of concept

yes it is a bit extreme, just to demonstrate it could be done.

done...

UP/DN spinner limited to -32768 To 32768, wont work without some sort of handler / hack

or custom spinner with buttons

#include <guiconstants.au3>
#include <GuiSlider.au3>
Opt("GUIoneventmode",1)

Global Const $WM_HSCROLL = 0x0114
Global Const $WM_VSCROLL = 0x0115

GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL")

GUICreate("GUI",550,350)
GUICtrlCreateLabel("Port",10,13,50)

$slider=GUICtrlCreateSlider(120,10,400,40,$TBS_AUTOTICKS)
GUICtrlSetLimit($slider, 32767, -32768)
GUICtrlSetData($slider, -32768)

$h_slider = GUICtrlGetHandle($slider)
_GUICtrlSliderSetLineSize($h_slider, 1)
;_GUICtrlSliderSetPageSize($h_slider, 10)
_GUICtrlSliderSetTicFreq($h_slider, 1000)

$input = GUICtrlCreateInput("-32768", 35, 10, 40, 20, $ES_NUMBER)
GUICtrlSetLimit($input,5)   ; to limit the entry to 5 chars
GUICtrlSetOnEvent($input, "Inputupdate")

$updown = GUICtrlCreateUpdown($input,$UDS_NOTHOUSANDS+$UDS_ARROWKEYS) ; BitOR($UDS_NOTHOUSANDS,$UDS_ARROWKEYS,$UDS_WRAP)
GUICtrlSetLimit($updown, 32767, 0)
GUICtrlSetPos($input, 35,10, 80, 40 )


GUISetOnEvent($GUI_EVENT_CLOSE, "Aclose")
GUISetState(@SW_SHOW)
GUICtrlCreateLabel("Enter Port Number or use UP/DN and < > Keys",10,55,120,50)
$label=GUICtrlCreateLabel("",10,100,500)

$read = GUICtrlRead($slider) + 32768
GUICtrlSetData($input, $read)
$val=IniRead(@ScriptDir&"\db.ini","desc",$read,"None")
GUICtrlSetData($label,"Port "&$read&": "&$val)

while 1
    Sleep(10)
WEnd

Func aclose()
    Exit
EndFunc

Func Inputupdate()
    $read=GUICtrlRead($input)
    GUICtrlSetData($slider,$read -32768)
    $val=IniRead(@ScriptDir&"\db.ini","desc",$read,"None")
    GUICtrlSetData($label,"Port "&$read&": "&$val)
EndFunc

; WM_HSCROLL and WM_VSCROLL event handler, intercepts Slider/Trackbar messages
Func WM_HVSCROLL($hWndGUI, $MsgID, $WParam, $LParam)
    Switch $LParam
        Case GUICtrlGetHandle($slider)
              $read = GUICtrlRead($slider) + 32768
              GUICtrlSetData($input, $read)
              $val=IniRead(@ScriptDir&"\db.ini","desc",$read,"None")
              GUICtrlSetData($label,"Port "&$read&": "&$val)
    EndSwitch
EndFunc
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

EDIT Updated with code example of slider with 65535 positions

don't need to see the ticks

any of the arrow keys will move the slider 1 tick, (1 port) for fine adjustment

and the gui is instantly updated smoothly as the slider is moved

pg/up down keys work as well

also the input edit box used as a label could have the readonly style removed and be used to input

port numbers directly, then on Enter the slider position could be updated.

and the GUICtrlCreateUpdown ctrl can be added.

just tried adding the up/dn box and editable input, all works.

just needs the math for the slider numbers, don't know if thats possible....

done..

working 0 to 65535 ports slider

tried with rough port list

Up/Dn needs work setting slider to input value with buttons but overall

proof of concept

yes it is a bit extreme, just to demonstrate it could be done.

done...

UP/DN spinner limited to -32768 To 32768, wont work without some sort of handler / hack

or custom spinner with buttons

Hey rover, very nice work! Exactly what I was looking for, but there is one small problem. The arrow keys to zero in on the exact port you want maxes out at 32767. Is there a way to fix that and make it go all the way?

Share this post


Link to post
Share on other sites

Hey rover, very nice work! Exactly what I was looking for, but there is one small problem. The arrow keys to zero in on the exact port you want maxes out at 32767. Is there a way to fix that and make it go all the way?

Hi Particle

The Up/Dn 'Spinner' only goes to 32767, actually range can be -32768 to 32767

same as the slider/trackbar, except with the slider you can add a positive integer

to the return to get the full range 65535

the spinner is 'buddyied' to the input ctrl

and doesn't return output, so either there's a message handling hack

or a custom up/dn has to be coded with small buttons.

haven't tried reading it with guictrlread yet, maybe that's it

I left it on for demo purposes, so you have:

rough slider adjust

4 keyboard arrow keys for fine adjust on the slider +pgup/pgdn

up/dn ctrl with acceleration - acceleration values can be set (arrow keys also work on up/dn, speed is faster)

direct entry of a port value

having a background in electronics, i'm familiar with the concept of fine and coarse adjustment controls

so the slider doesn't need individual markings for each port, the idea is a rough adjustment to jump up and down the range without having to type in each value at a time or wait for up/dn controls to step up/dn large numbers

as for the up/dn problem, i'll look into it, can't promise when, but i'll let you know (PM), and post here


I see fascists...

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

GUICtrlCreateUpdown and GUICtrlCreateSlider range problem resolved

here's a working 0 To 65535 port select GUI

with UP/DN Spinner, Slider, and Inputbox

Particle, post some code when your ready.

enjoy.

EDIT download attachment at bottom, codebox's tend to mung up the code formating

EDIT forgot to credit evilertoaster for iniread idea for database

;===============================================================================
; Description:  Demonstration of range extension for UP/DN Spinner and Slider
;               using GUICtrlCreateUpdown and GUICtrlCreateSlider controls.
;               Converts range of controls from -32768 -> 32767 To 0 -> 65535
;               UP/DN Spinner, Slider and Inputbox controls interlink and update each other
;
; Author(s)  :  Rover 2k7, from idea by Particle for Port Info Database GUI
;===============================================================================

; UP/DN control hold down acceleration set for:
; 1 step, after 2 seconds 10 steps, after 5 seconds 200 steps

#include <guiconstants.au3>
#include <GuiSlider.au3>

Opt("GUIoneventmode",1)
Opt("MustDeclareVars", 1)

Global Const $WM_HSCROLL = 0x0114
Global Const $WM_VSCROLL = 0x0115
Global Const $UDM_SETACCEL = $WM_USER+107

Local $gui, $slider, $updown, $input0, $input1
Local $read, $val
Local $sliderhwnd, $input0hwnd, $input1hwnd
Local $label, $font = "Arial"

;Local $font = "DIGITAL READOUT UPRIGHT"
; an LCD font for the inputbox would look good, look into "XSkin" for GUI skinning

;---- GUI & LABELS --------------------------------
$gui = GUICreate("Port Scan",550,350)
GUICtrlCreateLabel("Select Port"&@tab&"0",35,10,200)
GUICtrlSetFont(-1,9,800)
GUICtrlCreateLabel("65535",480,10,80)
GUICtrlSetFont(-1,9,800)
GUICtrlCreateLabel("Port",10,35,50)
GUICtrlSetFont(-1,9,800)
GUICtrlCreateLabel("Enter Number or use Up/Dn < > Arrow Keys" & @LF & _
"(Hold Down For Acceleration)" & @LF &  "< > Arrow Keys Adjust Slider",35,75,260,60)
GUICtrlSetFont(-1,9,800)
GUICtrlCreateLabel("Port",35,140,30)
GUICtrlSetFont(-1,9,800)
$label = GUICtrlCreateLabel("",65,140,500)
GUICtrlSetFont(-1,9,800)
;--------------------------------------------------

;---- SLIDER --------------------------------------
$slider=GUICtrlCreateSlider(120,30,400,40,$TBS_AUTOTICKS)
GUICtrlSetLimit($slider, 32767, -32768)
GUICtrlSetData($slider, -32768)
$sliderhwnd = GUICtrlGetHandle($slider)
_GUICtrlSliderSetLineSize($sliderhwnd, 1)
;_GUICtrlSliderSetPageSize($sliderhwnd, 10)
_GUICtrlSliderSetTicFreq($sliderhwnd, 1000)
;--------------------------------------------------

;---- INPUT0 DUMMY --------------------------------
 ; Dummy Input Control "Buddy" For GUICtrlCreateUpdown
$input0 = GUICtrlCreateInput("-32768", 95, 30, 20, 40, $ES_NUMBER)
GUICtrlSetLimit($input0,5)   ; to limit the entry to 5 chars
GUICtrlSetOnEvent($input0, "_Inputupdate0")
$input0hwnd = GUICtrlGetHandle($input0)
;--------------------------------------------------

;---- INPUT1 --------------------------------------
$input1 = GUICtrlCreateInput("-32768", 35, 30, 62, 40, $ES_NUMBER, $WS_EX_CLIENTEDGE )
GUICtrlSetLimit($input1,5)   ; to limit the entry to 5 chars
GUICtrlSetOnEvent($input1, "_Inputupdate1")
$input1hwnd = GUICtrlGetHandle($input1)

GUICtrlSetFont ($input1,12, 800, 1, $font)
GUICtrlSetColor($input1,0x00EEEE)    ; Cyan 0x00EEEE Yellow0xFFFF00
GUICtrlSetBkColor($input1,0x363636)  ; Gray 0x363636
;--------------------------------------------------

;---- UP/DN ---------------------------------------
$updown = GUICtrlCreateUpdown($input0,$UDS_NOTHOUSANDS+$UDS_ARROWKEYS)
GUICtrlSetPos($input0, 35,140, 80, 40 )
_GUICtrlUpdownSetAccel($updown,"0|2|5","1|10|200")
GUICtrlSetLimit($updown, 32767, -32768)
GUICtrlSetPos($input0, 95,30, 20, 40 )
;--------------------------------------------------

;---- Control Initialization ----------------------
$read = GUICtrlRead($slider) + 32768
GUICtrlSetData($input1, $read)
GUICtrlSetData($input0, - 32768)
$val=IniRead(@ScriptDir&"\db.ini","desc",$read,"None")
GUICtrlSetData($label,$read&" : "&$val)
;--------------------------------------------------

;--------------------------------------------------
GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)
;--------------------------------------------------

While 1
    Sleep(50000)
WEnd

Func _Exit()
    Exit
EndFunc

Func _Inputupdate0() ; UP/DN dummy GUICtrlCreateInput control
        Local $updnread = GUICtrlRead($input0) + 32768                          ; Read UP/DN
        Switch ControlGetHandle($gui, '', ControlGetFocus($gui))                ; Control focus method from _CheckInput()
            Case $input0hwnd                                                    ; UDF by MsCreatoR
                 ConsoleWrite(' UP/DN '& $updnread &@crlf)                      ; $updnread Data
                 GUICtrlSetData($input1, $updnread)                             ; Write Input1
                 GUICtrlSetData($slider,$updnread - 32767)                      ; Write Slider
                 $val=IniRead(@ScriptDir&"\db.ini","desc", $updnread,"None")
                 GUICtrlSetData($label, $updnread &" : "&$val)                  ; Write label
        Endswitch
EndFunc

Func _Inputupdate1() ; Input - accepts entry 0 to 65535, no leading zeros (default to 0) 
    Local $iread = GUICtrlRead($input1)                                         ; Read Input
    Switch ControlGetHandle($gui, '', ControlGetFocus($gui))
        Case $input1hwnd
             Switch $iread                                                      ; Number only input set by 
                Case 0 To 65535                                                 ; GUICtrlCreateInput $ES_NUMBER style
                     GUICtrlSetData($input1, $iread)                            ; Write Input1
                Case 65536 To 99999
                      $iread = 65535
                     GUICtrlSetData($input1, $iread)
             EndSwitch
             Switch  StringLeft($iread, 1)
                Case 0
                     $iread = 0
                     GUICtrlSetData($input1, $iread)
             EndSwitch
                     ConsoleWrite(' Input1 '& $iread &@crlf)                    ; $iread Data
                     GUICtrlSetData($slider, $iread - 32767)                    ; Write Slider
                     GUICtrlSetData($input0, $iread - 32768)
                     $val=IniRead(@ScriptDir&"\db.ini","desc", $iread ,"None")
                     GUICtrlSetData($label, $iread &" : "&$val)                 ; Write label
    Endswitch
EndFunc

Func WM_HVSCROLL($hWndGUI, $MsgID, $WParam, $LParam)                            ; Slider
    Switch $LParam
        Case GUICtrlGetHandle($slider)
              Local $slread = GUICtrlRead($slider) + 32768                      ; Read Slider
              ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Slider = ' & $slread & @crlf)
              GUICtrlSetData($input0, $slread - 32768)
              GUICtrlSetData($input1, $slread)                                  ; Write Input1          
              $val=IniRead(@ScriptDir&"\db.ini","desc", $slread ,"None")
              GUICtrlSetData($label, $slread &" : "&$val)                       ; Write label
    EndSwitch
EndFunc

;===============================================================================
;
; Description:    _GUICtrlUpdownSetAccel
; Parameter(s):  $h_updown - updown controlID
;               $nSecList - "|" delimited list of nSec times (Default "0|2|5" )
;               $nIncList - "|" delimited list of nInc increment (Default "1|5|20" )
;                        after 0 seconds, updown increments by 1
;                        after 1 second, updown increments by 5
;                        after 5 seconds, updown increments by 20
; Requirement:    <GUIConstants.au3>
; Return Value(s):  Returns nonzero if successful, or zero otherwise.
;                     If an error occurs, the return value is $LV_ERR (-1) and @error is set to -1
; User CallTip:  _GUICtrlUpdownSetAccel ( $h_updown ) resets to default values in example above
;               _GUICtrlUpdownSetAccel ( $h_updown, "0", "10" ) makes the updown increment by 10 with no acceleration
;               _GUICtrlUpdownSetAccel ( $h_updown, "0|2", "1|10" ) makes the updown increment by 1. After 2 seconds, it increments by 10
; Author(s):        Chris Howes (OjO)
; Note(s):      $nSecList and $nIncList must have the same number of delimited values
;               $nSecList must be in increasing order ex: "0|7|8"  - using "0|8|7" would fail and return -1
;               string values in $nSecList and $nIncList must have integer value of 0 or greater
;
;===============================================================================
Func _GUICtrlUpdownSetAccel ( $h_updown = 0, $nSecList = "0|2|5", $nIncList = "1|5|20" ); 0|2|5 and 1|5|20 are default windows settings
    ;Global Const $UDM_SETACCEL = $WM_USER+107
    Local $nSecErr = 0
    Local $nSec = StringSplit ( $nSecList, "|" )
    Local $nInc = StringSplit ( $nIncList, "|" )
    Local $x = 0
   
    If $nSec[0] <> $nInc[0] Then Return SetError($CB_ERR,$CB_ERR,$CB_ERR);check for same # of nSec & nInc sets
    For $x = 1 to $nSec[0];check for non integers, and negative numbers, and zero length entries
        If StringIsInt ($nSec[$x]) = 0 Or Int ( $nSec[$x]) < 0 Or StringLen ( $nSec[$x] ) = 0 Then Return SetError($CB_ERR,$CB_ERR,$CB_ERR)
        If StringIsInt ($nInc[$x]) = 0 Or Int ( $nInc[$x]) < 0 Or StringLen ( $nInc[$x] ) = 0 Then Return SetError($CB_ERR,$CB_ERR,$CB_ERR)
    Next
    If $nsec[0] > 1 Then
        For $x = 2 To $nSec[0]
            If $nSec[$x] <= $nSec[$x-1] Then $nSecErr = 1;check for ascending order of nSec sequence
        Next
        If $nSecErr = 1 Then Return SetError($CB_ERR,$CB_ERR,$CB_ERR)
    EndIf
       
    Local $str = "uint;uint";create initial structure for set of nSec;nInc
    if $nsec[0] > 1 Then ;add more structure for additional entries
        For $x = 2 To $nSec[0]
            $str = $str & ";uint;uint"
        Next
    EndIf
    Local $AccelStruct = DllStructCreate ( $str )
   
    For $x = 1 To $nSec[0];Put Data in the structure
        DllStructSetData ( $AccelStruct, ($x * 2) - 1, Number ($nSec[$x]) )
        DllStructSetData ( $AccelStruct, ($x * 2), Number ($nInc[$x]) )
    Next
   
    If IsHWnd($h_updown) Then
        Local $a_ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_updown, _
        "int", $UDM_SETACCEL, "int", $nSec[0], "ptr", DllStructGetPtr($AccelStruct))
        Return $a_ret[0]
    Else
        GUICtrlSendMsg($h_updown, $UDM_SETACCEL, $nSec[0], DllStructGetPtr ( $AccelStruct ))
    EndIf
EndFunc

PortDatabaseSlider.au3

Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

Thanks! I will add this code into the full program i'm working on and post it when it's finished. Give me about a week or two i'd say...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0