BBC BASIC for Windows
Programming >> User Interface >> Unrequired dialog response.
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1370704114

Unrequired dialog response.
Post by Matt on Jun 8th, 2013, 1:25pm

Hi,

The following test program supplies an undesired response.

Code:
      LB_ADDSTRING = 384
      LB_RESETCONTENT = 388
      LB_GETCURSEL = 392
      INSTALL @lib$ + "WINLIB2B"
      ON SYS Click% = @wparam% AND &FFFF : RETURN
      dlg%=FN_newdialog(     "TEST",          0,  0,162,306, 8, 500) : dlg%!16 = &90C808C4
      PROC_pushbutton( dlg%, "OK",        1,  6,288, 42, 14, &20001)
      PROC_pushbutton( dlg%, "Cancel",    2,114,288, 42, 14, &0)
      PROC_static(     dlg%, "Test box",100,  6,  6,150, 10, &0)
      PROC_listbox(    dlg%, "",        101,  6, 18,150,274, &7E)
      PROC_showdialog(dlg%)
      SYS "SendDlgItemMessage", !dlg%, 101, LB_RESETCONTENT, 0, 0
      FOR i% = 0 TO 9
        SYS "SendDlgItemMessage", !dlg%, 101, LB_ADDSTRING, 0, "Line "+STR$(i%)
      NEXT
      Click% = 0 : sel% = -1
      REPEAT
        REPEAT click% = 0 : WAIT 1 : SWAP Click%, click% : UNTIL click% <> 0
        IF click% = 101 THEN SYS "SendDlgItemMessage", !dlg%, 101, LB_GETCURSEL, 0, 0 TO sel%
        PRINT click%, sel%
      UNTIL click% = 1 OR click% = 2 OR !dlg% = 0
      IF !dlg%>0 THEN PROC_closedialog(dlg%)
      END
 

When you first click on the listbox, the resulting click is, in fact, showing up as two clicks (I appreciate that this might not be technically a 'click') This only happens when information is inserted into the box first, as in the program. Now, I want to be able to click on the box's list to gain the selected item's index, and that item might be the same one twice in a row. However, an apparent double clicking is not required. I can come up with a complicated routine for ignoring the first click, but I wondered if anyone knew of a simple way to stop this?

Matt
Re: Unrequired dialog response.
Post by admin on Jun 8th, 2013, 2:55pm

on Jun 8th, 2013, 1:25pm, Matt wrote:
I can come up with a complicated routine for ignoring the first click, but I wondered if anyone knew of a simple way to stop this?

I don't really understand what the problem is. You are choosing to ignore the @lparam% value, and to throw away the high 16-bits of the @wparam% value, so you can hardly complain that as a result it is difficult to separate the various notifications! It would surely be better to keep all the information which the ON SYS gives to you, then you can easily distinguish one notification from another.

I would almost always choose to use this code (or something similar) to ensure I don't discard useful information:

Code:
ON SYS Click%() = @wparam%,@lparam% : RETURN
 


Richard.

Re: Unrequired dialog response.
Post by Matt on Jun 8th, 2013, 5:16pm

on Jun 8th, 2013, 2:55pm, Richard Russell wrote:
I don't really understand what the problem is. You are choosing to ignore the @lparam% value, and to throw away the high 16-bits of the @wparam% value, so you can hardly complain that as a result it is difficult to separate the various notifications! It would surely be better to keep all the information which the ON SYS gives to you, then you can easily distinguish one notification from another.

I would almost always choose to use this code (or something similar) to ensure I don't discard useful information:

Code:
ON SYS Click%() = @wparam%,@lparam% : RETURN
 


My appologies, Richard. You're right. With a little experimenting, I've noticed the increase in information that I can get. The line : ON SYS Click% = @wparam% AND &FFFF : RETURN is one I've gleaned from somewhere early on and now use it most of the time, without fully understanding what it means. However, removing the AND &FFFF returns a value which includes the hiword and therefore doesn't immediately return the control id. Easy enought to overcome, but I'm guessing that's why it was used where I got it from.

Now I know there's more to it than that, I need to know what the values mean. I've tried looking on MSDN, but I'm getting bogged down. Any pointers?

In the (modified) example I gave, the loword gives the id value, and the hiword give a 4 initially, then reverts to 1, until a button is pressed. (No idea about lparam!) I can use these figures without knowing what they mean to establish the correct response by my code, but I'd like to find out more.

Matt

p.s. did you have a look at my other thread: PE Hangs with Module Viewer?
Re: Unrequired dialog response.
Post by admin on Jun 8th, 2013, 8:03pm

on Jun 8th, 2013, 5:16pm, Matt wrote:
I've tried looking on MSDN, but I'm getting bogged down. Any pointers?


If you're specifically interested in the List Box notifications there are details here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ff485968.aspx

Richard.

Re: Unrequired dialog response.
Post by Matt on Jun 8th, 2013, 9:08pm

Actually, it was more to do with the parameters wparam and lparam in general. For instance, it appears that the hiword of wparam in the case above, seems to give 1 and 2 for the single and double click. I don't know if this is just coincidence, or if this is actually the case. And, as stated before, I've no idea what lparam is. I'd like to know more, but preferably in layman's terms.

If my request is confusing, then I obviously know even less about it than I thought.

Matt
Re: Unrequired dialog response.
Post by admin on Jun 9th, 2013, 06:56am

on Jun 8th, 2013, 9:08pm, Matt wrote:
Actually, it was more to do with the parameters wparam and lparam in general. For instance, it appears that the hiword of wparam in the case above, seems to give 1 and 2 for the single and double click. I don't know if this is just coincidence, or if this is actually the case. And, as stated before, I've no idea what lparam is. I'd like to know more, but preferably in layman's terms.

But the link to MSDN I gave you provides exactly this information!! It says this:

wParam
The LOWORD contains the identifier of the list box. The HIWORD specifies the notification code.
lParam
Handle to the list box.


Given that the Windows Constants utility (for example) tells you the numeric values of the notification codes, I don't understand what more information you could need, or why you think the information provided in MSDN (the reference source) is inadequate.

Richard.
Re: Unrequired dialog response.
Post by Matt on Jun 9th, 2013, 4:03pm

on Jun 9th, 2013, 06:56am, Richard Russell wrote:
Given that the Windows Constants utility (for example) tells you the numeric values of the notification codes...
I'm probably being unusually thick, but I don't understand what this means or how to relate it to my code.
Quote:
I don't understand what more information you could need, or why you think the information provided in MSDN (the reference source) is inadequate.
Because it doesn't tell me what the 1 or 2, etc. refer to.

Matt
Re: Unrequired dialog response.
Post by admin on Jun 9th, 2013, 7:48pm

on Jun 9th, 2013, 4:03pm, Matt wrote:
Because it doesn't tell me what the 1 or 2, etc. refer to.

We seem to be having some difficulty understanding each other. You surely know that in Windows (indeed, virtually universally)
constants are referred to by name, not by numeric value. You won't find numbers such as 1 and 2 in MSDN, instead you will find names such as LBN_SELCHANGE. Indeed, this use of names rather than numbers should extend to your own BASIC programs; in your ON SYS handler you would be expected to have code similar to the following:

Code:
      CASE notification_code% OF
        WHEN LBN_SELCHANGE: REM Do something here
      ENDCASE
 

If you run this code BB4W will of course report 'No such variable' for the LBN_SELCHANGE constant, because it doesn't know what its numeric value is. This is where the Windows Constants Utility comes in (see Frequently Asked Question #9). Whenever you write a program which accesses the Windows API, and therefore refers to constants by name, you need to run that utility in order to assign the appropriate numeric values. I would have expected you to be doing that already.

Virtually all programming languages which provide access to the Windows API support the use of named constants; really they have to because that's all MSDN refers to - the actual numeric values aren't of interest to the human programmer. In the case of C the pre-processor replaces the names with numbers, in the case of Liberty BASIC the names are known internally (you need to add an underscore prefix) and in the case of BB4W the Windows Constants utility does the job.

It's because this is so fundamental that it's answered on the BB4W Frequently Asked Questions page!

http://www.bbcbasic.co.uk/bbcwin/faq.html

Richard.

Re: Unrequired dialog response.
Post by Matt on Jun 10th, 2013, 05:45am

on Jun 9th, 2013, 7:48pm, Richard Russell wrote:
We seem to be having some difficulty understanding each other.
Richard. My appologies for not understanding you and not making myself clear. That's the trouble with being a novice.

Quote:
You surely know that in Windows (indeed, virtually universally) constants are referred to by name, not by numeric value. You won't find numbers such as 1 and 2 in MSDN, instead you will find names such as LBN_SELCHANGE.
Yes. This is something I've learned through experience.

Quote:
Indeed, this use of names rather than numbers should extend to your own BASIC programs;
By and large, it does.

However, there is a difference, here, with what you are saying and what I'm doing. If you want the program to recognise a notification, say LBN_SELCHANGE, then what you've said above is fine. If you find you're getting a result, say of 1, and you've no idea what it is or where it came from (slight exageration in this case), then, to someone whose still learning, this can sometimes be somewhat difficult to find out.

Having said that, your latest reply has managed to lead me to answer most of my queries. (Putting them in to practice might be a different matter. We'll see.)

Again, my appologies for my ignorance. It must be quite frustrating to be costantly answering questions that seem so basic. But at least I'm willing to try to learn.

Matt

p.s. Please have a look at my post on 'PE Hangs with Module Viewer'. I can't use the Module Viewer until I sort it.

Re: Unrequired dialog response.
Post by admin on Jun 10th, 2013, 1:30pm

on Jun 10th, 2013, 05:45am, Matt wrote:
However, there is a difference, here, with what you are saying and what I'm doing. If you want the program to recognise a notification, say LBN_SELCHANGE, then what you've said above is fine. If you find you're getting a result, say of 1, and you've no idea what it is or where it came from (slight exageration in this case), then, to someone whose still learning, this can sometimes be somewhat difficult to find out.

There must be hundreds of Windows constants that have the value '1'. Even if you had a 'reverse' look-up listing all of those constants, it would still be difficult to identify which corresponds to the value you are receiving. It still seems to me that the only sensible approach is first to use MSDN to discover what notifications a List Box can provide and then (if necessary) find their numeric values using either the Windows Constants Utility or API Viewer.

It's trivial to write the following BASIC 'program' and then to run the Windows Constants utility to find the numeric values:

Code:
      PRINT LBN_DBLCLK
      PRINT LBN_KILLFOCUS
      PRINT LBN_SELCANCEL
      PRINT LBN_SELCHANGE
      PRINT LBN_SETFOCUS
 

Richard.
Re: Unrequired dialog response.
Post by admin on Jun 10th, 2013, 2:49pm

on Jun 10th, 2013, 05:45am, Matt wrote:
Please have a look at my post on 'PE Hangs with Module Viewer'.

I have no comment to make on that thread.

R.

Re: Unrequired dialog response.
Post by Malvern on Jun 10th, 2013, 11:10pm

Quote:
Even if you had a 'reverse' look-up listing all of those constants, it would still be difficult to identify which corresponds to the value you are receiving.


Such a program does exist!

Have you tried: WINCONSTlookup2_1.exe in the group files? It lets you search for constant numbers and against the type of constant. So if you are looking for anything to do with list box notifications use LBN_ and it will list all matches. If you put in a value as well only those matches will appear. It is much faster than searching MSDN. The list is not exhaustive and some Post Vista constants are not there, but most of WIN32 is included. The idea is Michael Hutton's and the constants data base is Richard's work.
Re: Unrequired dialog response.
Post by Matt on Jun 11th, 2013, 5:14pm

on Jun 10th, 2013, 11:10pm, Malvern wrote:
Have you tried: WINCONSTlookup2_1.exe in the group files.

Thanks Malvern. Just installed it and it looks good. As does win32.hlp that , I think, Richard suggested.

Matt