Announcement

Collapse
No announcement yet.

Interesting Issue with %EN_SETFOCUS msg between PBWin8 & PBWin9

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Interesting Issue with %EN_SETFOCUS msg between PBWin8 & PBWin9

    I have been working on some code that was originally written a long time ago in PBDLL version 6, and it has always ported to the newer compilers without any problem. Recently I compiled using PBWin 9.01 and have noticed something odd happening with the %EN_SetFocus message. I am using this message on a textbox control that is not a tabstop. Whenever a user clicks on the field one would expect to be able to process the %EN_SetFocus message. This is working, but I am getting 2 messages in the queue when compile with PBWin 9.01 rather than the 1 that I have always gotten in the past.

    Below is a fully working piece of code to demonstrate what I am talking about. Compile this code with PBWin 8 and it works as expected. Compile with 9 and you get 2 messages instead of the expected 1.

    compile the code and then click in the TextBox area. You should only get one message box for the code to be working as expected.

    Code:
    #Compile Exe
    #Dim All
      
    %WM_Command       = &H111
    %EN_SetFocus      = &H100
    %ES_Left          = &H0&
    %ES_Center        = &H1&
    %ES_Right         = &H2&
    %ES_MultiLine     = &H4&
    %ES_Uppercase     = &H8&
    %ES_Lowercase     = &H10&
    %ES_Password      = &H20&
    %ES_AutoVScroll   = &H40&
    %ES_AutoHScroll   = &H80&
    %ES_NoHideSel     = &H100&
    %ES_OEMConvert    = &H400&
    %ES_ReadOnly      = &H800&
    %ES_WantReturn    = &H1000&
    %ES_Number        = &H2000&
    %WS_Ex_ClientEdge = &H00000200
      
    CallBack Function DlgProc
      
       Static x As Dword
      
       Select Case CbMsg
          Case %WM_Command
             Select Case CbCtl
                Case 100
                   If CbCtlMsg = %EN_SetFocus Then
                      If x < 10 Then ? "%EN_SetFocus msg recievd"
                      Incr x
                   End If
                Case 1, 2
                   Dialog End CbHndl, 0
             End Select
       End Select
      
    End Function
      
    Function PBMain () As Long
      
        Local hDlg As Long
      
        Dialog New 0, "Test %EN_SetFocus Response",,,200, 60 To hDlg
        Control Add TextBox, hDlg, 100, "Click Here", 10, 10, 180, 12, %ES_AutoHScroll Or %ES_Left, %WS_Ex_ClientEdge  ' NOT A TAB STOP
        Control Add Button, hDlg, 1, "Cancel", 20, 30, 50, 20
        Control Add Button, hDlg, 2, "Ok", 130, 30, 50, 20
      
        Dialog Show Modal hDlg, Call DlgProc
      
    End Function
    Any ideas??
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

  • #2
    Another interesting thing to note. This has to do with the dialog losing then regaining focus. If you switch out the ? statement with the API function MessageBox (will need the declare added) it will lock into an endless cycle of message boxes opening when the subsequent one is closed when compile with PBWin 9. That is the reason for the static variable x being in place to stop it after 10 times.
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

    Comment


    • #3
      >Any ideas??

      Send code to PB support?
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        >Any ideas??

        Send code to PB support?
        I am in the process of doing so. I just wanted to be sure that it wasn't my mistake first.
        Scott Slater
        Summit Computer Networks, Inc.
        www.summitcn.com

        Comment


        • #5
          Update:

          I guess this was a previously broken feature that I was taking advantage of that has now been fixed.

          From PB Support:
          Version 9.01 is correctly setting the focus back to the last control that had focus after the messagebox is closed. This was a problem in previous versions, where DDT was not setting the focus back to the correct control after the dialog box lost focus.
          So here is what I am doing in PBWin9. The code won't compile in 8 anyway because it is now using objects (the reason for to port to 9 in the first place)

          Code:
          #Compile Exe
          #Dim All
            
          %WM_Command       = &H111
          %EN_SetFocus      = &H100
          %ES_Left          = &H0&
          %ES_AutoHScroll   = &H80&
          %WS_Ex_ClientEdge = &H00000200
            
          Declare Function MessageBox Lib "USER32.DLL" Alias "MessageBoxA" (ByVal hWnd As Dword, lpText As Asciiz, lpCaption As Asciiz, ByVal dwType As Dword) As Long
            
          CallBack Function DlgProc
            
             Select Case CbMsg
                Case %WM_Command
                   Select Case CbCtl
                      Case 100
                         If CbCtlMsg = %EN_SetFocus Then
                            Control Set Focus CbHndl, 1  '<--- Set focus away from control BEFORE Opening Child Dialog/Window
                            MessageBox CbHndl, "%EN_SetFocus msg recievd", " ", 0
                         End If
                      Case 1, 2
                         Dialog End CbHndl, 0
                   End Select
             End Select
            
          End Function
            
          Function PBMain () As Long
            
              Local hDlg As Long
            
              Dialog New 0, "Test %EN_SetFocus Response",,,200, 60 To hDlg
              Control Add TextBox, hDlg, 100, "Click Here", 10, 10, 180, 12, %ES_AutoHScroll Or %ES_Left, %WS_Ex_ClientEdge  ' NOT A TAB STOP
              Control Add Button, hDlg, 1, "Cancel", 20, 30, 50, 20
              Control Add Button, hDlg, 2, "Ok", 130, 30, 50, 20
            
              Dialog Show Modal hDlg, Call DlgProc
            
          End Function
          The above functions as expected in PBWin9, but it would have to have the text field clicked twice in prior versions of PB.
          Last edited by Scott Slater; 3 Aug 2009, 06:45 PM. Reason: Found better solution
          Scott Slater
          Summit Computer Networks, Inc.
          www.summitcn.com

          Comment


          • #6
            Version 9.01 is correctly setting the focus back to the last control that had focus after the messagebox is closed
            "Correctly?" Is that a change in MSGBOX behavior or a change in DDT-generated code?

            MSGBOX has never reset the focus anywhere as far as I can tell. I've always had to do that myself; and there is no "changes to existing statments and functions" for MSGBOX in the 9.0.1 help file. Or is that omission an error?


            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              My take on this is that DDT now performs this internally.

              Code:
                    Case %WM_NCActivate
                       Static hWndSaveFocus As Dword
                       If IsFalse Cb.WParam Then
                          ' Save control focus
                          hWndSaveFocus = GetFocus()
                       ElseIf hWndSaveFocus Then
                          ' Restore control focus
                          SetFocus(hWndSaveFocus)
                          hWndSaveFocus = 0
                       End If
              Scott Slater
              Summit Computer Networks, Inc.
              www.summitcn.com

              Comment

              Working...
              X