Announcement

Collapse
No announcement yet.

HELP WITH ACCEL ATTACH statement

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

  • Robert Alvarez
    replied
    Dave

    Your right using %WS_Group and other setting does work, at first it did not, but copyed again and it works now.

    The code you showed and subclass is more advance code for me but this code will be good to study on using api calls.


    Thanks Dave

    Leave a comment:


  • Dave Biggs
    replied
    Robert,

    I think that the %WS_Group solution suggested by Rod and demonstrated by Gary solves your original problem
    (labels interfering with keyboard navigation using arrow keys) nicely but maybe not best in your actual application?

    Here is an interpretation of the use of 'Accel Attach' that you asked about.
    It looks ok at first but starts to get a bit messy if there are other controls (eg TextBox) that
    also normally respond to arrow keys.

    Another approach that could give more controllable results would be to Subclass the required controls.
    You can then respond to the arrow keys within a subclass procedure without affecting their default
    behaviour elsewhere.

    Code:
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
     
    %KEY_UP     = 201
    %KEY_LEFT   = 202
    %KEY_DOWN   = 203
    %KEY_RIGHT  = 204
     
    Function PBMain() As Long
        Local hDlg As Dword
        Dialog New Pixels, 0, "Button Test",300,300,350,300, %WS_OverlappedWindow To hDlg
        Control Add Button, hDlg, 101,"Push", 50,10,40,20', %WS_Group OR %WS_Tabstop    '# Option 1
        Control Add Button, hDlg, 102,"Push", 50,40,40,20
        Control Add Button, hDlg, 103,"Push", 50,70,40,20
        Control Add Button, hDlg, 104,"Push", 50,100,40,20
        Control Add Button, hDlg, 105,"Push", 50,130,40,20
     
        Control Add Button, hDlg, 106,"Push", 50,200,40,20
        Control Add Button, hDlg, 107,"Push",100,200,40,20
        Control Add Button, hDlg, 108,"Push", 150,200,40,20
        Control Add Button, hDlg, 109,"Push", 200,200,40,20
        Control Add Button, hDlg, 110,"Push", 250,200,40,20
     
        Control Add Label, hDlg, 100,"Push", 110,10,40,20', %WS_Group                   '# Option 1
        Control Add Label, hDlg, 100,"Push", 110,40,40,20
        Control Add Label, hDlg, 100,"Push", 110,70,40,20
        Control Add Label, hDlg, 100,"Push", 110,100,40,20
        Control Add Label, hDlg, 100,"Push", 110,130,40,20
        CONTROL ADD TEXTBOX, hDlg, 200, "TextBox1", 158, 89, 150, 21                    '* Option 2 problem ?
     
       AttachAccel hDlg     ' Comment this line to revert to 'normal' operation         '* Option 2
     
      Dialog Show Modal hDlg Call DlgProc
     
    End Function
    '------------------/PBMain    <
     
    CallBack Function DlgProc()
     Local i As Long
      Select Case As Long CbMsg 
        Case %WM_InitDialog
     
        Case %WM_Command
          Select Case As Long CbCtl
            Case %KEY_UP, %KEY_LEFT
              If GetFocus = GetDlgItem(CbHndl, 200) Then                                '* Option 2 problem fix
                Control Send CbHndl, 200, %EM_GETSEL, VarPtr(i), 0
                Control Send CbHndl, 200, %EM_SETSEL, i-1, i-1
                Exit Function
              End If
              If GetFocus = GetDlgItem(CbHndl, 101) Then       ' step to specified control
                WinBeep 800,1
                Dialog Send CbHndl, %WM_NEXTDLGCTL, GetDlgItem(CbHndl, 110), 1          ' similar to SetFocus
              Else                                             ' step to previous control
                Dialog Send CbHndl, %WM_NEXTDLGCTL, 1, 0
              End If
            Case %KEY_DOWN, %KEY_RIGHT
              If GetFocus = GetDlgItem(CbHndl, 200) Then                                '* Option 2 problem fix
                Control Send CbHndl, 200, %EM_GETSEL, VarPtr(i), 0
                Control Send CbHndl, 200, %EM_SETSEL, i+1, i+1
                Exit Function
              End If
              If GetFocus = GetDlgItem(CbHndl, 110) Then       ' step to specified control
                WinBeep 800,1
                Dialog Send CbHndl, %WM_NEXTDLGCTL, GetDlgItem(CbHndl, 101), 1
              Else                                             ' step to next control
                Dialog Send CbHndl, %WM_NEXTDLGCTL, 0, 0
              End If
          End Select
      End Select
    End Function
    '------------------/DlgProc
     
    Function AttachAccel(ByVal hDlg As Dword) As Dword
     Local hAccel         As Dword
     Local tAccel()       As ACCELAPI
     Dim   tAccel(1 To 4) As ACCELAPI
     
      AssignAccel tAccel(1), %VK_UP,    %KEY_UP,    %FVIRTKEY           ' Arrow keys
      AssignAccel tAccel(2), %VK_LEFT,  %KEY_LEFT,  %FVIRTKEY
      AssignAccel tAccel(3), %VK_DOWN,  %KEY_DOWN,  %FVIRTKEY
      AssignAccel tAccel(4), %VK_RIGHT, %KEY_RIGHT, %FVIRTKEY
      Accel Attach hDlg, tAccel() To hAccel
     
     Function = hAccel
    End Function
    '------------------/AttachAccel
     
    Function AssignAccel(tAccel As ACCELAPI, ByVal wKey As Word, ByVal wCmd As Word, ByVal byFVirt As Byte) As Long
      tAccel.fVirt = byFVirt
      tAccel.key   = wKey
      tAccel.cmd   = wCmd
    End Function
    '------------------/AssignAccel

    Leave a comment:


  • Robert Alvarez
    replied
    Thanks everyone for answering.

    Reading all responses, I see that arrow keys do not jump from one group to another group after adding label to top buttons, it did work when dialog had only buttons and no labels.

    -------------
    CALLBACK FUNCTION Cat_Matrl_Sel_RdKey()
    SELECT CASE CBMSG
    CASE %WM_COMMAND
    SELECT CASE CBCTL
    CASE 1001 AND CBCTL=%BU1 <<<< IS THIS CORRECT CODING???
    CONTROL SET FOCUS hDlg, %BU28 <<<<<< ??

    END SELECT
    END SELECT
    END FUNCTION
    ---------------

    Going back to my code in question using 'accel attach' , is the code shown above correct or is there another way to do it. When the focus is at top or bottom left, I want to detect the arrow key pressed and then let the 'control set focus' to wherever other button I want.

    I have used 'accel attach' to press a key to do doing something. Now I want to check for two things, the arrow key being pressed and read the button id , then do someting.

    Leave a comment:


  • Gary Beene
    replied
    Ahhhh... I see that my example has a shortcoming.

    In Help I find:

    Groups configured this way permit the arrow keys to shift focus between the controls within the group, and focus can jump from group to group with the usual TAB and SHIFT+TAB keys
    So in this following example, I've added another group of buttons. TAB will switch between groups, but the arrow key works only within the current TAB group. This example makes it much clearer how the two work together.

    My earlier example worked, but I don't know whether Robert had other controls or not, which would affect how he could/should use the example.

    Code:
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    
    Function PBMain() As Long
        Local hDlg As Dword
        Dialog New Pixels, 0, "Button Test",300,300,325,300, %WS_OverlappedWindow To hDlg
        Control Add Button, hDlg, 171,"Push", 50,10,40,20, %WS_Group Or %WS_TabStop
        Control Add Button, hDlg, 171,"Push", 50,40,40,20
        Control Add Button, hDlg, 172,"Push", 50,70,40,20
        Control Add Button, hDlg, 173,"Push", 50,100,40,20
        Control Add Button, hDlg, 174,"Push", 50,130,40,20
    
        Control Add Button, hDlg, 105,"Push", 50,200,40,20
        Control Add Button, hDlg, 106,"Push",100,200,40,20
        Control Add Button, hDlg, 107,"Push", 150,200,40,20
        Control Add Button, hDlg, 108,"Push", 200,200,40,20
        Control Add Button, hDlg, 109,"Push", 250,200,40,20
    
        Control Add Label, hDlg, 110,"Push", 110,10,40,20, %WS_Group
        Control Add Label, hDlg, 120,"Push", 110,40,40,20
        Control Add Label, hDlg, 130,"Push", 110,70,40,20
        Control Add Label, hDlg, 140,"Push", 110,100,40,20
        Control Add Label, hDlg, 150,"Push", 110,130,40,20
    
        Control Add Button, hDlg, 571,"Push", 150,10,40,20, %WS_Group Or %WS_TabStop
        Control Add Button, hDlg, 571,"Push", 150,40,40,20
        Control Add Button, hDlg, 572,"Push", 150,70,40,20
    
        Dialog Show Modal hDlg
    End Function

    Leave a comment:


  • Michael Mattias
    replied
    Of course, has I been completely copy-proof, I would have used equates for the control ID's
    Well, if they are going to be sequential IDs, you don't need equates for ALL the controls.....
    http://www.powerbasic.com/support/pb...4&postcount=11 ...

    Leave a comment:


  • Gary Beene
    replied
    So here's a version with unique control IDs.

    Note that in my original response I left off the %WS_TabStop on the first button. It needs to be there for the TAB key to work. Without that style, the 1st button cannot be reached with the TAB key. All other buttons can.

    But even without that style, the arrow keys will reach all buttons. I wonder why that is?

    Of course, has I been completely copy-proof, I would have used equates for the control ID's. That's such a pain however. There's got to be some "left-to-the-reader" requirement, doesn't there?

    I may not be so "teach-them-to fish" as to give hints (MCM?), but I certainly am lazy enough to not dot all my i's.

    Code:
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    
    Function PBMain() As Long
        Local hDlg As Dword
        Dialog New Pixels, 0, "Button Test",300,300,600,300, %WS_OverlappedWindow To hDlg
        Control Add Button, hDlg, 171,"Push", 50,10,40,20, %WS_Group Or %WS_TabStop
        Control Add Button, hDlg, 171,"Push", 50,40,40,20
        Control Add Button, hDlg, 172,"Push", 50,70,40,20
        Control Add Button, hDlg, 173,"Push", 50,100,40,20
        Control Add Button, hDlg, 174,"Push", 50,130,40,20
    
        Control Add Button, hDlg, 105,"Push", 50,200,40,20
        Control Add Button, hDlg, 106,"Push",100,200,40,20
        Control Add Button, hDlg, 107,"Push", 150,200,40,20
        Control Add Button, hDlg, 108,"Push", 200,200,40,20
        Control Add Button, hDlg, 109,"Push", 250,200,40,20
    
        Control Add Label, hDlg, 110,"Push", 110,10,40,20, %WS_Group
        Control Add Label, hDlg, 120,"Push", 110,40,40,20
        Control Add Label, hDlg, 130,"Push", 110,70,40,20
        Control Add Label, hDlg, 140,"Push", 110,100,40,20
        Control Add Label, hDlg, 150,"Push", 110,130,40,20
    
        Dialog Show Modal hDlg
    End Function
    Last edited by Gary Beene; 31 Aug 2009, 09:19 AM.

    Leave a comment:


  • Gary Beene
    replied
    Well, MCM, it was just a demo to show how to get the arrow keys to work.

    It works with arrow keys as is and works with unique control IDs too -or so my test shows.

    However, though you didn't say it, users have been know to copy code as-is and then wonder why something else broke.

    I'd have to agree that it's always best to use examples that are "copy" proof.

    Leave a comment:


  • Michael Mattias
    replied
    > See the following example. Is this what you wanted

    I doubt it. That screen is not going to be any fun at all to code, because all the controls have the same control ID.

    I'll hazard a guess "copy and paste" is the primary suspect in this case.

    Leave a comment:


  • Gary Beene
    replied
    Using the %WS_group to separate the buttons from labels (groupwise), seems to do the trick.

    See the following example. Is this what you wanted?

    Code:
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    
    Function PBMain() As Long
        Local hDlg As Dword
        Dialog New Pixels, 0, "Button Test",300,300,600,300, %WS_OverlappedWindow To hDlg
        Control Add Button, hDlg, 100,"Push", 50,10,40,20, %WS_Group
        Control Add Button, hDlg, 100,"Push", 50,40,40,20
        Control Add Button, hDlg, 100,"Push", 50,70,40,20
        Control Add Button, hDlg, 100,"Push", 50,100,40,20
        Control Add Button, hDlg, 100,"Push", 50,130,40,20
    
        Control Add Button, hDlg, 100,"Push", 50,200,40,20
        Control Add Button, hDlg, 100,"Push",100,200,40,20
        Control Add Button, hDlg, 100,"Push", 150,200,40,20
        Control Add Button, hDlg, 100,"Push", 200,200,40,20
        Control Add Button, hDlg, 100,"Push", 250,200,40,20
    
        Control Add Label, hDlg, 100,"Push", 110,10,40,20, %WS_Group
        Control Add Label, hDlg, 100,"Push", 110,40,40,20
        Control Add Label, hDlg, 100,"Push", 110,70,40,20
        Control Add Label, hDlg, 100,"Push", 110,100,40,20
        Control Add Label, hDlg, 100,"Push", 110,130,40,20
    
        Dialog Show Modal hDlg Call DlgProc
    End Function

    Leave a comment:


  • Rodney Hicks
    replied
    Does your upper left button have the %WS_GROUP and %WS_TABSTOP styles?
    Do all the other buttons you listed have the %WS_TABSTOP style?
    Do the interfering labels have the %WS_TABSTOP style?

    More code shown(using codetags, the # icon above the textbox I wrote this in) would be helpful.

    Leave a comment:


  • Robert Alvarez
    started a topic HELP WITH ACCEL ATTACH statement

    HELP WITH ACCEL ATTACH statement

    Having a dialog with 10 vertical buttons and 10 horz buttons on bottom, when you use the tab key, button focus go round and round and with shift tab, button focus goes in reverse.

    Using the arrow keys up and down or left and right makes the tab focus on buttons with same effect.

    When you add labels to the top ten buttons, the arrow keys now stop at the top and at the bottom left. They do not now go from the top to the bottom left or bottom left to the top.

    With this problem , what I am trying to do with accel attach is tell the program when at the top button detect 'up key' and button id (bu1) to focus on to bottom right button id (bu20) to continue looping button focus around using the arrows.

    And add simular code to other arrows key detection.

    I am missing something in the code below that does not work.

    Hope someone can help here.

    Below is my accel code.
    ------------------------------------------
    CALLBACK FUNCTION Sel_READKey()
    SELECT CASE CBMSG
    CASE %WM_COMMAND
    SELECT CASE CBCTL
    ' CASE 1001 AND CBCTL=%BU1
    ' CONTROL SET FOCUS hDlg, %BU28
    CASE 1002 AND CBCTL=%BU1
    MSGBOX "UP":CONTROL SET FOCUS hDlg, %BU28 ' %VK_PGUP %VK_PGDN %VK_LEFT %VK_UP %VK_RIGHT %VK_DOWN %VK_NUMPAD0
    ' CASE 1003
    ' GOSUB CCNT
    ' CASE 1004
    ' GOSUB CCNTR
    END SELECT
    END SELECT
    END FUNCTION
Working...
X