Jump to content
Sign in to follow this  
gseller

Setting name from key value

Recommended Posts

gseller

Hi all,

I am working on showing an icon in a listview according to what is read from an ini file. I am stuck with displaying the name of the key value and then actually applying the key value. Can someone take a look and tell me what I am doing wrong? Thank you in advance. Here is a zip with the files I can put just the code too if needed. I thought having the whole enchilada would be better.

Share this post


Link to post
Share on other sites
WideBoyDixon

You might need to explain a little better what you're trying to achieve. I'm not sure I understand your original post.

WBD

Share this post


Link to post
Share on other sites
KaFu

Something more like this?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------
#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>
#include <TabConstants.au3>

;dimmed items ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim $somethingCurIndex
Dim $DMSPicture = @ScriptDir & "\dms1_icon.ico"
;end dimmed items ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;global constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global Const $WM_NOTIFY = 0x004E
Global Const $SS_NOTIFY = 0x0100
Global Const $WS_GROUP = 0x00020000
Global Const $SS_LEFT = 0x0000
Global Const $BS_DEFPUSHBUTTON = 0x0001
Global Const $ES_MULTILINE = 0x0004
Global Const $ES_AUTOVSCROLL = 0x0040
Global Const $WS_VSCROLL = 0x00200000
;end global constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;globals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global $something_DoubleClicked   = False
;end globals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Opt("GUIOnEventMode", 1)


;gui necessities~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$FontSize = 16 
$fsize = 14
$fcolor = 0xFFFFFF
$lbgcolor = 0x65A89D
$GUI_BG = 0x7CCFC1
$somethingfsize = 14
$GUI_W = "785"
$GUI_H = "470"
$laHors = "8"
$laVert = "140"
$laHorsBut = "125"
$laVertBut = "30"
$laButSize = "125, 25"
GUISetBkColor ($GUI_BG)
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")
$hGui = GUICreate("", $GUI_W, $GUI_H, (@DesktopWidth-$GUI_W)/10, (@DesktopHeight-$GUI_H)/10,-1)
$Tab1 = GUICtrlCreateTab(16, 40, 689, 350)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close_gui")
;end gui necessities ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




;begin ini read ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global $iniFile = @ScriptDir & "\info.ini"

;end ini read ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;tab ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TabSheet1 = GUICtrlCreateTabItem("something")
$ListView_something = GUICtrlCreateListView ("Sessions",30, 85, 660, 268)
GUICtrlSetStyle($ListView_something, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $WS_VSCROLL))
    GUICtrlSetOnEvent($ListView_something, "something_launch")
$something_button = GUICtrlCreateButton("LAUNCH", 224, 357, 89, 25, 0)
    GUICtrlSetOnEvent(-1, "something_launch")
GUICtrlCreateGroup("something", $laHors * 3, $laVert / 2, 672, 315)
GUICtrlCreateLabel("Choose Your Session To Launch", 10, 10, 625, 20, $SS_Left)
$avSwitches2 = IniReadSection($IniFile, "section")
If @error Or $avSwitches2[0][0] = 0 Then
    MsgBox(16, "Error", "Error reading ini file, or no data.")
Else
    $h = 0
    $v = 0
For $n = 1 To $avSwitches2[0][0]
    GUICtrlCreateListViewItem($avSwitches2[$n][0] , $ListView_something)
        GUICtrlSetImage(-1, $DMSPicture, 0)
            $h = $h + 1
            if $h > 4 Then
                $h = 0
                $v = $v + 1
            EndIf
Next
EndIf
; end tab ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GUISetState()

While 1
    Sleep(100)
    If $something_DoubleClicked Then
        something_launch()
        $something_DoubleClicked = False
    EndIf
WEnd



Func something_launch()
 $somethingCurIndex = _GUICtrlListView_GetSelectedIndices($ListView_something,true)
 If $somethingCurIndex[0] = 0 Then
  MsgBox(0, "Error", "You must select a session from the list" )
  Return
 EndIf
 SplashTextOn( "Please Stand by", "Launching: "  & @CRLF & IniRead($iniFile,"section","item" & ($somethingCurIndex[1] + 1),""),300, 75, -1, -1,17)
 ShellExecute("file.exe", " " & IniRead($iniFile,"section","item" & ($somethingCurIndex[1] - 1),""), @ProgramFilesDir & "\path\to\file","")
 Sleep(1000)
 SplashOff()
EndFunc


Func MY_WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return $GUI_RUNDEFMSG
    Local $Code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $ListView_something And $Code = -3 Then $something_DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc

Func _close_gui()
Exit
EndFunc  ;==>Close Up Shop

Share this post


Link to post
Share on other sites
gseller

KaFu... That totally works.. Thank you so much! I have been pulling my hair out and could not get that to work.. Thank You!

edit: Well, it works as long as the key name is named item? Thanks for trying...

Edited by gseller

Share this post


Link to post
Share on other sites
KaFu

LOL, that's the way it's hardcoded based on your example. To make it dynamic replace

SplashTextOn( "Please Stand by", "Launching: "  & @CRLF & IniRead($iniFile,"section","item" & ($somethingCurIndex[1] + 1),""),300, 75, -1, -1,17)
 ShellExecute("file.exe", " " & IniRead($iniFile,"section","item" & ($somethingCurIndex[1] - 1),""), @ProgramFilesDir & "\path\to\file","")

with

SplashTextOn( "Please Stand by", "Launching: "  & @CRLF & IniRead($iniFile,"section",_GUICtrlListView_GetItemText($ListView_something, $somethingCurIndex[1]),""),300, 75, -1, -1,17)
 ShellExecute("file.exe", " " & IniRead($iniFile,"section",_GUICtrlListView_GetItemText($ListView_something, $somethingCurIndex[1]),""), @ProgramFilesDir & "\path\to\file","")

Share this post


Link to post
Share on other sites
gseller

LOL, that's the way it's hardcoded based on your example. To make it dynamic replace

SplashTextOn( "Please Stand by", "Launching: "  & @CRLF & IniRead($iniFile,"section","item" & ($somethingCurIndex[1] + 1),""),300, 75, -1, -1,17)
ShellExecute("file.exe", " " & IniRead($iniFile,"section","item" & ($somethingCurIndex[1] - 1),""), @ProgramFilesDir & "\path\to\file","")

with

SplashTextOn( "Please Stand by", "Launching: "  & @CRLF & IniRead($iniFile,"section",_GUICtrlListView_GetItemText($ListView_something, $somethingCurIndex[1]),""),300, 75, -1, -1,17)
ShellExecute("file.exe", " " & IniRead($iniFile,"section",_GUICtrlListView_GetItemText($ListView_something, $somethingCurIndex[1]),""), @ProgramFilesDir & "\path\to\file","")
I agree! Thanks, my bad... I do get an idea from your example tho. I am hoping to make it work.

Thanks again!

Share this post


Link to post
Share on other sites
KaFu

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.