BBC BASIC for Windows
« List Box Notification »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:27pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: List Box Notification  (Read 1511 times)
admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: List Box Notification
« Reply #15 on: Aug 5th, 2013, 10:32am »

on Aug 5th, 2013, 04:49am, Matt wrote:
If another method that does more but is more complicated (not that I'm saying in this case that WM_NEXTDLGCTL is more complicated) then why use it?

Because, as I keep saying, otherwise it doesn't work correctly. Since for some reason you seem not to want to believe me, I would refer you to Raymond Chen's blog:

http://blogs.msdn.com/b/oldnewthing/archive/2004/08/02/205624.aspx

"To avoid this problem, don't use SetFocus to change focus on a dialog. Instead, use the WM_NEXTDLGCTL message.
As the remarks for the WM_NEXTDLGCTL message observe, the DefDlgProc function handles the WM_NEXTDLGCTL message by updating all the internal dialog manager bookkeeping, deciding which button should be default, all that good stuff.
Now you can update dialog boxes like the professionals, avoiding oddities like having no default button, or worse, multiple default buttons!
"

So now you know exactly the consequences of not writing your code "like the professionals". I can only hope that you have more regard for Raymond's opinion than you evidently have for mine.

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: List Box Notification
« Reply #16 on: Aug 6th, 2013, 05:29am »

on Aug 5th, 2013, 10:32am, Richard Russell wrote:
Because, as I keep saying, otherwise it doesn't work correctly.

As you are quite fond of saying, you obviously didn't read my post properly. I wasn't referring specifically to SetFocus, but to general procedures. If something does work correctly and is simple...

Quote:
I can only hope that you have more regard for Raymond's opinion than you evidently have for mine.

In fact, my regard for you opinion is quite high. But I will not just accept your opinion blindly if I don't understand it. Unfortunately, whereas you obviously have the ability to learn, absorb and understand the intricacies of, at least, the workings of a computer, I, just like others, seem to struggle. Sometimes the answers are hidden and we need to search for them (sometimes, needing help, time and time again) and other times the answer is right under our noses, but we cannot see. Do not confuse ignorance with carelessness, or a lack of regard for your opinion.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: List Box Notification
« Reply #17 on: Aug 6th, 2013, 1:08pm »

on Aug 6th, 2013, 05:29am, Matt wrote:
Do not confuse ignorance with carelessness, or a lack of regard for your opinion.

BBC BASIC provides only a low level access to the Windows API. That means that, as soon as you move beyond the capabilities of the supplied libraries, a good understanding of the internal workings of Windows is necessary before you can successfully program GUI features from BBC BASIC. That level of understanding comes only with experience.

The same is not true of some other languages. For example both Visual BASIC and Liberty BASIC provide a high-level interface to the Windows API. Using those it is possible for a complete beginner to write GUI-based programs easily and safely.

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: List Box Notification
« Reply #18 on: Aug 10th, 2013, 8:17pm »

on Aug 2nd, 2013, 7:50pm, Matt wrote:
EVENTLIB is not in the BB4W LIBs.

Sorry for not responding to this earlier, but EVENTLIB is one of the standard supplied libraries. If it's not in your LIB folder, reinstalling BB4W (v5.94a) will put it there.

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: List Box Notification
« Reply #19 on: Sep 2nd, 2013, 5:00pm »

OK. What am I doing wrong?!

I've studied all that I can find relating to this and I just can't make it work.

Code:
      INSTALL @lib$+"WINLIB2"
      INSTALL @lib$+"WINLIB5"
      
      WM_NEXTDLGCTL = 40
      
      dlg1% = FN_DLG1
      dlg2% = FN_DLG2
      
      PROC_showdialog(dlg1%)
      
      PROC_showdialog(dlg2%)
      WAIT 100
      PROC_closedialog(dlg2%)
      
      REM THIS LINE DOESN'T WORK
      REM SYS "PostMessage", !dlg1%, WM_NEXTDLGCTL, 0, 0 TO result% : PRINT result%
      
      REM THIS LINE DOES WORK
      REM SYS "GetDlgItem", !dlg1%, 1 TO h% : PROC_setfocus(h%)
      
      WAIT 100
      
      PROC_closedialog(dlg1%)
      END
      
      DEF FN_DLG1
      LOCAL dlg%
      dlg%=FN_newdialog("Dialogue box 1",150,50,160,128,8,180)
      PROC_pushbutton( dlg%, "OK",1,16,104,50,14,&20001):REM  BS_DEFPUSHBUTTON, WS_TABSTOP, WS_GROUP
      PROC_pushbutton( dlg%, "Cancel",2,88,104,50,14,&0)
      =dlg%
      
      DEF FN_DLG2
      LOCAL dlg%
      dlg%=FN_newdialog("Dialogue box 2",160,60,160,128,8,180)
      PROC_pushbutton( dlg%, "OK",1,16,104,50,14,&20001):REM  BS_DEFPUSHBUTTON, WS_TABSTOP, WS_GROUP
      PROC_pushbutton( dlg%, "Cancel",2,88,104,50,14,&0)
      =dlg% 


The "PostMessage" line (when un-REMmed) does not return focus to the first dialog box, but the "GetDlgItem" line does. (Yes, Richard, I know I'm not supposed to be using it. It's just there as a comparison. It's the "PostMessage" I'm more interested in.) Is there another command that I should be adding to the code? As I said, I've gone through all the texts that I can think of in relation to this.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: List Box Notification
« Reply #20 on: Sep 2nd, 2013, 5:29pm »

on Sep 2nd, 2013, 5:00pm, Matt wrote:
OK. What am I doing wrong?

This is what MSDN says about the WM_NEXTDLGCTL message: "wParam: If lParam is TRUE, this parameter identifies the control that receives the focus":

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

So to transfer the focus to a specific control you need to set wParam to the window handle of the control and lParam to 'true' (i.e. 1, for Windows, although any non-zero value may work). However that's not what you do in your code; you set both wParam and lParam to zero:

Code:
      REM SYS "PostMessage", !dlg1%, WM_NEXTDLGCTL, 0, 0 TO result% : PRINT result% 

As it tells you in the MSDN page, setting both wParam and lParam to zero means "the next control [with the WS_TABSTOP style] receives the focus"; effectively it has the same effect as pressing the Tab key.

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: List Box Notification
« Reply #21 on: Sep 2nd, 2013, 6:57pm »

So does that mean, then, that SYS "PostMessage", !dlg%, WM_NEXTDLGCTL, 0, 0 would normally be used when the dialog box already has focus, but when closing a child dialog box, what is required is to select the control of the parent box that initially requires focus, i.e. SYS "PostMessage", !dlg%, WM_NEXTDLGCTL, ctrl%, 1?

Edit: Just realised that the ctrl% parameter should be the control handle rather than the control id. Although it does say this, I was using the id because, in my experience, it's unusual to have both the window handle and the control handle. Normally, I've found that it's either the window handle and the control id, or the control handle only.

It's sorted anyway.

Matt
« Last Edit: Sep 2nd, 2013, 7:49pm by Matt » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: List Box Notification
« Reply #22 on: Sep 2nd, 2013, 7:59pm »

on Sep 2nd, 2013, 6:57pm, Matt wrote:
So does that mean, then, that SYS "PostMessage", !dlg%, WM_NEXTDLGCTL, 0, 0 would normally be used when the dialog box already has focus, but when closing a child dialog box

It's difficult to speculate on what a particular API might 'normally' be used for. Since the action is that of the Tab key (moving the input focus to the next control having the WS_TABSTOP style), I would expect that the most likely use is exactly that, i.e. to be called (internally to Windows) when the Tab key is pressed.

Bear in mind that the API functions documented in MSDN aren't necessarily intended to be called from an application, many of them are primarily for internal use within Windows.

Quote:
what is required is to select the control of the parent box that initially requires focus

I'm not sure what you mean by "parent box" in this context. Do you mean the parent window of the controls, i.e. the dialogue box itself, or the parent window of the dialogue box? Normally a dialogue box shouldn't have a parent - i.e. it shouldn't be a child window. The reason is that child windows are constrained to remain within the client area of their parent window, and the expectation is that you will be able to move a dialogue box freely anywhere on the screen.

The parent window of the controls (i.e. the dialogue box itself) should never have the input focus - I'm not even sure that it is possible. It only makes sense to give the input focus to a window which can receive input! Since the dialogue box itself can't receive input (where would it go?) it should never have the input focus.

Does that answer the question?

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: List Box Notification
« Reply #23 on: Sep 3rd, 2013, 04:48am »

It certainly does.

My mistake is for using words which aren't technically correct. What I meant by parent / child box is a dialog box called by a routine that, when a button is pressed within that box, calls yet another dialog box - which, I aggree, is not technically called a parent / child window.

Sorry for the confusion. And thanks for answering it better than I asked it.

Matt
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls