CommandButton Behavior

Started by Klaas Holland, September 15, 2010, 06:18:33 PM

Previous topic - Next topic

Klaas Holland

In PB you can push the Enter Button to let the CommandButton react when it has got the Focus.
In FF you have to push the Spacebar to do the same thing I read somewhere in this Forum.
However, when you have a little program with 1 Form and a couple of CommandButtons these CommandButtons
react the same way as in PB both with the Enter Button and the Spacebar.
That is how I like it.

But when you do create a program with a TabControl and multiple Forms it becomes complicated.
In those child Forms under the TabControl the CommandButtons do not react on the Enter Button being pushed.
This is strange for me. Why in the first Form and not in the second Form?????

It becomes even stranger when in the first MainForm you have a CommandButton on the 7th position in the TabOrder
in FF_Workspace and you have a CommandButton in the second TabForm also in the 7th position in the TabOrder of that TabForm.
Then the push on the Enter Button does the thing of the CommandButton in the first MainForm,
and the push on the Spacebar or the click with the mouse does the things you expect from the CommandButton
on the second TabForm.

This is very odd, it has something to do with the position in the TabOrder in the FF_Workspace.

Can anyone tell me if this is a bug or do I do something wrong???
Is there a possibility to let the CommandButtons respond on the push of the Enter Button???

Regards,
Klaas.



Christian Weilguny

Hi Klaas,

I've made a look at your problem and found this:

I've a form with a tabcontrol on it. There are two pages and on each page is a form with the same controls on it (But this are TWO forms and not the same form on two pages).
On the two tabchilds are in each case two listboxes, two textboxes, some labels and a command-button for saving the data.
The command-button is in each case at the 6th (and last) position on the forms. They have the same name (cmdSave).

They don't react at the enter-key but they react at the spacebar.
I haven't seen that the button reacts without it's form is active. Neither at the enter-key nor at the spacebar.

Maybe you have some Command-Messages coded for reacting on the enter-key?
On the other hand I have this form with the two tabchilds in a dll. Perhaps this reacts different?

Also I've seen that the tab-routine works around the whole application and not arround the active window. I some cases that would be not expected.

Christian

Klaas Holland

Hi Cristian,

I have a MainForm with a ComboBox, two ListBoxes, a DateTimePicker, an Editbox, a CommandButton and the TabControl.
In the TabControl a have 4 Forms, FormT1, FormT2 and so on.
FormT1 contains a ListView, an EditBox, a ComboBox and 3 CommandButtons.
FormT2 contains also a couple of CommandButtons in almost the same TabOrder positions.

The CommandButton on FormT1 in the same TabOrder as the CommandButton on the MainForm is reacting with the Enter Button
as if it is the CommandButton on the MainForm.
With Spacebar or the MouseClick it is reacting as the FormT1_CommandButton.

The CommandButton on FormT2 in the same TabOrder is also reacting on the Enter Button as if it is the MainForm_CommandButton.

When I create an extra (normal) Form with a couple of things plus a CommandButton, then this CommandButton
is reacting normally on the Enter Button and on the Spacebar.

So it must be something between the MainForm and the FormT1 of the TabControl

I assume the CommandButtons should always react on both the Enter Button and the Spacebar.
This is also the matter in MessageBoxes.

Klaas










Paul Squires

I haven't tested your exact scenario but I expect that it is more of an issue with the use of modal (main form) and non-modal (tab child forms) than it is with the tab order. The message loop may not be reacting the same way in both cases.

I remember there being a lot of talk on the PB forum on the command button spacebar versus enter issue. I can't seem to pinpoint it right now but Dominic Mitchell had a pretty good explanation. I seem to remember that it revolved around the difference between standard CreateWindowEx created windows and windows created by the CreateDialogIndirect (which libraries like DDT uses).
Paul Squires
PlanetSquires Software

Roger Garstang

There was a discussion here recently too...mostly concerning onFocus stuff if I recall and how the first control given focus either had or did not have focus and Default Status.  I think part of the problem was some code added for multi-line text boxes that handles focus different.  Even when it was changed though there was still a difference in DDT and FF, so PB does some type of magic.  It didn't really bother me though since I came from Win3.x days and know all the keyboard navigation tricks to have more than one way of clicking a button.

Klaas Holland

Here is an example to show you what I mean.
Please try all the buttons with the Spacebar and also with the Enter Button.
You will see that Button 2 and 3 in the Tabs react as Button 1 and 2 of the Main Form.
Play with the TabOrder and tell me what is going wrong.


Cho Sing Kum

#6
Hi Klaas,

The below is a link to a thread to some unexpected behaviour with Command button.
http://www.planetsquires.com/protect/forum/index.php?topic=2435.0


Paul Squires

Hi Klaas,

I took a look at your project. It appears that the control identifiers that FF3 is generating for each Form could be the problem. Here is what FF3 generates for your project:

Sub FLY_InitializeVariables()   
   ' All FireFly variables relating to Forms and Controls are initialized here. This
   ' includes any Control Arrays that have been defined and control identifiers
   ' per the listing in the Declares include file.
   
    IDC_FORM1_COMBO1 = 1000
    IDC_FORM1_LIST1 = 1001
    IDC_FORM1_TABCONTROL1 = 1002
    IDC_FORM1_LABEL1 = 1003
    IDC_FORM1_COMMAND1 = 1004
    IDC_FORM1_COMMAND2 = 1005
    IDC_FORM1_LABEL3 = 1006
    IDC_FORMT1 = 100
    IDC_FORMT1_LISTVIEW1 = 1000
    IDC_FORMT1_TEXT1 = 1001
    IDC_FORMT1_COMBO2 = 1002
    IDC_FORMT1_COMMAND1 = 1003
    IDC_FORMT1_COMMAND2 = 1004
    IDC_FORMT1_COMMAND3 = 1005
    IDC_FORMT2 = 101
    IDC_FORMT2_TEXT1 = 1000
    IDC_FORMT2_TEXT2 = 1001
    IDC_FORMT2_TEXT3 = 1002
    IDC_FORMT2_COMMAND1 = 1003
    IDC_FORMT2_COMMAND2 = 1004
    IDC_FORMT2_COMMAND3 = 1005
         

End Sub   


As you can see, each Form's control ids start at 1000 and increment by one for each control on the Form. For some reason, when the ENTER key is pressed it doesn't recognize the correct CommandButton. Weird, that pressing the SpaceBar does correctly identify the control.

Paul Squires
PlanetSquires Software

Paul Squires

You could put the following code into the FF_PUMPHOOK function to filter the ENTER key and send the correct BN_CLICKED notification based on the CommandButton that has focus when the ENTER key is pressed.

   ' Filter the ENTER key for the command buttons
   Select Case Msg.Message
     
      Case %WM_KEYDOWN
         Local hFocus    As Dword
         Local idControl As Long 
         
         hFocus      = GetFocus()
         
         If Msg.wParam = %VK_RETURN Then
            ' Only handle the ENTER key for the CommandButtons that we are interested
            ' in. Maybe a better approach could be to filter this list based on the
            ' 'Button' class. ie. GetClassName.
            Select Case hFocus
               Case HWND_FORM1_COMMAND1, HWND_FORM1_COMMAND2, _
                    HWND_FORMT1_COMMAND1, HWND_FORMT1_COMMAND2, HWND_FORMT1_COMMAND3, _
                    HWND_FORMT2_COMMAND1, HWND_FORMT2_COMMAND2, HWND_FORMT2_COMMAND3
                     
                    idControl = GetWindowLong( hFocus, %GWL_ID )
                    SendMessage GetParent(hFocus), %WM_COMMAND, Mak( Long, idControl, %BN_CLICKED), hFocus
                    Msg.Message = %WM_NULL
                   
            End Select         
         End If   
       
   End Select   

Paul Squires
PlanetSquires Software

Roger Garstang

So, is FF going to change the ID behavior?  It looks like the problem is FF considers forms to be parents and only on screen one at a time, but in a tab control they are child controls/WS_CHILD.  Looks like it would be safest to generate IDs Globally/Project-Wide and make each one different across the board.  Or, at least for Child Forms.

Paul Squires

Quote from: Roger Garstang on September 20, 2010, 12:46:20 PM
Looks like it would be safest to generate IDs Globally/Project-Wide and make each one different across the board.  Or, at least for Child Forms.
I tried doing that but it makes no difference (surprisingly). For some reason, the ENTER key processing is not playing well with the focused CommandButton when it is on a child form.
Paul Squires
PlanetSquires Software

Klaas Holland

Hi Paul,

This work-around in the FF-PUMPHOOK works fine.
But I hope you will have fixed the problem in the next update.
I like FF so I will wait for the next update to start with a major new project.

Thanks to all of you.

Klaas.