Announcement

Collapse
No announcement yet.

Not Sure Why This Happens - TreeView

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

  • Not Sure Why This Happens - TreeView

    I thought when I made a control invisible, that it would not respond to keypresses.

    But in this example, where there is only a TreeView control in the Dialog, the TreeView responds to pressing arrow keys even though the TreeView is hidden.

    If I add a button, however, the TreeView does not respond.

    I assume there needs to be another control that can take focus, but still, when the TreeView is invisible I thought it would not be responsive.

    The use of Control Disable stops the behavior but I didn't think that would be necessary.

    Code:
    #Compile Exe
    #Dim All
    %Unicode=1
    #Include "Win32API.inc"
    %IDC_TreeView = 500 : %IDC_Button = 501
    Global hDlg,hTree As Dword
    
    Function PBMain() As Long
       Local hItem As Dword, hTemp,hRoot As Dword
       Dialog New Pixels, 0, "TreeView",200,200,200,200, %WS_SysMenu, 0 To hDlg
       Control Add Treeview, hDlg, %IDC_TreeView, "", 0,0,200,150
       Treeview Insert Item  hDlg, %IDC_TreeView, 0, %TVI_Last, 0,0,"Root" To hRoot
       Treeview Insert Item  hDlg, %IDC_TreeView, hRoot, %TVI_Last, 0,0,"Mother" To hTemp
       Treeview Insert Item  hDlg, %IDC_TreeView, hRoot, %TVI_Last, 0,0,"Father" To hTemp
       Treeview Set Expanded hDlg, %IDC_TreeView, hRoot, %True
    '   Control Add Button, hDlg, %IDC_Button, "Button", 10,170,50,20  'this stops the treeview response
       Dialog Show Modal     hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_InitDialog
             Control Show State hDlg, %IDC_TreeView, %SW_Hide
          Case %WM_Notify
             Select Case Cb.NmId
                Case %IDC_TreeView
                   Select Case Cb.NmCode
                      Case %TVN_SelChanged : Beep
                   End Select
             End Select
       End Select
    End Function

  • #2
    I've done a fair amount of web search but still haven't found why an invisible control might to respond to key presses.

    As annoying as it might be, I can do this, for code that I don't want to execute unless the control is visible ...

    Code:
    If IsWindowVisible(hTree) Then ...
    Does anyone have insight on why an invisible control can respond to a keypress?

    Comment


    • #3
      I get no BEEP when it is hidden.
      I get no BEEP with CONTROL ADD BUTTON remarked or unremarked.
      Windows 10, 32-bit 1809 (Build 17763.475)
      https://duckduckgo.com instead of google

      Comment


      • #4
        An invisible control is not a disabled control.
        The Win32 programmer's reference states nothing about disabling or enabling a control when IsWindowVisible is used.
        The IsWindowVisible function retrieves the visibility state of the specified window.

        BOOL IsWindowVisible(
        HWND hWnd // handle of window
        );


        Parameters

        hWnd

        Identifies the window.

        Return Values

        If the specified window and its parent window have the WS_VISIBLE style, the return value is nonzero.

        If the specified window and its parent window do not have the WS_VISIBLE style, the return value is zero. Because the return value specifies whether the window has the WS_VISIBLE style, it may be nonzero even if the window is totally obscured by other windows.

        Remarks

        The visibility state of a window is indicated by the WS_VISIBLE style bit. When WS_VISIBLE is set, the window is displayed and subsequent drawing into it is displayed as long as the window has the WS_VISIBLE style.

        Any drawing to a window with the WS_VISIBLE style will not be displayed if the window is obscured by other windows or is clipped by its parent window.
        Rod
        "To every unsung hero in the universe
        To those who roam the skies and those who roam the earth
        To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

        Comment


        • #5
          Added the button to the callback to hide/unhide and still no BEEP when hidden
          My toggle of hide/unhide is quick and dirty with a global.
          When hidden, I click all over the place and can't get a BEEP.

          Like Rodney says hidden and disabled not the same, but ....
          I thought I would get a BEEP when hidden since it is not disabled, but no BEEP ever if hidden on this machine.

          Compiled with 10.04.0108
          Windows 10, 32-bit 1809 (Build 17763.475)

          Code:
          #COMPILE EXE
          #DIM ALL
          %Unicode=1
          #INCLUDE "Win32API.inc"
          %IDC_TreeView = 500
          %IDC_Button   = 501
          GLOBAL hDlg,gHide AS DWORD
          
          FUNCTION PBMAIN() AS LONG
             LOCAL hItem AS DWORD, hTemp,hRoot AS DWORD
             DIALOG NEW PIXELS, 0, "TreeView",200,200,200,200, %WS_SYSMENU, 0 TO hDlg
             CONTROL ADD TREEVIEW, hDlg, %IDC_TreeView, "", 0,0,200,150
             TREEVIEW INSERT ITEM  hDlg, %IDC_TreeView, 0, %TVI_LAST, 0,0,"Root" TO hRoot
             TREEVIEW INSERT ITEM  hDlg, %IDC_TreeView, hRoot, %TVI_LAST, 0,0,"Mother" TO hTemp
             TREEVIEW INSERT ITEM  hDlg, %IDC_TreeView, hRoot, %TVI_LAST, 0,0,"Father" TO hTemp
             TREEVIEW SET EXPANDED hDlg, %IDC_TreeView, hRoot, %True
             CONTROL ADD BUTTON, hDlg, %IDC_Button, "Hide", 10,170,50,20  'this stops the treeview response
             DIALOG SHOW MODAL     hDlg CALL DlgProc
          END FUNCTION
          
          CALLBACK FUNCTION DlgProc() AS LONG
             SELECT CASE CB.MSG
                CASE %WM_INITDIALOG
          
                CASE %WM_COMMAND
                 SELECT CASE AS LONG CB.CTL
                  CASE %IDC_Button
                   IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                    IF gHide = 0  THEN
                     gHide = 1
                     CONTROL SHOW STATE hDlg, %IDC_TreeView, %SW_HIDE
                     CONTROL SET TEXT hDlg, %IDC_BUTTON,"UnHide"
                    ELSE
                     gHide = 0
                     CONTROL SHOW STATE hDlg, %IDC_TreeView, %SW_NORMAL
                     CONTROL SET TEXT hDlg, %IDC_BUTTON,"Hide"
                    END IF
                   END IF
                  END SELECT
          
          
                CASE %WM_NOTIFY
                   SELECT CASE CB.NMID
                      CASE %IDC_TreeView
                         SELECT CASE CB.NMCODE
                            CASE %TVN_SELCHANGED : BEEP
                         END SELECT
                   END SELECT
             END SELECT
          END FUNCTION
          https://duckduckgo.com instead of google

          Comment


          • #6
            The use of Control Disable stops the behavior but I didn't think that would be necessary
            It doesn't appear to have to be disabled with my operating system and compiler version.
            This machine gets no BEEP if treeview is invisible.
            Compiled with 10.04.0108
            Windows 10, 32-bit 1809 (Build 17763.475)

            Gary,

            REM %UNICODE = 1 ' brainstorming, never get a beep if remarked on this machine with or without Jose Roca includes.
            Only get a BEEP if %UNICODE = 1
            CASE %TVN_SELCHANGED : BEEP

            Tried adjusting for best appearance and best performance and both get same results.
            https://duckduckgo.com instead of google

            Comment


            • #7
              Mike,
              Nice catch, and I can see the same thing - %Unicode=1 enables the Beep. I'm not sure of the logic for that, but it's a starting point for some additional searching.

              Rodney,
              Yes, I cannot find any documentation that justifies the visible=disabled assumption I've made. But with the %Unicode observation by Mike, it would seem that sometimes visible IS disabled and sometimes it is not. Somewhere there must be some documentation that clarifies Mike's finding.

              Comment


              • #8
                Commenting out the %Unicode=1 line changes the message from TVN_SelChanged to TVN_SelChangedW. That is why you don't hear the beep.
                Code:
                 
                 Case %TVN_SelChangedW : Beep

                Comment


                • #9
                  Mike,
                  Mine beeps. And we are talking about keyboard movement not mouse. Your code added a button which takes the focus away. If you set the focus to the hidden control it beeps. Try this with the arrow keys...
                  Code:
                  #COMPILE EXE
                  #DIM ALL
                  %Unicode=1
                  
                  #INCLUDE "Win32API.inc"
                  
                  %IDC_TreeView = 500
                  %IDC_Button   = 501
                  
                  GLOBAL hDlg,gHide AS DWORD
                  
                  FUNCTION PBMAIN() AS LONG
                    LOCAL hItem AS DWORD, hTemp,hRoot AS DWORD
                  
                    DIALOG NEW PIXELS, 0, "TreeView",200,200,200,200, %WS_SYSMENU, 0 TO hDlg
                  
                    CONTROL ADD TREEVIEW, hDlg, %IDC_TreeView, "", 0,0,200,150
                    TREEVIEW INSERT ITEM  hDlg, %IDC_TreeView, 0, %TVI_LAST, 0,0,"Root" TO hRoot
                    TREEVIEW INSERT ITEM  hDlg, %IDC_TreeView, hRoot, %TVI_LAST, 0,0,"Mother" TO hTemp
                    TREEVIEW INSERT ITEM  hDlg, %IDC_TreeView, hRoot, %TVI_LAST, 0,0,"Father" TO hTemp
                    TREEVIEW SET EXPANDED hDlg, %IDC_TreeView, hRoot, %True
                    CONTROL ADD BUTTON, hDlg, %IDC_Button, "Hide", 10,170,50,20  'this stops the treeview response
                  
                    DIALOG SHOW MODAL     hDlg CALL DlgProc
                  END FUNCTION
                  
                  CALLBACK FUNCTION DlgProc() AS LONG
                    SELECT CASE CB.MSG
                    CASE %WM_INITDIALOG
                  
                    CASE %WM_COMMAND
                      SELECT CASE AS LONG CB.CTL
                      CASE %IDC_Button
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                          IF gHide = 0  THEN
                            gHide = 1
                            CONTROL SHOW STATE hDlg, %IDC_TreeView, %SW_HIDE
                            CONTROL SET TEXT hDlg, %IDC_BUTTON,"UnHide"
                  
                            CONTROL SET FOCUS hDlg, %IDC_TreeView '<---- force focus to the hidden treeview
                  
                          ELSE
                            gHide = 0
                            CONTROL SHOW STATE hDlg, %IDC_TreeView, %SW_NORMAL
                            CONTROL SET TEXT hDlg, %IDC_BUTTON,"Hide"
                          END IF
                        END IF
                      END SELECT
                    CASE %WM_NOTIFY
                      SELECT CASE CB.NMID
                      CASE %IDC_TreeView
                        SELECT CASE CB.NMCODE
                        CASE %TVN_SELCHANGED : BEEP
                        END SELECT
                      END SELECT
                    END SELECT
                  END FUNCTION

                  Comment


                  • #10
                    Good catch. I wasn't using the keyboard.
                    https://duckduckgo.com instead of google

                    Comment


                    • #11
                      I didn't know this was possible, although, the results certainly imply that it is.

                      If you set the focus to the hidden control...

                      Comment

                      Working...
                      X