1. Multi-list behavior under win32lib
- Posted by jjnick at cvn.com Apr 22, 2001
- 372 views
This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0CB8F.EE79DEA0 boundary="----=_NextPart_001_0008_01C0CB8F.EE79DEA0" ------=_NextPart_001_0008_01C0CB8F.EE79DEA0 charset="iso-8859-1" I am confident the following is a problem with win32lib (has this been = fixed in later version of win32lib, I am using v0.50)? Here is the sample code for those worried about viruses: -- Under win32lib v0.50, the following behavior occurs using = multi-select list boxes . . . --=20 -- Gathering whether a user selected items in a multi-select list box = gives -- erroneous info using provided functions in win32lib. Running the = sample below showcases -- this behavior. The ability to check whether or not a user has = selected anything is -- because if this is not done before accessing the getMultItems(), an = error occurs -- within win32lib. -- -- getIndex() works fine in a single select list box. --=20 -- Please note: LB_GETANCHORINDEX works initially, but once an item is = selected and then -- deselected, LB_ANCHORINDEX remembers previous item = selected and returns result include win32lib.ew without warning constant Win =3D create ( Window, "Showcase Multi-List problem", = 0, Default, Default, 300, 150, 0 ), Button1 =3D create ( PushButton, "Use getIndex()", = Win, 120, 10, 150, 30, 0 ), Button2 =3D create ( PushButton, "Use LB_GETSELCOUNT", = Win, 120, 60, 150, 30, 0 ), List1 =3D create ( SortedList, "", = Win, 10, 10, 100, 100, LBS_EXTENDEDSEL ) addItem(List1, "> Item 1 <") addItem(List1, "> Item 2 <") addItem(List1, "> Item 3 <") addItem(List1, "> Item 4 <") addItem(List1, "> Item 5 <") addItem(List1, "> Item 6 <") addItem(List1, "> Item 7 <") setEnable ( List1, False ) procedure onClick_Button1() atom test object result =20 test =3D getIndex( List1 ) result =3D message_box (sprintf( "getIndex() still returns a value = even though nothing is selected!: %d", test ), "Test multi-list", = MB_ICONERROR+MB_TASKMODAL ) =20 end procedure procedure onClick_Button2() atom test object result test =3D sendMessage(List1, LB_GETSELCOUNT, 0, 0) result =3D message_box(sprintf( "However, using LB_GETSELCOUNT = provides the correct result: %d", test ), "Test multi-list", = MB_ICONINFORMATION+MB_TASKMODAL ) end procedure onClick [ Button1 ] =3D routine_id( "onClick_Button1" ) onClick [ Button2 ] =3D routine_id( "onClick_Button2" ) WinMain( Win, Normal ) ------=_NextPart_001_0008_01C0CB8F.EE79DEA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY> <DIV><FONT face=3DArial size=3D2>I am confident the following is a = problem=20 with win32lib (has this been fixed in later version of = win32lib, I am=20 using v0.50)?</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Here is the sample code for those = worried about=20 viruses:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>-- Under win32lib v0.50, the = following=20 behavior occurs using multi-select list boxes . . .<BR>-- <BR>-- = Gathering=20 whether a user selected items in a multi-select list box gives<BR>-- = erroneous=20 info using provided functions in win32lib. Running the sample = below=20 showcases<BR>-- this behavior. The ability to check whether or not = a user=20 has selected anything is<BR>-- because if this is not done before = accessing the=20 getMultItems(), an error occurs<BR>-- within win32lib.<BR>--<BR>-- = getIndex()=20 works fine in a single select list box.<BR>-- <BR>-- Please note:=20 LB_GETANCHORINDEX works initially, but once an item is selected and=20 then<BR>-- &nb= sp; =20 deselected, LB_ANCHORINDEX remembers previous item selected and returns=20 result</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>include win32lib.ew<BR>without=20 warning</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>constant<BR> =20 Win =3D create (=20 Window, "Showcase Multi-List=20 problem", &nbs= p; =20 0, Default, Default, 300, 150, 0=20 ),<BR> Button1 =3D create (=20 PushButton, "Use=20 getIndex()", &= nbsp; &n= bsp;=20 Win, 120, 10, = 150, =20 30, 0 ),<BR> Button2 =3D create (=20 PushButton, "Use=20 LB_GETSELCOUNT", &nb= sp; =20 Win, 120, 60, = 150, =20 30, 0 ),<BR> List1 =3D create (=20 SortedList, =20 "", &nbs= p;  = ; = =20 Win, 10, 10, = 100,=20 100, LBS_EXTENDEDSEL )</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>addItem(List1, "> Item 1=20 <")<BR>addItem(List1, "> Item 2 <")<BR>addItem(List1, "> = Item 3=20 <")<BR>addItem(List1, "> Item 4 <")<BR>addItem(List1, "> = Item 5=20 <")<BR>addItem(List1, "> Item 6 <")<BR>addItem(List1, "> = Item 7=20 <")</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>setEnable ( List1, False = )</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>procedure = onClick_Button1()<BR> atom=20 test<BR> object result<BR> <BR> test =3D getIndex( List1=20 )<BR> result =3D message_box (sprintf( "getIndex() still returns a = value=20 even though nothing is selected!: %d", test ), "Test multi-list",=20 MB_ICONERROR+MB_TASKMODAL ) = <BR>end=20 procedure</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>procedure = onClick_Button2()<BR> atom=20 test<BR> object result</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1> test =3D = sendMessage(List1,=20 LB_GETSELCOUNT, 0, 0)<BR> result =3D message_box(sprintf( = "However, using=20 LB_GETSELCOUNT provides the correct result: %d", test ), "Test = multi-list",=20 MB_ICONINFORMATION+MB_TASKMODAL )<BR>end procedure</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>onClick [=20 Button1 ] =3D routine_id( = "onClick_Button1"=20 )<BR>onClick [ Button2 ] =3D = routine_id(=20 "onClick_Button2" )</FONT></DIV> <DIV><FONT face=3D"Courier New" size=3D1></FONT> </DIV> <DIV><FONT face=3D"Courier New" size=3D1>WinMain( Win, Normal=20 ------=_NextPart_001_0008_01C0CB8F.EE79DEA0-- ------=_NextPart_000_0007_01C0CB8F.EE79DEA0 Content-Type: application/octet-stream; name="Multi-list problem.exw" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Multi-list problem.exw" -- Under win32lib v0.50, the following behavior occurs using = multi-select list boxes . . . --=20 -- Gathering whether a user selected items in a multi-select list box = gives -- erroneous info using provided functions in win32lib. Running the = sample below showcases -- this behavior. The ability to check whether or not a user has = selected anything is -- because if this is not done before accessing the getMultItems(), an = error occurs -- within win32lib. -- -- getIndex() works fine in a single select list box. --=20 -- Please note: LB_GETANCHORINDEX works initially, but once an item is = selected and then -- deselected, LB_ANCHORINDEX remembers previous item = selected and returns result include win32lib.ew without warning constant Win =3D create ( Window, "Showcase Multi-List problem", = 0, Default, Default, 300, 150, 0 ), Button1 =3D create ( PushButton, "Use getIndex()", = Win, 120, 10, 150, 30, 0 ), Button2 =3D create ( PushButton, "Use LB_GETSELCOUNT", = Win, 120, 60, 150, 30, 0 ), List1 =3D create ( SortedList, "", = Win, 10, 10, 100, 100, LBS_EXTENDEDSEL ) addItem(List1, "> Item 1 <") addItem(List1, "> Item 2 <") addItem(List1, "> Item 3 <") addItem(List1, "> Item 4 <") addItem(List1, "> Item 5 <") addItem(List1, "> Item 6 <") addItem(List1, "> Item 7 <") setEnable ( List1, False ) procedure onClick_Button1() atom test object result =09 test =3D getIndex( List1 ) result =3D message_box (sprintf( "getIndex() still returns a value = even though nothing is selected!: %d", test ), "Test multi-list", = MB_ICONERROR+MB_TASKMODAL ) =20 end procedure procedure onClick_Button2() atom test object result test =3D sendMessage(List1, LB_GETSELCOUNT, 0, 0) result =3D message_box(sprintf( "However, using LB_GETSELCOUNT = provides the correct result: %d", test ), "Test multi-list", = MB_ICONINFORMATION+MB_TASKMODAL ) end procedure onClick [ Button1 ] =3D routine_id( "onClick_Button1" ) onClick [ Button2 ] =3D routine_id( "onClick_Button2" ) WinMain( Win, Normal ) ------=_NextPart_000_0007_01C0CB8F.EE79DEA0--
2. Re: Multi-list behavior under win32lib
- Posted by jjnick at cvn.com Apr 23, 2001
- 361 views
----- Original Message ----- From: "Derek Parnell" <ddparnell at bigpond.com> To: "EUforum" <EUforum at topica.com> Subject: RE: Multi-list behavior under win32lib > Hi "jjnick at cvn.com", > you have discovered a bug - sort of. The main problem is that getIndex() was > only designed to be used on single-selection listboxes. It works fine it > those cases. I know how to "fix" it to work with multi-select lists but the > problem I have is 'What do I return?' If multiple items are selected then > the obvious choice is a sequence of indexes. But this might break some code > that assigns the return value to an atom or integer. What do you guys think > I ought to do? > > My preference is to return a sequence of indexes when the list is a > multiple-select type and an integer otherwise. An empty list would indicate > that nothing is selected. I tried "getMultIndices( id )" just now and and it also doesn't provide the correct result (don't know why I didn't try this last night! ). My contention is that if multi-selection boxes are supported in win32lib, then how come there isn't the facility to detect whether or not a user has selected anything from the list accurately? If I just call "getMultItems()" without checking to see whether a user has selected an item first, an error comes up in win32lib itself . . . Anyway, you probably know all this, just reiterating . . . > Here is the Microsoft documentation on the LB_GETCURSEL message, which is > currently being used in Win32lib. Please note the *Remarks* when used with > multi-selection lists. > > ------------------------------------- > *LB_GETCURSEL* > Send an LB_GETCURSEL message to retrieve the index of the currently selected > item, if any, in a single-selection list box. > > To send this message, call the SendMessage function with the following > parameters. > > SendMessage( > (HWND) hWnd, // handle to destination window > LB_GETCURSEL, // message to send > (WPARAM) wParam, // not used; must be zero > (LPARAM) lParam // not used; must be zero > ); > > *Parameters* > This message has no parameters. > > *Return Values* > In a single-selection list box, the return value is the zero-based index of > the currently selected item. If there is no selection, the return value is > LB_ERR. > > *Remarks* > Do not send this message to a multiple-selection list box. > > To retrieve the indexes of the selected items in a multiple-selection list > box, use the LB_GETSELITEMS message. To determine whether the item that has > the focus rectangle in a multiple selection list box is selected, use the > LB_GETSEL message. > > If sent to a multiple-selection list box, LB_GETCURSEL returns the index of > the item that has the focus rectangle. If no items are selected, it returns > zero. > > > ------------------------------------- > > cheers, > Derek Parnell > > > > >