Author |
Topic: List Box Notification (Read 1516 times) |
|
Matt
Developer
member is offline


Gender: 
Posts: 210
|
 |
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
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
Matt
Developer
member is offline


Gender: 
Posts: 210
|
 |
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 » |
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
Matt
Developer
member is offline


Gender: 
Posts: 210
|
 |
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
|
|
Logged
|
|
|
|
|