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

+ Recent posts