728x90
DataLife
  • Members
  • 1022 posts
      •  Last active: Nov 27 2015 01:09 AM
      • Joined: 27 Apr 2008
      I need to get the highlighted line number in listbox.

      I am using the g label for one thing and the v associated variable for another so altsubmit won't work for me.

      I know that double click puts the line number in A_EventInfo but I want to highlight a row of text then click a control button to use that text for something else.

      How can I retrieve the line number?

      thanks
      DataLife 
      SKAN
      • Administrators
      • 9115 posts
          •  Last active:
          • Joined: 26 Dec 2005

          How can I retrieve the line number?


          You may send LB_GETCURSEL message to the ListBox Control

          Gui, Add, ListBox, w100 R9 hWndLB1,  ABC|DEF|GHI|JKL|MNO|PQR|STU|VWX|YZ
          Gui, Add, Button, w100 gGetLineNumber, Get Line Number
          Gui, Show,,
          Return
          
          GetLineNumber:
           SendMessage,(LB_GETCURSEL := 0x188),0,0,, ahk_id %LB1%
           LineNumber := ErrorLevel+1
           MsgBox %LineNumber%
          Return

          :) 
          kWo4Lk1.png
          DataLife
          • Members
          • 1022 posts
              •  Last active: Nov 27 2015 01:09 AM
              • Joined: 27 Apr 2008
              You are correct. I found a post by Chris that used LB_GETCURSEL. It works great.

              Any chance you know how to send a single click to a highlighted row in listbox?

              Either that or make the listbox active again after I refresh the contents. I have to click on the listbox to be able to scroll with the arrow keys.

              thanks again.
              DataLife 
              DataLife
              • Members
              • 1022 posts
                  •  Last active: Nov 27 2015 01:09 AM
                  • Joined: 27 Apr 2008
                  I found the answer to my previous question.

                  I can use controlfocus to make the listbox the active control again.
                  So simple, I found it in the documentation looking for something else.
                  example:

                  ControlFocus, Listbox1


                  thanks

                  DataLife 


                  고전적인 ListBox 의 문제점 중 하나는, Line number 나 Data를 얻어 올 수 있지만 "상태에 의해 제약받는다" 는 점이 있다.
                  그 상태에 대해선 3가지 부류가 있는데.. 결론은 Selected 상태여야 한다는 것으로 귀결된다.
                   


                  'AUTOHOTKEY' 카테고리의 다른 글

                  ControlSend 와 Nox에 관한 고찰  (0) 2019.02.22
                  IniRead, IniWrite, IniDelete  (0) 2019.02.20
                  ControlGet 에 관한 고찰  (0) 2019.02.20
                  GetText from ListBox  (0) 2019.02.20
                  ControlGet  (0) 2019.02.20
                  728x90

                  List

                  Retrieves a list of items from a ListView, ListBox, ComboBox, or DropDownList. For ListView, additional options can be specified.

                  ControlGet, OutputVar, List , Options, Control, WinTitle, WinText, ExcludeTitle, ExcludeText


                  위에 함수원형의 Prototype 을 살펴보자.  5번째 Argument 에 Control 이 위치하도록 되어있다. 신기하게도 이 부분에서 Control 에 대해서 특별한 언급이 없는 경우에, v 로 지정하는 Label 로 써 구분짓는 것이 아닌, ListBox 의 생성순서에 따라서, ListBox1 과 같은 Control 의 이름을 따른다.

                  이것은 Win32 API, MFC 를 따르는 전통적인 관례다.

                  예제 소스를 보자!


                  ControlGet, GetListBox_List, List,, ListBox1, A 
                  ;ListBox1 means the First ListBox
                  IniRead, QT, Set.ini, Common, QT, 0 

                  Loop, % QT 
                    IniDelete, Set.ini, Common, %A_Index% 

                  Loop, Parse, GetListBox_List,`n 
                    SetQT := A_Index 
                    IniWrite, %A_LoopField%, Set.ini,Common, %A_Index% 
                  iniWrite, %SetQT%, Set.ini,Common, QT 

                  ListBox1 부분에 특희 유념할 것!

                  ListView

                  If the Options parameter is blank or omitted, all the text in the control is retrieved. Each row except the last will end with a linefeed character (`n). Within each row, each field (column) except the last will end with a tab character (`t).

                  Specify for Options zero or more of the following words, each separated from the next with a space or tab:

                  SelectedRetrieves only the selected (highlighted) rows rather than all rows. If none, OutputVar is made blank.
                  FocusedRetrieves only the focused row. If none, OutputVar is made blank.
                  Col4Retrieves only the fourth column (field) rather than all columns (replace 4 with a number of your choice).
                  CountRetrieves a single number that is the total number of rows in the control.
                  Count SelectedRetrieves the number of selected (highlighted) rows.
                  Count FocusedRetrieves the row number (position) of the focused row (0 if none).
                  Count ColRetrieves the number of columns in the control (or -1 if the count cannot be determined).

                  Note: Some applications store their ListView text privately, which prevents their text from being retrieved. In these cases, ErrorLevel will usually be set to 0 (indicating success) but all the retrieved fields will be empty. Also note that ListView text retrieval is not restricted by #MaxMem.

                  Upon success, ErrorLevel is set to 0. Upon failure, it is set to 1 and OutputVar is made blank. Failure occurs when: 1) the target window or control does not exist; 2) the target control is not of type SysListView32; 3) the process owning the ListView could not be opened, perhaps due to a lack of user permissions or because it is locked; 4) the ColNoption specifies a nonexistent column.

                  To extract the individual rows and fields out of a ListView, use a parsing loop as in this example:

                  ControlGet, SelectedItems, List, Selected, SysListView321, WinTitle
                  Loop, Parse, SelectedItems, `n  ; Rows are delimited by linefeeds (`n).
                  {
                      RowNumber := A_Index
                      Loop, Parse, A_LoopField, %A_Tab%  ; Fields (columns) in each row are delimited by tabs (A_Tab).
                          MsgBox Row #%RowNumber% Col #%A_Index% is %A_LoopField%.
                  }

                  On a related note, the columns in a ListView can be resized via SendMessage as shown in this example:

                  SendMessage, 4126, 0, 80, SysListView321, WinTitle  ; 4126 is LVM_SETCOLUMNWIDTH.

                  In the above, 0 indicates the first column (specify 1 for the second, 2 for the third, etc.) Also, 80 is the new width. Replace 80 with -1 to autosize the column. Replace it with -2 to do the same but also take into account the header text width.

                  ListBox, ComboBox, DropDownList

                  All the text is retrieved from the control (that is, the ListView options above such as Count and Selected are not supported).

                  Each item except the last will be terminated by a linefeed character (`n). To access the items individually, use a parsing loop as in this example:

                  ControlGet, Items, List,, ComboBox1, WinTitle
                  Loop, Parse, Items, `n
                      MsgBox Item number %A_Index% is %A_LoopField%.


                  'AUTOHOTKEY' 카테고리의 다른 글

                  IniRead, IniWrite, IniDelete  (0) 2019.02.20
                  Line number in listbox  (0) 2019.02.20
                  GetText from ListBox  (0) 2019.02.20
                  ControlGet  (0) 2019.02.20
                  ListBox Count  (0) 2019.02.20
                  728x90
                  David Andersen
                  • Guests
                    •  Last active:
                    • Joined: --
                    I really need to read the text in a ListBox. My script is as follows:
                    #x::
                    SendMessage, 0x189, 2, 0, WindowsForms10.LISTBOX.app.0.378734a1, Form1
                    if ErrorLevel <> FAIL
                    {
                    MsgBox, %ErrorLevel%
                    }

                    Where 0x189 refers to the following MSDN function:
                    http://msdn.microsof... ... ettext.asp

                    at least according to http://www.codeguru.... ... .php/c2771

                    Anyways... My problem is that this returns the length of the string in the listbox (this is in accordance with the description of LB_GETTEXT on MSDN. My quesiton is how I could retreave the content that lParam is pointing at after this sendmessage function.

                    The following is a link to an .exe file that made in Visual Studio 2005 beta 2 (hope it works for you), containing the listbox that I am trying to retreave the text from. http://www.translati...ds.com/demo.exe.

                    Thanks 


                    Chris
                    • Administrators
                    • 10727 posts
                        •  Last active:
                        • Joined: 02 Mar 2004

                        I really need to read the text in a ListBox.

                        Have you tried "ControlGet, List"? This is a relatively recent feature that gets a complete list of items from a ListBox, ComboBox, or DropDownList. 
                        David Andersen
                        • Guests
                          •  Last active:
                          • Joined: --
                          Thanks for the replay, Chris.

                          I have tried the following script:
                          ControlGet, List, List,, WindowsForms10.LISTBOX.app.0.378734a1, Form1 
                          Loop, Parse, List, `n
                          {
                          MsgBox Item number %A_Index% is %A_LoopField%.
                          }

                          Unfortunatelly, I did not receive any output at all. 

                          While I got a message box saying "5" with the following script:
                          SendMessage, 0x189, 2, 0, WindowsForms10.LISTBOX.app.0.378734a1, Form1 
                          if ErrorLevel <> FAIL 

                          MsgBox, %ErrorLevel% 
                          }

                          5 represents the number of characters in this entry in the list. 
                          Chris
                          • Administrators
                          • 10727 posts
                              •  Last active:
                              • Joined: 02 Mar 2004
                              ControlGet is only designed to work with standard ListBoxes and ComboBoxes. Yours control seems like a non-standard (custom) control, which might explain why it doesn't work.

                              Although I'm all out of ideas, I hope you find a solution or that someone else comes along who knows something. 


                              그렇다! Chris 의 말대로라면 ControlGet 은 standard ListBoxes and ComboBoxes 에 디자인된 것이다. (어쨋든 여기서 필자의 요구조건은 충족시키므로 패스!)



                              더욱 흥미로운 Chris 의 발언들을 살펴보자!


                              David Andersen
                              • Guests
                                •  Last active:
                                • Joined: --
                                I understand. The control that I am using is the standard one used by Visual Studio 2005 (although, I am using the beta 2 version).

                                Although I don't know C++ I found the method that would need some adjustments to make it possible to receive the text. Its name is ScriptSendMessage and it is located in Script2.cpp. This method uses the MSDN method SendMessageTimeout (http://msdn.microsoft.com/library/defau ... ettext.asp).

                                Are there any C++ experts out there that knows how to implement this?

                                Thanks a lot in advance. 
                                Chris
                                • Administrators
                                • 10727 posts
                                    •  Last active:
                                    • Joined: 02 Mar 2004
                                    I don't see how any internal changes to SendMessage would help in this case. The "ControlGet List" method I mentioned
                                    earlier already uses LB_GETTEXT internally. If it fails to work on a custom ListBox, you would have to find out what
                                    messages to send to that particular type of ListBox to get the text out of it.

                                    Microsoft Active Accessibility might be able to extract text from many types of custom controls, but I don't know much
                                    else about it yet. 

                                    ControlGet List method 는 내부적으로 LB_GETTEXT 를 사용한다고 되어있다. 그렇다는 것은 DllCall 에 의해서도 충분히 얻어질 수 있다는 것이다!


                                    이와같이 말이다.


                                    LBCount := DllCall("SendMessage", "uint", hIDLB, "uint", 0x18B) ;LB_GETCOUNT




                                    David Andersen
                                    • Members
                                    • 140 posts
                                        •  Last active: Jun 28 2011 04:54 PM
                                        • Joined: 15 Jul 2005
                                        Thank you a lot for your help. I have sent you 10 dollars to your email address to show my appreciation.

                                        I have a far more general question now. Is it in principle possible to extract the text from any listbox or combobox? I understand that i.e. Java programs are build up in a totally different way, so my question is just about the programs that show up as listboxes in AU3_Spy.

                                        I really need to read text from a range of listboxes where the one at http://www.translati...ds.com/demo.exe is an example of one of them. I think that all the listboxes I want to read from have been programmed in Visual Studio.

                                        I have also thought about using OCR technology to "read" the text off the screen, but this is a really dirty way to solve the problem so I hope there are other possibilities.

                                        Thanks again. 
                                        Chris
                                        • Administrators
                                        • 10727 posts
                                            •  Last active:
                                            • Joined: 02 Mar 2004

                                            Is it in principle possible to extract the text from any listbox or combobox?

                                            Since any custom control can arbitrarily contain the word ListBox or ComboBox in its name, I would have to say "no".
                                            An application can be designed to store its text privately and draw it on the screen only as needed. In such a case, there
                                            would be no external/direct access to the text (other than something fairly difficult such as ReadProcessMemory).

                                            I have also thought about using OCR technology to "read" the text off the screen

                                            This may be the best approach in this case. Here is a nice command line OCR tool that daonlyfreez recently posted:
                                            Optical Character Recognition (OCR) - gocr [CLI] 



                                            'AUTOHOTKEY' 카테고리의 다른 글

                                            IniRead, IniWrite, IniDelete  (0) 2019.02.20
                                            Line number in listbox  (0) 2019.02.20
                                            ControlGet 에 관한 고찰  (0) 2019.02.20
                                            ControlGet  (0) 2019.02.20
                                            ListBox Count  (0) 2019.02.20
                                            728x90

                                            Retrieves various types of information about a control.

                                            ControlGet, OutputVar, SubCommand , Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

                                            Parameters

                                            OutputVar
                                            The name of the variable in which to store the result of SubCommand.
                                            SubCommand, Value
                                            These are dependent upon each other and their usage is described below.
                                            Control

                                            Can be either ClassNN (the classname and instance number of the control) or the control's text, both of which can be determined via Window Spy. When using text, the matching behavior is determined by SetTitleMatchMode. If this parameter is blank, the target window's topmost control will be used.

                                            To operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter (this also works on hidden controls even when DetectHiddenWindows is Off). The HWND of a control is typically retrieved via ControlGet HwndMouseGetPos, or DllCall.

                                            WinTitle
                                            A window title or other criteria identifying the target window. See WinTitle.
                                            WinText
                                            If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.
                                            ExcludeTitle
                                            Windows whose titles include this value will not be considered.
                                            ExcludeText
                                            Windows whose text include this value will not be considered.

                                            Sub-commands

                                            For SubCommand, specify one of the following:

                                            • List: Retrieves a list of items from a ListView, ListBox, ComboBox, or DropDownList.
                                            • Checked: Retrieves 1 if the checkbox or radio button is checked or 0 if not.
                                            • Enabled: Retrieves 1 if the control is enabled, or 0 if disabled.
                                            • Visible: Retrieves 1 if the control is visible, or 0 if hidden.
                                            • Tab: Retrieves the tab number of a SysTabControl32 control.
                                            • FindString: Retrieves the entry number of a ListBox or ComboBox that is an exact match for the string.
                                            • Choice: Retrieves the name of the currently selected entry in a ListBox or ComboBox.
                                            • LineCount: Retrieves the number of lines in an Edit control.
                                            • CurrentLine: Retrieves the line number in an Edit control where the caret resides.
                                            • CurrentCol: Retrieves the column number in an Edit control where the caret resides.
                                            • Line: Retrieves the text of the specified line number in an Edit control.
                                            • Selected: Retrieves the selected text in an Edit control.
                                            • Style: Retrieves an 8-digit hexadecimal number representing the style of the control.
                                            • ExStyle: Retrieves an 8-digit hexadecimal number representing the extended style of the control.
                                            • Hwnd [v1.1.04+]: Retrieves the window handle (HWND) of the control.
                                            해석에 유의해야한다. List 부분에서 a list of items 를 반환한다고 되어있다.  

                                            List

                                            Retrieves a list of items from a ListView, ListBox, ComboBox, or DropDownList. For ListView, additional options can be specified.

                                            ControlGet, OutputVar, List , Options, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

                                            ListView

                                            If the Options parameter is blank or omitted, all the text in the control is retrieved. Each row except the last will end with a linefeed character (`n). Within each row, each field (column) except the last will end with a tab character (`t).

                                            Specify for Options zero or more of the following words, each separated from the next with a space or tab:

                                            SelectedRetrieves only the selected (highlighted) rows rather than all rows. If none, OutputVar is made blank.
                                            FocusedRetrieves only the focused row. If none, OutputVar is made blank.
                                            Col4Retrieves only the fourth column (field) rather than all columns (replace 4 with a number of your choice).
                                            CountRetrieves a single number that is the total number of rows in the control.
                                            Count SelectedRetrieves the number of selected (highlighted) rows.
                                            Count FocusedRetrieves the row number (position) of the focused row (0 if none).
                                            Count ColRetrieves the number of columns in the control (or -1 if the count cannot be determined).

                                            Note: Some applications store their ListView text privately, which prevents their text from being retrieved. In these cases, ErrorLevel will usually be set to 0 (indicating success) but all the retrieved fields will be empty. Also note that ListView text retrieval is not restricted by #MaxMem.

                                            Upon success, ErrorLevel is set to 0. Upon failure, it is set to 1 and OutputVar is made blank. Failure occurs when: 1) the target window or control does not exist; 2) the target control is not of type SysListView32; 3) the process owning the ListView could not be opened, perhaps due to a lack of user permissions or because it is locked; 4) the ColNoption specifies a nonexistent column.

                                            To extract the individual rows and fields out of a ListView, use a parsing loop as in this example:

                                            ControlGet, SelectedItems, List, Selected, SysListView321, WinTitle
                                            Loop, Parse, SelectedItems, `n  ; Rows are delimited by linefeeds (`n).
                                            {
                                                RowNumber := A_Index
                                                Loop, Parse, A_LoopField, %A_Tab%  ; Fields (columns) in each row are delimited by tabs (A_Tab).
                                                    MsgBox Row #%RowNumber% Col #%A_Index% is %A_LoopField%.
                                            }

                                            On a related note, the columns in a ListView can be resized via SendMessage as shown in this example:

                                            SendMessage, 4126, 0, 80, SysListView321, WinTitle  ; 4126 is LVM_SETCOLUMNWIDTH.

                                            In the above, 0 indicates the first column (specify 1 for the second, 2 for the third, etc.) Also, 80 is the new width. Replace 80 with -1 to autosize the column. Replace it with -2 to do the same but also take into account the header text width.

                                            ListBox, ComboBox, DropDownList

                                            All the text is retrieved from the control (that is, the ListView options above such as Count and Selected are not supported).

                                            컨트롤(개체)로부터 모든 텍스트가 반환되어진다. 즉, ListView의 옵션들 (Count 그리고 Selected 같은 것은 지원되지 않는다)


                                            Each item except the last will be terminated by a linefeed character (`n). To access the items individually, use a parsing loop as in this example:


                                            마지막을 제외한 각각의 아이템들은 Linefeed Character (`n) 문자에 의해서 구분지어진다. 각각의 아이템들에 접근하기 위해, 다음과 같은 parsing loop 를 사용해본다.

                                            ControlGet, Items, List,, ComboBox1, WinTitle
                                            Loop, Parse, Items, `n
                                                MsgBox Item number %A_Index% is %A_LoopField%.


                                            'AUTOHOTKEY' 카테고리의 다른 글

                                            IniRead, IniWrite, IniDelete  (0) 2019.02.20
                                            Line number in listbox  (0) 2019.02.20
                                            ControlGet 에 관한 고찰  (0) 2019.02.20
                                            GetText from ListBox  (0) 2019.02.20
                                            ListBox Count  (0) 2019.02.20

                                            + Recent posts