Jump to content

How to do word wrap in ListBox?


Recommended Posts

Excellent work function! Thank you PhoenixXL! Do not expect so much help that much to get a full UDF. Almost completely replaced my ListBox on EditList.
 
However, there is still a couple of things that I do not know how to solve.
 
For example, I need identify that there was a click on EditList?
 
For example:
#include <EditList.au3>


Opt("GUIOnEventMode", 1)


$hMain = GUICreate("Test", 500, 300)
Global $hRichEdit_ = _Edit_List_Create(10, 10, 300, 200, $hMain)

$But1 = GUICtrlCreateButton("1",330, 100, 40, 40)
GUICtrlSetOnEvent(-1,"OnClick_Handler")

$But2 = GUICtrlCreateButton("2",380, 100, 40, 40)
GUICtrlSetOnEvent(-1,"OnClick_Handler")


_Edit_List_InsertItem("1. The usual high-level elements for functions, loops and expression-handling."&@CRLF)
_Edit_List_InsertItem("2. A staggering amount of string handling functions and a Perl Compatible Regular Expression Engine(PCRE)"&@CRLF)
_Edit_List_InsertItem("3. COM support"&@CRLF)
_Edit_List_InsertItem("4. Call Win32 and Third-Party DLL APIs."&@CRLF)
_Edit_List_InsertItem("1. The usual high-level elements for functions, loops and expression-handling."&@CRLF)
_Edit_List_InsertItem("2. A staggering amount of string handling functions and a Perl Compatible Regular Expression Engine(PCRE)"&@CRLF)
_Edit_List_InsertItem("3. COM support"&@CRLF)
_Edit_List_InsertItem("4. Call Win32 and Third-Party DLL APIs."&@CRLF)
_Edit_List_SetOnEvent("OnClick_Handler")


GUISetState()

_SendMessage($hRichEdit_, $WM_SETFOCUS) ;required for initial hiding of the caret

While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Func OnClick_Handler()
  If @GUI_CtrlId=$But1 Then
    ConsoleWrite("Press Button 1" & @CRLF)
  ElseIf @GUI_CtrlId=$hRichEdit_ Then
    ConsoleWrite("Press EditList" & @CRLF)
  ElseIf @GUI_CtrlId=$But2 Then
    ConsoleWrite("Press Button 2" & @CRLF)
  EndIf
EndFunc
Prompt if there are options, how to recognize a click on EL?
 
 
 
P.S. Already using beta like until all without problems except for an error in the file: APIMiscConstants.au3 which apparently refers to the file Resources.au3.
Edited by AndreyS
Link to post
Share on other sites
  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Sounds like you want this: Specifically, post #17.  It's an Outlook style ListView which should do the trick for you.  Very customizable!

But it is an edit control and we are speaking about ListBox, can you provide an example for a listbox ?

This is what I've got for the moment. If you are interested in it tell me for any modifications. Added a lot more of code and functions Features Add, Insert or Delete(one or all) Item Call func

Posted Images

The macros are manipulated by autoit under the hood, I have no option to manipulate them( as far as I know).

Just use a different function and that is the identity that the editlist is pressed

Example

#include <EditList.au3>


Opt("GUIOnEventMode", 1)


$hMain = GUICreate("Test", 500, 300)
Global $hRichEdit_ = _Edit_List_Create(10, 10, 300, 200, $hMain)

$But1 = GUICtrlCreateButton("1", 330, 100, 40, 40)
GUICtrlSetOnEvent(-1, "OnClick_Handler")

$But2 = GUICtrlCreateButton("2", 380, 100, 40, 40)
GUICtrlSetOnEvent(-1, "OnClick_Handler")


_Edit_List_InsertItem("1. The usual high-level elements for functions, loops and expression-handling." & @CRLF)
_Edit_List_InsertItem("2. A staggering amount of string handling functions and a Perl Compatible Regular Expression Engine(PCRE)" & @CRLF)
_Edit_List_InsertItem("3. COM support" & @CRLF)
_Edit_List_InsertItem("4. Call Win32 and Third-Party DLL APIs." & @CRLF)
_Edit_List_InsertItem("1. The usual high-level elements for functions, loops and expression-handling." & @CRLF)
_Edit_List_InsertItem("2. A staggering amount of string handling functions and a Perl Compatible Regular Expression Engine(PCRE)" & @CRLF)
_Edit_List_InsertItem("3. COM support" & @CRLF)
_Edit_List_InsertItem("4. Call Win32 and Third-Party DLL APIs." & @CRLF)
_Edit_List_SetOnEvent("OnClick_RichEditHandler")


GUISetState()

_SendMessage($hRichEdit_, $WM_SETFOCUS) ;required for initial hiding of the caret

While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Func OnClick_Handler()

    If @GUI_CtrlId = $But1 Then
        ConsoleWrite("Press Button 1" & @CRLF)
    ElseIf @GUI_CtrlId = $But2 Then
        ConsoleWrite("Press Button 2" & @CRLF)
    EndIf

EndFunc   ;==>OnClick_Handler

Func OnClick_RichEditHandler()
    ConsoleWrite("RichEdit Pressed")
EndFunc

Regards :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites
That's a pity! I have one big function for processing. Difficult otherwise.
But thanks anyway.
 
Very grateful, PhoenixXL, for your continued support! :)
 
And nothing you can do to when the focus to another control on the selection does not disappear?
Link to post
Share on other sites

Done!!

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites

Done..!

Happy New Year and Merry Christmas :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites
Continue to improve on the idea.
PhoenixXL, is it possible to change the mouse cursor when it is placed over the EL?
Tried to apply the standard function(GUICtrlSetCursor) changes the cursor, but it does not work.
 
And is there any hope that it will be possible to use two controls EL?
It's too good and he wants to use in multiple positions!
Edited by AndreyS
Link to post
Share on other sites

Cursor part is done.

To encorporate multiple edit lists global variables just should be converted to arrays so that data of multiple items could be added and retreived,

converting the whole script back to using arrays would consume much time. I leave it to you as this isn't that hard.

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites
I do not understand why, but I started to be an error in the file  Resources.au3 after upgrading to a new release Autoit.
Yes, I use the function of this file and the bug seems to reconnect this file in the file EditList.au3.
How to solve this problem, PhoenixXL?
 
Error:
"D:\Program Files\AutoIt3\Include\Resources.au3"(9,28) : error: $RT_CURSOR previously declared as a 'Const'.
Global Const $RT_CURSOR = 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\Program Files\AutoIt3\Include\Resources.au3"(10,28) : error: $RT_BITMAP previously declared as a 'Const'.
Global Const $RT_BITMAP = 2
...
Link to post
Share on other sites

can you show me your includes as  i havent faced this problem

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites

Yes, of course that's my includes:

#include-once
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Date.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <GuiRichEdit.au3>
#include <Sound.au3>
#include <INet.au3>
#include <DateTimeConstants.au3>
#include <String.au3>
#include <ListboxConstants.au3>
#include <ID3_v3.4.au3>
#include <StringSize.au3>
#include <VLC.au3>
#include <SliderConstants.au3>
#include <GuiListBox.au3>
#include <MouseOnEvent.au3>
#include <GUIMenu.au3>
#include <EditList.au3> 
#include <Resources.au3>

The problem in the latter two files. They are duplicate include files and therefore is re-declare constants. But why this error started to arise as soon as I changed the release Autoit and how to solve it if I need to also use functions Resurces.au3?

Link to post
Share on other sites

Then its a problem in #include <Resources.au3>.  As it is not updated with the new release.

comment out the declaration lines in the UDF that give you the error of redeclaration.

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites
Then tell me which file to comment out the best constants?
 
   D: \ Program Files \ AutoIt3 \ Include \ APIResConstants.au3 (1 hit)
Line 19: Global Const $ RT_CURSOR = 1
...

or

   D: \ Program Files \ AutoIt3 \ Include \ Resources.au3 (1 hit)
Line 9: Global Const $ RT_CURSOR = 1 
...
Link to post
Share on other sites
the one in resources.au3
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites

Thanks, and did!

 
PhoenixXL, has immediate tasks / problems .
 
1. When filling EL items present in it for some reason some invisible last item on which you can even carry a click. How to get rid of this false item? So that when you click anywhere on a particular item stood out .
 
 
2 . After filling EL many items I need to make the transition to the very first item. I do it like this: 
_GUICtrlRichEdit_SetScrollPos($EditList, 1, 1)
But the trouble is that when the text cursor appears at the end of the items.
What he finds there is an invisible last position, I think it is related to the first problem somehow. I would like to have a special function to work correctly in EditList.au3
 
 
Need your help again...
Link to post
Share on other sites

Its maybe you are using @CRLF in the text, so that, it is even a part of the item.

To get rid of it set the Appendstring to "@CRLF & @CRLF" in _Edit_List_Create.

Further I could be more helpful if you can show me through an example.

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites
And it does not matter at all. Okey, here is the same example that demonstrates two problems at once. 
 
1. Scroll down and there will be a cursor that should not be there.
2. Clicking can be done at the end all the items, which should highlight the last item. But this is not happening. There is even a kind of incomprehensible last line empty.
#include <EditList.au3>


$hMain = GUICreate("Test", 500, 300)
Global $hRichEdit_ = _Edit_List_Create(10, 10, 300, 200, $hMain)

_Edit_List_InsertItem("1. The usual high-level elements for functions, loops and expression-handling.")
_Edit_List_InsertItem("2. A staggering amount of string handling functions and a Perl Compatible Regular Expression Engine(PCRE)")
_Edit_List_InsertItem("3. COM support")
_Edit_List_InsertItem("4. Call Win32 and Third-Party DLL APIs.")
_Edit_List_InsertItem("1. The usual high-level elements for functions, loops and expression-handling.")
_Edit_List_InsertItem("2. A staggering amount of string handling functions and a Perl Compatible Regular Expression Engine(PCRE)")
_Edit_List_InsertItem("3. COM support")
_Edit_List_InsertItem("4. Call Win32 and Third-Party DLL APIs.")
_Edit_List_SetOnEvent("OnClick_Handler")

_GUICtrlRichEdit_SetScrollPos($hRichEdit_, 0, 0)

_Edit_List_SetOnEvent("OnClick_Handler")


GUISetState()


While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Func OnClick_Handler()
    MsgBox(0,_GUICtrlRichEdit_IsTextSelected ( $hRichEdit_ ),_Edit_List_GetItemText())
EndFunc
Link to post
Share on other sites
  • 5 weeks later...
Hello PhoenixXL! 
Use your UDF. It is almost perfect! 
 
I'd love to to have another opportunity to use several EL.
 
Trying to do it, but the problem occurs in function _NewWnd_Proc_ (): 

"D:Program FilesAutoIt3IncludeEditList_.au3"(162,57) : warning: $h_ControlHwnd: possibly used before declaration.
                        _Edit_List_SetSel($h_ControlHwnd,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:Program FilesAutoIt3IncludeEditList_.au3"(162,57) : error: $h_ControlHwnd: undeclared global variable.
                        _Edit_List_SetSel($h_ControlHwnd,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

 

 

 
Tell me, please, how can I fix this error?
 
#include-once
#include <Array.au3>
#include <WinAPISys.au3>
#include <WinAPIRes.au3>
#include <APISysConstants.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

; = = = = = = .  . . . Private UDF Global Variables ===========================================================

Global $aItems[1] ;stores Item indexes
Global $sAppend ;stores Item delimited
Global $__hCur  ;stores the handle to the cursor
;~ Global $h_ControlHwnd ;stores the handle of the control.
Global $p_Original_WindowProc ;stores the original window procedure(WndProc) of the edit control.

Global $h_NewWndProc = DllCallbackRegister("_NewWnd_Proc_", "int", "hwnd;uint;wparam;lparam") ;hanlde to the new WndProc
Global $p_NewWndProc = DllCallbackGetPtr($h_NewWndProc) ;pointer to the new WndProc.

Global $s_OnEventFunc ;string storing the name of the func to call upon click.

Func _Edit_List_Create($iX, $iY, $iWidth, $iHeight, $hWin, $sAppendString = -1)

    $h_ControlHwnd = _GUICtrlRichEdit_Create($hWin, "", $iX, $iY, $iWidth, $iHeight, BitOR($WS_TABSTOP, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL))
;~     OnAutoItExitRegister("Destroy")

    $p_Original_WindowProc = _Subclass_($h_ControlHwnd, $p_NewWndProc)

    _GUICtrlRichEdit_SetText($h_ControlHwnd, "")

    If $sAppendString = -1 Then $sAppendString = @LF
    $sAppend = $sAppendString
    $aItems[0] = -StringLen($sAppend)

    Return $h_ControlHwnd ;

EndFunc   ;==>_Edit_List_Create

Func _Edit_List_InsertItem($h_ControlHwnd, $s_Text, $iIndex = -1)

    Local $sEdit_Text = _GUICtrlRichEdit_GetText($h_ControlHwnd)
    Local $iMaxLen = StringLen($sEdit_Text)

    If IsInt($iIndex) = 0 Then Return SetError(2, 0, 0) ;bad $iIndex
    $s_Text = StringRegExpReplace($s_Text, "\v+", @LF)

    If $iIndex >= UBound($aItems) Then Return SetError(3, 0, 0)

    If $iIndex >= 1 Then

        Local $iUbound = UBound($aItems)
        If $iIndex > $iUbound Then Return SetError(3, 0, 0) ;bad $iIndex

        _GUICtrlRichEdit_GotoCharPos($h_ControlHwnd, $aItems[$iIndex - 1] + StringLen($sAppend))
        _GUICtrlRichEdit_InsertText($h_ControlHwnd, $s_Text & $sAppend)

        Local $Change = StringLen($s_Text & $sAppend)

        _ArrayInsert($aItems, $iIndex - 1, $aItems[$iIndex - 1])
        ;reset the array
        For $i = $iIndex To $iUbound
            $aItems[$i] += $Change
        Next


    ElseIf $iIndex = -1 Then

        _ArrayAdd($aItems, StringLen($sEdit_Text & $s_Text))
        _GUICtrlRichEdit_AppendText($h_ControlHwnd, $s_Text & $sAppend)

    Else
        Return SetError(1, 0, 0) ;$iIndex parameter is wrong.
    EndIf

    Return 1

EndFunc   ;==>_Edit_List_InsertItem

Func _Edit_List_GetItemText($h_ControlHwnd, $iIndex = -1) ;by default gets the selected items text
    If $iIndex = -1 Then Return _GUICtrlRichEdit_GetSelText($h_ControlHwnd)
    If $iIndex <= 0 Or IsInt($iIndex) = 0 Then Return SetError(1, 0, 0)
    If $iIndex >= UBound($aItems) Then Return SetError(3, 0, 0)
    Return _GUICtrlRichEdit_GetTextInRange($h_ControlHwnd, $aItems[$iIndex - 1] + StringLen($sAppend), $aItems[$iIndex])
EndFunc   ;==>_Edit_List_GetItemText

Func _Edit_List_GetSelItemIndex($h_ControlHwnd)
    Local $iLowerIndex = _GUICtrlRichEdit_GetSel($h_ControlHwnd)
    If @error Then Return SetError(1, @error, 0)
    $iLowerIndex = $iLowerIndex[0]

    For $i = 1 To UBound($aItems) - 1
        Switch $iLowerIndex
            Case $aItems[$i - 1] + StringLen($sAppend) To $aItems[$i]
                Return $i
        EndSwitch
    Next

    Return SetError(2, 0, 0)
EndFunc   ;==>_Edit_List_GetSelItemIndex

;The Following function was works using the functions of the already present library.
;Therefore it would work with both OnEvent as well as MsgLoop methods.
;PS: The OnEvent macros won't work like @GUI_CTRLID, etc.
;Use _Edit_List_SetOnClick("") to deregister an already registered function.
;The function should not have any parameter.
Func _Edit_List_SetOnEvent($h_ControlHwnd, $s_FuncName)
    $s_OnEventFunc = $s_FuncName
EndFunc   ;==>_Edit_List_SetOnEvent


Func _Edit_List_SetCursor($h_ControlHwnd, $hCursor)
    $__hCur = $hCursor;_WinAPI_CopyCursor()
EndFunc

Func _Edit_List_SetSel($h_ControlHwnd, $iIndex, $iReverse = False)
    ;key: the index of the array is the length of the item,
    ;use the index of the previous item to get the initial position of the required item
    If IsInt($iIndex) = 0 Or $iIndex < 1 Or $iIndex >= UBound($aItems) Then Return SetError(1, 0, 0)

    Local $iAnchor = $aItems[$iIndex - 1] + StringLen($sAppend)
    Local $iActive = $aItems[$iIndex]

    If $iReverse Then _ArraySwap($iActive, $iAnchor)

    Return _GUICtrlRichEdit_SetSel($h_ControlHwnd, $iAnchor, $iActive)
EndFunc   ;==>_Edit_List_SetSel

Func _Edit_List_RemoveItem($h_ControlHwnd, $iIndex)

    If $iIndex >= UBound($aItems) Then Return SetError(3, 0, 0)

    _GUICtrlRichEdit_SetSel($h_ControlHwnd, $aItems[$iIndex - 1] + StringLen($sAppend), $aItems[$iIndex] + 1)
    _GUICtrlRichEdit_ReplaceText($h_ControlHwnd, "", False)

    Local $Change = StringLen(_Edit_List_GetItemText($iIndex) & $sAppend)

    _ArrayDelete($aItems, $iIndex)
    ;reset the array
    For $i = $iIndex To UBound($aItems) - 1
        $aItems[$i] -= $Change
    Next

    _SendMessage($h_ControlHwnd, $WM_SETFOCUS)

EndFunc   ;==>_Edit_List_RemoveItem

Func _NewWnd_Proc_($hWnd, $iMsg, $wParam, $lParam)

    Switch $iMsg

        Case $WM_LBUTTONDOWN, $WM_LBUTTONDBLCLK

            $iX = _WinAPI_LoWord($lParam)
            $iY = _WinAPI_HiWord($lParam)
            $iChar = _GUICtrlRichEdit_GetCharPosFromXY($hWnd, $iX, $iY);

            For $n = 1 To UBound($aItems) - 1
                Switch $iChar
                    Case $aItems[$n - 1] + StringLen($sAppend) To $aItems[$n]

                        _Edit_List_SetSel($h_ControlHwnd,$n, 1)
                        _GUICtrlRichEdit_ScrollToCaret($hWnd)

                EndSwitch
            Next

            Call($s_OnEventFunc)
            Return 0;

        Case $WM_SETFOCUS, $WM_KILLFOCUS
            Local $iRet = _WinAPI_CallWindowProc($p_Original_WindowProc, $hWnd, $iMsg, $wParam, $lParam)

            Switch $iMsg
                Case $WM_KILLFOCUS

                    DllCall("user32.dll", "int", "ShowCaret", "hwnd", $hWnd)

                Case $WM_SETFOCUS
                    DllCall("user32.dll", "int", "HideCaret", "hwnd", $hWnd)
            EndSwitch

            Return $iRet

        Case $WM_RBUTTONDOWN, $WM_CHAR
            Return 0

        Case $WM_SETCURSOR
            If $__hCur <> 0 And _WinAPI_LoWord($lParam) = 1 Then Return _WinAPI_SetCursor($__hCur)  ;lparam = hittest = 1 = client area

        Case $WM_KEYDOWN

            Local Const $VK_UP_ = 0x26
            Local Const $VK_DOWN_ = 0x28
            Local Const $VK_ENTER_ = 0x0D

            Switch $wParam
                Case $VK_UP_, $VK_DOWN_

                    _Edit_List_SetSel($h_ControlHwnd,_Edit_List_GetSelItemIndex($h_ControlHwnd) + $wParam - 0x27, $wParam - 0x28)
                    _GUICtrlRichEdit_ScrollToCaret($hWnd)

                Case $VK_ENTER_

                    Call($s_OnEventFunc)

            EndSwitch
            Return 0

    EndSwitch

    ;go with the original processing.
    Return _WinAPI_CallWindowProc($p_Original_WindowProc, $hWnd, $iMsg, $wParam, $lParam)

EndFunc   ;==>_NewWnd_Proc_

Func _Subclass_($hWnd, $pNew_WndProc)

    ;substitute the WndProc of the control.
    Return _WinAPI_SetWindowLong ($hWnd, $GWL_WNDPROC, $pNew_WndProc)

EndFunc   ;==>_Subclass_

Func Destroy($h_ControlHwnd)

    _Subclass_($h_ControlHwnd, $p_Original_WindowProc)
    _GUICtrlRichEdit_Destroy($h_ControlHwnd)
    _WinAPI_DestroyCursor($__hCur)

EndFunc   ;==>Destroy

Func _Edit_List_Clear($h_ControlHwnd)
    ReDim $aItems[1]
    Local $iRet = _GUICtrlRichEdit_SetText($h_ControlHwnd, "")
    _SendMessage($h_ControlHwnd, $WM_SETFOCUS)

    Return $iRet
EndFunc   ;==>_Edit_List_Clear
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By RAMzor
      Hello all,
      I am trying to get scrolling events for ListBox (mouse wheel and up/down arrows) but without success. The event not occured on row change but if I click on it - yes
      The ComboBox works fine even if not in focus (with mouse wheel) but I prefer visual look of ListBox. In addition to all, I can't change the height of control. Unfortunately it depends only on font size and same fonts has different heights between InputBox and ComboBox
      Is there a way to get over the issue?
      Any other ideas for unit selection realization are welcome
      #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global $idCombo, $idComboUnit, $idList, $idListUnit Global $sComboInitUnit = "pJ", $fComboVal = 7.5 Global $sListInitUnit = "nF", $fListVal = 0.15 Units_Conversion_Example() Func Units_Conversion_Example() ; Create GUI GUICreate("Units Conversion", 400, 296) $idCombo = GUICtrlCreateInput($fComboVal, 22, 20, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idComboUnit = GUICtrlCreateCombo("", 112, 20, 50, 30) GUICtrlSetData(-1, "uJ|nJ|pJ", $sComboInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idList = GUICtrlCreateInput($fListVal, 22, 80, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idListUnit = GUICtrlCreateList("", 112, 80, 57, 26, BitOR($LBS_NOTIFY,$LBS_NOSEL,$WS_VSCROLL)) GUICtrlSetData(-1, "uF|nF|pF", $sListInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Do Sleep(5) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo, $hWndListBox If Not IsHWnd($idComboUnit) Then $hWndCombo = GUICtrlGetHandle($idComboUnit) If Not IsHWnd($idListUnit) Then $hWndListBox = GUICtrlGetHandle($idListUnit) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndCombo Switch $iCode Case $LBN_SELCHANGE ConsoleWrite(GUICtrlRead($idComboUnit) & @CRLF) EndSwitch Case $hWndListBox Switch $iCode Case $CBN_SELCHANGE ConsoleWrite(GUICtrlRead($idListUnit) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND  
       
    • By Dan_555
      Hi, here are few functions for the ListBox.
      I have searched the forum, but most of the functions are for listview, so i took one example code from melba23 (clear selection) and
      wrote few more functions. (Because my current project needs them).
       
      These functions work only on a Multi-selection ListBox . 
      Edit: Only 1 function does not work with single selection box.
      The functions do: Clear Selection, Delete Selected items, Invert Selection, Move selected items up and down.
       The example code has 2 Listboxes. The selected items on the left ListBox can be moved up and down. The right Listbox has buttons for the other functions.
      #include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> Local $singlesel = 0, $iMsgBoxAnswer = 0 ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question, Modality=Task Modal $iMsgBoxAnswer = MsgBox(8228, "Choose Listbox selecton type", "Yes for single, No for multi selection box") If $iMsgBoxAnswer = 6 Then $singlesel = 1 ;Yes Local $BL_1,$BL_2,$BR_1,$BR_2,$BR_3,$BR_4,$BR_5,$BR_6 Global $hForm1 = GUICreate("Listbox test", 349, 287) $LB_1 = GUICtrlCreateList("", 6, 40, 157, 244, BitOR($LBS_NOTIFY, $LBS_MULTIPLESEL, $WS_HSCROLL, $WS_VSCROLL, $LBS_DISABLENOSCROLL)) If $singlesel = 1 Then $LB_2 = GUICtrlCreateList("", 179, 40, 157, 244, BitOR($LBS_NOTIFY, $WS_HSCROLL, $WS_VSCROLL, $LBS_DISABLENOSCROLL)) Else $LB_2 = GUICtrlCreateList("", 179, 40, 157, 244, BitOR($LBS_NOTIFY, $LBS_MULTIPLESEL, $WS_HSCROLL, $WS_VSCROLL, $LBS_DISABLENOSCROLL)) $BR_3 = GUICtrlCreateButton("Reverse Sel", 272, 22, 68, 17) EndIf $BL_1 = GUICtrlCreateButton("Up", 20, 3, 35, 18) $BL_2 = GUICtrlCreateButton("Down", 60, 3, 35, 18) $BR_1 = GUICtrlCreateButton("Up", 200, 3, 35, 18) $BR_2 = GUICtrlCreateButton("Down", 240, 3, 35, 18) $BR_4 = GUICtrlCreateButton("Clear Sel", 217, 22, 52, 17) $BR_5 = GUICtrlCreateButton("Delete", 175, 22, 40, 17) $BR_6 = GUICtrlCreateButton("Populate", 290, 3, 50, 18) GUISetState(@SW_SHOW) For $x = 0 To 50 If $x <= 10 Then GUICtrlSetData($LB_1, $x & " test", 0) GUICtrlSetData($LB_2, $x & " Test", 0) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $BL_1 $a = Listbox_ItemMoveUD($LB_1, -1) If $a > -1 Then WinSetTitle($hForm1, "", "Moved items: " & $a) Case $BL_2 $a = Listbox_ItemMoveUD($LB_1, 1) If $a > -1 Then WinSetTitle($hForm1, "", "Moved items: " & $a) Case $BR_1 Listbox_ItemMoveUD($LB_2, -1) Case $BR_2 Listbox_ItemMoveUD($LB_2, 1) Case $BR_3 Listbox_ReverseSelection($LB_2) Case $BR_4 Listbox_ClearSelection($LB_2) Case $BR_5 Listbox_DeleteSelectedItems($LB_2) Case $BR_6 ;Populate GUICtrlSetData($LB_2, "") ; Clears the listbox For $x = 0 To 50 GUICtrlSetData($LB_2, $x & " Test", 0) Next EndSwitch WEnd ;note $hLB_ID - is the Listbox id Func Listbox_DeleteSelectedItems($hLB_ID) Local $aSel = _GUICtrlListBox_GetSelItems($hLB_ID) ;Get selected items Local $i, $slb = 0, $y, $x If $aSel[0] = 0 Then ;If the array is empty, there is no selection, or it is a single selection listbox For $x = 0 To _GUICtrlListBox_GetCount($hLB_ID) - 1 $y = _GUICtrlListBox_GetSel($hLB_ID, $x) If $y = True Then $slb = 1 _GUICtrlListBox_DeleteString($hLB_ID, $x) ;Perform a delete on single sel. LB ExitLoop EndIf Next EndIf If $slb = 0 Then _GUICtrlListBox_BeginUpdate($hLB_ID) For $i = $aSel[0] To 1 Step -1 ;Loop backwards and delete the selected items _GUICtrlListBox_DeleteString($hLB_ID, $aSel[$i]) Next _GUICtrlListBox_EndUpdate($hLB_ID) EndIf EndFunc ;==>Listbox_DeleteSelectedItems Func Listbox_ClearSelection($hLB_ID) ;Removes the selection from multi and single selection ListBox Local $aSel = _GUICtrlListBox_GetSelItems($hLB_ID) ;Code from Melba23 - Autoit Forum Local $slb, $x, $y If $aSel[0] = 0 Then _GUICtrlListBox_SetCurSel($hLB_ID, -1) $slb = 1 EndIf If $slb = 0 Then _GUICtrlListBox_BeginUpdate($hLB_ID) For $i = 1 To $aSel[0] _GUICtrlListBox_SetSel($hLB_ID, $aSel[$i], False) Next _GUICtrlListBox_EndUpdate($hLB_ID) EndIf EndFunc ;==>Listbox_ClearSelection Func Listbox_ReverseSelection($hLB_ID) ;Logically, this function works only on multi-selection listboxes Local $i Local $aCou = _GUICtrlListBox_GetCount($hLB_ID) Local $cSel = _GUICtrlListBox_GetCaretIndex($hLB_ID) ;Save the caret _GUICtrlListBox_BeginUpdate($hLB_ID) For $i = 0 To $aCou _GUICtrlListBox_SetSel($hLB_ID, $i, Not (_GUICtrlListBox_GetSel($hLB_ID, $i))) Next _GUICtrlListBox_SetCaretIndex($hLB_ID, $cSel) ;Restore the caret _GUICtrlListBox_EndUpdate($hLB_ID) EndFunc ;==>Listbox_ReverseSelection Func Listbox_ItemMoveUD($hLB_ID, $iDir = -1) ;Listbox_ItemMoveUD - Up/Down Move Multi/Single item in a ListBox ;$iDir: -1 up, 1 down ;Return values -1 nothing to do, 0 nothing moved, >0 performed moves Local $iCur, $iNxt, $aCou, $aSel, $i, $m = 0, $y, $slb = 0 ;Current, next, Count, Selection, loop , movecount $aSel = _GUICtrlListBox_GetSelItems($hLB_ID) ;Put selected items in an array $aCou = _GUICtrlListBox_GetCount($hLB_ID) ;Get total item count of the listbox If $aSel[0] = 0 Then $y = _GUICtrlListBox_GetCurSel($hLB_ID) If $y > -1 Then _ArrayAdd($aSel, $y) $aSel[0] = 1 $slb = 1 EndIf EndIf ;WinSetTitle($hGUI, "", $aSel[0]) ;Debugging info Select Case $iDir = -1 ;Move Up For $i = 1 To $aSel[0] If $aSel[$i] > 0 Then $iNxt = _GUICtrlListBox_GetText($hLB_ID, $aSel[$i] - 1) ;Save the selection index - 1 text _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i] - 1, _GUICtrlListBox_GetText($hLB_ID, $aSel[$i])) ;Replace the index-1 text with the index text _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i], $iNxt) ;Replace the selection with the saved var $m = $m + 1 EndIf Next For $i = 1 To $aSel[0] ;Restore the selections after moving If $aSel[$i] > 0 Then If $slb = 0 Then _GUICtrlListBox_SetSel($hLB_ID, $aSel[$i] - 1, 1) Else _GUICtrlListBox_SetCurSel($hLB_ID, $aSel[$i] - 1) EndIf EndIf Next Return $m Case $iDir = 1 ;Move Down If $aSel[0] > 0 Then For $i = $aSel[0] To 1 Step -1 If $aSel[$i] < $aCou - 1 Then $iNxt = _GUICtrlListBox_GetText($hLB_ID, $aSel[$i] + 1) _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i] + 1, _GUICtrlListBox_GetText($hLB_ID, $aSel[$i])) _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i], $iNxt) $m = $m + 1 EndIf Next EndIf For $i = $aSel[0] To 1 Step -1 ;Restore the selections after moving If $aSel[$i] < $aCou - 1 Then If $slb = 0 Then _GUICtrlListBox_SetSel($hLB_ID, $aSel[$i] + 1, 1) Else _GUICtrlListBox_SetCurSel($hLB_ID, $aSel[$i] + 1) EndIf EndIf Next Return $m EndSelect Return -1 EndFunc ;==>Listbox_ItemMoveUD  
    • By topgundcp
      Hi, 
      This is my very first post in this forum and am also new with Autoit programming so be easy on me.
      Below is the code that I am trying to get the index of the item selected. No problem getting the text.
      Case $listEdition   ; handle of the list             local $index=0             $item=GUICTRLRead($listEdition)    ; This will return the text in the list             ; ==============   The loop below always fails  ==================             ; Meaning _GUICtrlListView_GetItemSelected($listEdition, $i) always return FALSE. WHY ???????              For $i = 0 To $editionArray[0] - 1   ; The content of the list in an array where editionArray[0] contains total count of items                 If _GUICtrlListView_GetItemSelected($listEdition, $i) Then                     $index = $i                     exitloop                 EndIf              Next              ;===================================================             ConsoleWrite( "Select Edition:     " & $item & "  index: " & $index & @CR) ....... Please look at the comments in the code & the pix attached.
      _GUICtrlListView_GetItemSelected($listEdition, $i) always returns FALSE.
      Another problem is on the list. It also populate  the total count of items from the Array. How can I skip this item from populating to the list ?.
      Please advise and thanks

    • By kneze
      Hi
      first step i write ipconfig output to ipconfig.txt. Now i try to find all Adapters and get for each adapter: Adapter Name, Description, Media State and Mac Adress and put it to listbox. I search for "Ethernet Adapter" but they are other entrys like Wireless Adapter .. How can i get all Adapters from ipconfig.txt and information for each adapter Adapter Name, Description, Media State and Mac Adress and write to listbox ? 
      Would appreciate any help!
      #include <File.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 451, 328, 856, 237) $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 25) $List1 = GUICtrlCreateList("", 88, 8, 353, 305) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select ;Case $GUI_EVENT_CLOSE Case $msg = $GUI_EVENT_CLOSE Exitloop Case $msg = $Button1 $FilePath= "C:\temp\IPconfig.txt" $StringToSearch= "Ethernet adapter" $CaseSense=0 $Lines=_FileCountLines($FilePath) $hFile=FileOpen($FilePath,0) $Lines=_FileCountLines($FilePath) For $i=0 To Number($Lines) $Test=FileReadLine($hFile,$i) If StringInStr($Test,$StringToSearch,$CaseSense) Then $filereadAdapter = FileReadLine($hFile,$i) $filereadDescription = FileReadLine($hFile,$i+4) $filereadMediaState = FileReadLine($hFile,$i+2) $filereadMAcAdress = FileReadLine($hFile,$i+5) GUICtrlSetData($List1 , "Adapter: " & $filereadAdapter & @CRLF& "Description: "& $filereadDescription & @CRLF & "Media State: " & $filereadMediaState & @CRLF & "Mac Adress: " & $filereadMAcAdress& @CRLF) ;ExitLoop EndIf Next FileClose($hFile)  
       
    • By nacerbaaziz
      can we  create a list box with  Columns?
      welcome everybody
      Dears I have a question if you let me
      can we  create a list box with  Columns?
      i know we can create a list view with Columns
      but my question is about the list box
      I'm waiting your responses
      Thank you in advance
×
×
  • Create New...