Jump to content

Return The Control's Text With Guictrlcreatetreeitem


laphlaw
 Share

Recommended Posts

I need a way to be able to get the tree item's *text*, not the control ID. So basically, I'm going to have a GUI with a list of servers. When a user clicks one of the servers, it will get the name of the server. Based on that, I am going to read an ini file that contains the IP addresses of each server, so...

$serverIP=IniRead(@ScriptDir & '\DX8000_IP.ini',$sec,'IP','Not Found')

Where $sec = the name of the server that was clicked on. Then, it will read the ini under that server's section name, and return the IP. Then, I'll have a label that will be dynamic, as the user clicks different servers.

I tried using a list view instead of a tree, but when you poll the GUI, it doesn't recognize clicking on a list view item as an event; only when it's a tree.

Please help!

Link to comment
Share on other sites

requires beta (listview) click, double click events

; Events - ListView
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <GuiListView.au3>

Global $ListView
Global Const $WM_NOTIFY = 0x004E
Global Const $DebugIt = 1

;ListView Events
Global Const $NM_FIRST = 0
Global Const $NM_LAST = (-99)
Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1)
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)
;~ Global Const $NM_RETURN = ($NM_FIRST - 4)
;~ Global Const $NM_RCLICK = ($NM_FIRST - 5)
;~ Global Const $NM_RDBLCLK = ($NM_FIRST - 6)
;~ Global Const $NM_SETFOCUS = ($NM_FIRST - 7)
;~ Global Const $NM_KILLFOCUS = ($NM_FIRST - 8)
;~ Global Const $NM_CUSTOMDRAW = ($NM_FIRST - 12)
;~ Global Const $NM_HOVER = ($NM_FIRST - 13)
;~ Global Const $NM_NCHITTEST = ($NM_FIRST - 14)
;~ Global Const $NM_KEYDOWN = ($NM_FIRST - 15)
;~ Global Const $NM_RELEASEDCAPTURE = ($NM_FIRST - 16)
;~ Global Const $NM_SETCURSOR = ($NM_FIRST - 17)
;~ Global Const $NM_CHAR = ($NM_FIRST - 18)
;~ Global Const $NM_TOOLTIPSCREATED = ($NM_FIRST - 19)
#endregion End Global variables

Opt("WinTitleMatchMode", 2)

$main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10, BitOR($WS_THICKFRAME, $WS_SIZEBOX))

$ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL))
_GUICtrlListViewSetColumnWidth ($ListView, 0, 100)
_GUICtrlListViewSetColumnWidth ($ListView, 1, 100)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("Name 1|Category 1", $ListView)
GUICtrlCreateListViewItem("Name 2|Category 2", $ListView)
GUISetState()

;Register WM_NOTIFY  events
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
   
   $msg = GUIGetMsg()
   
   Switch $msg
      
   ;-----------------------------------------------------------------------------------------
   ;This case statement exits and updates code if needed
      Case $GUI_EVENT_CLOSE
         Exit
         
         
      ;-----------------------------------------------------------------------------------------
      ;put all the misc. stuff here
  Case Else
  ;;;
   EndSwitch
WEnd

Func ListView_Click()
;----------------------------------------------------------------------------------------------
 If $DebugIt Then ConsoleWrite (_DebugHeader ("$NM_CLICK"))
;----------------------------------------------------------------------------------------------
EndFunc  ;==>ListView_Click

Func ListView_DoubleClick()
;----------------------------------------------------------------------------------------------
 If $DebugIt Then ConsoleWrite (_DebugHeader ("$NM_DBLCLK"))
;----------------------------------------------------------------------------------------------
 MsgBox(0,"Double Clicked", _GUICtrlListViewGetItemText ($ListView, _GUICtrlListViewGetSelectedIndices($ListView)))
EndFunc  ;==>ListView_DoubleClick

;
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
 #forceref $hWndGUI, $MsgID, $wParam
 Local $tagNMHDR, $event, $hwndFrom, $code
 $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
 If @error Then Return
 $event = DllStructGetData($tagNMHDR, 3)
 Select
 Case $wParam = $ListView
  Select
   Case $event = $NM_CLICK
    ListView_Click ()
   Case $event = $NM_DBLCLK
    ListView_DoubleClick ()
   EndSelect
 EndSelect
 $tagNMHDR = 0
 $event = 0
 $lParam = 0
EndFunc  ;==>WM_Notify_Events

Func _DebugHeader($s_text)
 Return _
   "!===========================================================" & @LF & _
   "+===========================================================" & @LF & _
   "-->" & $s_text & @LF & _
   "+===========================================================" & @LF
EndFunc  ;==>_DebugHeader

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • Moderators

What is this line #forceref Gary?

#forceref $hWndGUI, $MsgID, $wParam

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I installed the beta, and it still doesn't work. It can't find GuiListView.au3, and I searched my computer and it's not found either. Is this a custom au3 that you made?

It's part of the beta.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

What is this line #forceref Gary?

forces it see those as referenced when they aren't used, that way you don't get the warnings about variables not used

those variables are required for that function call but I didn't use them in this example.

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • Developers

I installed the beta... the function is still not found, and the script still won't compile. Whereabouts do I find it?

How are you running/compiling it ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

How are you running/compiling it ?

Tools -> beta run.

In the meantime, I basically just wrote a function that converts the control ID into the text of the control (with a bunch of case statements :mellow:.

It works, but now I'm having another problem... sorta. So I'm still using the tree view instead of the list view. When I click on a tree item, I have a label that updates the IP address of that server. The problem is it only responds when I *click* on the tree item... if I using the keyboard and scroll through the tree items, the label does *not* update. :)

So yeah... I don't know if I'm approaching this the right way. I don't know if I read wrong, but from the code you posted, it sounds like the user will have to double click the list item for the event to trigger. If that's the case, that's not really what I'm looking for.

Thanks a bunch!

Link to comment
Share on other sites

Tools -> beta run.

In the meantime, I basically just wrote a function that converts the control ID into the text of the control (with a bunch of case statements :mellow: .

It works, but now I'm having another problem... sorta. So I'm still using the tree view instead of the list view. When I click on a tree item, I have a label that updates the IP address of that server. The problem is it only responds when I *click* on the tree item... if I using the keyboard and scroll through the tree items, the label does *not* update. :)

So yeah... I don't know if I'm approaching this the right way. I don't know if I read wrong, but from the code you posted, it sounds like the user will have to double click the list item for the event to trigger. If that's the case, that's not really what I'm looking for.

Thanks a bunch!

Did you change the scite config to use beta?

Tools/Scite Config/Loaed AutoIt3 definitions

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Ok, maybe I'm missing something really simple here, but I cannot get the "beta run" to recognize the function _FileListToArray. I did the following:

-Downloaded and installed the beta

-Went to tools, scite config, loaded autoit definitions

-Hit alt+f5 to run the beta

After all that, it still doesn't work. I did some investigation and I found the beta version I downloaded was from 1/18/2006, 3.1.1.102. I then searched in array.au3, and found that _FileListToArray indeed is missing. The comments state that it's:

Include Version:1.53 (2/16/2006)

Link to comment
Share on other sites

Okay, maybe I'm doing something wrong, but I still can't seem to get the latest beta. In Scite, it still says 3.1.1.102 as the installed beta. I went to the link you gave me, installed 3.1.1.114. I went inside the include files, and I still can't find the function _FileListToArray(), which is a function I really need. Help!

Edit: okay, I finally found the function in file.au3. Now the problem is scite isn't loading these new files... the latest it sees is 3.1.1.102. How do I do that?

Edited by laphlaw
Link to comment
Share on other sites

  • Moderators

Have you tried downloading the latest SciTe definitions also? http://www.autoitscript.com/forum/index.ph...ndpost&p=160434

Also, you can toggle the beta via the start menu: Start >> All Programs >> AutoIt v3 >> Beta >> Toggle AU3 Beta....

Hope that helps you a tad.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Have you tried downloading the latest SciTe definitions also? http://www.autoitscript.com/forum/index.ph...ndpost&p=160434

Also, you can toggle the beta via the start menu: Start >> All Programs >> AutoIt v3 >> Beta >> Toggle AU3 Beta....

Hope that helps you a tad.

Don't think that's going to help, jdeb might have a better handle on this, but seems like gene had the same problem a while back.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...