Hi,
Not sure if this is the right area for this, so if it isn't I apologise.
I'm having trouble working out the logic in what I'm trying to do. I have a dialog box which has a listbox and several buttons. The main task would normally be: run the program, click on one of the items in the listbox, which would then automatically copy the item to the clipboard and close the window. The routine recognises the click on the listbox (id = 1) as Click% = 1 (actually Click% MOD &1000 = 1) and then follows the routine for copying and closing. The buttons (apart from the 'close' button) do various other things, specifically to do with a following selection of an item in the listbox - such as 'delete' (or they will do when I get round to writing the routines). However, when a button is pressed, the first figure to filter through is the listbox id (1) not the button that's just been clicked, which then comes after. (I believe it has something to do with the fact that it initially has focus.) I cannot figure out how to illuminate the listbox id being sent through when a button is pressed. It has to come through, as it needs to be a single click to copy the item to the clipboard. I appreciate that this would not normally be the routine, but I wanted the program to normally have as few clicks as possible. Can anyone think of a good way to accomplish this.
If this explanation makes no sense, then I apologise.
Matt
Listbox Selecting
-
- Posts: 78
- Joined: Sat 23 Jun 2018, 15:51
Re: Listbox Selecting
Shouldn't that be Click% MOD &10000 to get the low word?
A control ID of 1 is normally reserved for the OK button in Windows, ID=2 for the Close or Cancel buttons.
The control ID for the button will be different to that of the Listbox so can't you just use a CASE statement
Or is that not the question you are asking?
Z
A control ID of 1 is normally reserved for the OK button in Windows, ID=2 for the Close or Cancel buttons.
The control ID for the button will be different to that of the Listbox so can't you just use a CASE statement
Code: Select all
ON SYS Click%=@wparam% AND &FFFF
CASE Click% OF
WHEN ListboxID: .... do listbox stuff
WHEN Button1ID: .... do button action
ENDCASE
Z
-
- Posts: 114
- Joined: Mon 16 Apr 2018, 06:17
Re: Listbox Selecting
That's interesting. You're right it should be &10000. I had &1000 and was still getting 1.
The 'Close' button is 2. The Lixtbox is 1 partly because, with a normal routine, when clicking on the item in it the 'OK' is assumed and the window close. It's only when clicking on one of the other buttons would the 'OK' NOT be assumed. However, when clicking on one of the other buttons, the first id to come through is the listbox, which the program then assumes to have been clicked on.
A thought: is there a code that is also sent through which implies click ON the listbox and one that implies moving away from focus?
Matt
The 'Close' button is 2. The Lixtbox is 1 partly because, with a normal routine, when clicking on the item in it the 'OK' is assumed and the window close. It's only when clicking on one of the other buttons would the 'OK' NOT be assumed. However, when clicking on one of the other buttons, the first id to come through is the listbox, which the program then assumes to have been clicked on.
A thought: is there a code that is also sent through which implies click ON the listbox and one that implies moving away from focus?
Matt
-
- Posts: 78
- Joined: Sat 23 Jun 2018, 15:51
Re: Listbox Selecting
I think what you are missing is that the @wparam% contains information in the high word as well in Windows.
When you click on the List box you will get notification codes in this word. So if you look at @wparam% >>16 you will see perhaps one of these.
LBN_SELCANCEL = &3
LBN_SELCHANGE = &1 even if you click on one that is already selected!
LBN_SETFOCUS = &4
These notification message applies only to a list box that has the LBS_NOTIFY style.
And when you click on the button you will get another notification from the list box which is LBN_KILLFOCUS = &5 as it loses focus and then the click from the button.
Z
When you click on the List box you will get notification codes in this word. So if you look at @wparam% >>16 you will see perhaps one of these.
LBN_SELCANCEL = &3
LBN_SELCHANGE = &1 even if you click on one that is already selected!
LBN_SETFOCUS = &4
These notification message applies only to a list box that has the LBS_NOTIFY style.
And when you click on the button you will get another notification from the list box which is LBN_KILLFOCUS = &5 as it loses focus and then the click from the button.
Z
-
- Posts: 114
- Joined: Mon 16 Apr 2018, 06:17
Re: Listbox Selecting
Great. I think this might be what I'm looking for. Thanks. I can combine the two values (or take as a whole without AND &FFFF) to evaluate what's happening.
To be totally honest, I think I've been through something like this a few years back. So I should have remembered. That's the trouble with getting old.
To be totally honest, I think I've been through something like this a few years back. So I should have remembered. That's the trouble with getting old.

-
- Posts: 114
- Joined: Mon 16 Apr 2018, 06:17
Re: Listbox Selecting
Playing around with how I am going to do this, I noticed that the list box didn't always produce a LBN_SETFOCUS code when returning to the listbox - particularly when returning quickly. If I alternate clicking on a button and the listbox, it seems to produce a LBN_SETFOCUS code for the listbox almost at random. Sometimes it will produce a (LBN_SETFOCUS plus id) and then (LBN_SELCHANGE plus id), other times just (LBN_SELCHANGE plus id).
Any ideas why this is?
Matt
Any ideas why this is?
Matt
-
- Posts: 78
- Joined: Sat 23 Jun 2018, 15:51
Re: Listbox Selecting
It may be that you have no buffering to the interrupts and they are coming too fast. That is to say the one you are looking for is overwritten by a later one before you got to processing the interrupt in your main program polling loop. You can speed up the main loop or look at some interrupt buffering. You can find how to do that in the wiki: http://www.bbcbasic.co.uk/wiki/doku.php?id=queueing_20event_20interrupts
Z
Z
-
- Posts: 78
- Joined: Sat 23 Jun 2018, 15:51
Re: Listbox Selecting
Here is a short example program selecting list box items and using a minimal interrupt buffer.
It does not suffer the problems that you were experiencing Matt.
Note also that the LBS_NOTIFY style that I mentioned previously is already set out of the box in WINLIB2, something I had forgotten and personally the preset styles I find somewhat annoying although when starting out they are probably a boon.
Z
It does not suffer the problems that you were experiencing Matt.
Note also that the LBS_NOTIFY style that I mentioned previously is already set out of the box in WINLIB2, something I had forgotten and personally the preset styles I find somewhat annoying although when starting out they are probably a boon.
Code: Select all
INSTALL @lib$+"WINLIB2B"
LB_ADDSTRING = 384
LB_GETCURSEL = 392
Dlgt1% = FN_newdialog("Test Polling",125,40,153,61,8,700)
PROC_pushbutton(Dlgt1%,"Push",3,22,12,40,14,0)
PROC_listbox(Dlgt1%,"",4,89,12,40,40,0)
PROC_pushbutton(Dlgt1%,"OK",1,22,40,40,14,&20001)
PROC_pushbutton(Dlgt1%,"Cancel",2,89,40,42,14,&0)
PROC_showdialog(Dlgt1%)
SYS "SendDlgItemMessage", !Dlgt1%, 4, LB_ADDSTRING, 0, "item 0"
SYS "SendDlgItemMessage", !Dlgt1%, 4, LB_ADDSTRING, 0, "item 1"
SYS "SendDlgItemMessage", !Dlgt1%, 4, LB_ADDSTRING, 0, "item 2"
DIM Z%(20) :REM Define 20 event buffer
ON SYS Z%()=Z%(0)+(1 AND Z%(0)<20),@wparam%,Z%(1),Z%(2),Z%(3),Z%(4),Z%(5),Z%(6),Z%(7),Z%(8),Z%(9),Z%(10),Z%(11),Z%(12),Z%(13),Z%(14),Z%(15),Z%(16),Z%(17),Z%(18),Z%(19):RETURN
REM Main program idle loop
REPEAT
PROCDoEvents
UNTIL FALSE
END
DEF PROCDoEvents
LOCAL E%, R%
WHILE Z%(0) :REM Z%(0) is 0 if no event in the queue otherwise it points to the interrupt parameter @wparam%
E%=Z%(Z%(0))
Z%(0)-=1 :REM Z%(0) contains the pointer to the current event in the queue. Decrement as we take a value out of the queue
CASE E% AND &FFFF OF
WHEN 1: PRINT "OK"
WHEN 2: QUIT
WHEN 3: PRINT "I'm free!"
WHEN 4: IF (E%>>16) =1 : SYS "SendDlgItemMessage", !Dlgt1%, 4, LB_GETCURSEL , 0, 0 TO R% : PRINT "List ", R%
ENDCASE
REM ...
ENDCASE
ENDWHILE
WAIT 0
ENDPROC