Announcement

Collapse
No announcement yet.

Option and TAB Conflict?

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

  • Option and TAB Conflict?

    This very simple code freezes when I click on the option control. Is it obvious why?

    Code:
    [CODE]#Compile Exe
    #Dim All
    #Include "Win32API.inc"
    Global hDlg As Dword
    Function PBMain() As Long
       Dialog New Pixels, 0, "Test Code",300,300,600,500, %WS_OverlappedWindow To hDlg
       AddTAB
       Control Add Option, hDlg, 150, "Pick Me!", 20,290, 100,20
       Dialog Show Modal hDlg
    End Function
    
    Sub AddTab
      Local hPage1 As Dword, hPage2 As Dword
      Control Add Tab, hDlg, 540, "", 400,370,150,75
        Tab Insert Page hDlg, 540, 1,0,"Page1" To hPage1
            Control Add Label, hPage1, 550, "Label1", 20,20,60,20
    End Sub
    [/CODE]

  • #2
    Actually it IS obvious, but only if you scrollbar all the way to the right on the DIALOG NEW statement.

    I think you'll want to give yourself a great big for this one.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Ok Michael,

      I've not yet slapped my head because I still haven't figured out your hint.

      Another hint, please.

      Comment


      • #4
        Gary,

        The problem is that you have used an Option control without applying %WS_GROUP.

        This doesn't lock up..
        Code:
        #Compile Exe
        #Dim All
        #Include "Win32API.inc"
        Global hDlg As Dword
        Function PBMain() As Long
           Dialog New Pixels, 0, "Test Code",300,300,600,500, %WS_OverlappedWindow To hDlg
           AddTAB
           Control Add Option, hDlg, 150, "Pick Me!", 20,290, 100,20 ,%WS_GROUP
           Dialog Show Modal hDlg
        End Function
         
        Sub AddTab
          Local hPage1 As Dword, hPage2 As Dword
          Control Add Tab, hDlg, 540, "", 400,370,150,75 , %WS_GROUP
            Tab Insert Page hDlg, 540, 1,0,"Page1" To hPage1
                Control Add Label, hPage1, 550, "Label1", 20,20,60,20
        End Sub
        See http://www.powerbasic.com/support/pb...5&postcount=40
        Rgds, Dave

        Comment


        • #5
          Dave, I was just about to post my reply when I saw yours. I thought the AddTab call had to be moved after the options in order to end the group. I guess the tab control is added last even though the AddTab call is first... a little confusing, any thoughts? Also, I used two options to more clearly illustrate the problem.

          Code:
          #DIM ALL
          #INCLUDE "Win32API.inc"
          GLOBAL hDlg AS DWORD
          
          FUNCTION PBMAIN() AS LONG
             DIALOG NEW PIXELS, 0, "Test Code",200,200,600,500, %WS_OverlappedWindow TO hDlg
             CONTROL ADD OPTION, hDlg, 150, "Pick Me!", 20,260, 100,20, %WS_GROUP
             CONTROL ADD OPTION, hDlg, 151, "Not Me!", 20,290, 100,20
             AddTab
             DIALOG SHOW MODAL hDlg
          END FUNCTION                           
          
          SUB AddTab
            LOCAL hPage1 AS DWORD
            CONTROL ADD TAB, hDlg, 540, "", 400,370,150,75, %WS_GROUP
            TAB INSERT PAGE hDlg, 540, 1, 0, "Page1" TO hPage1
            CONTROL ADD LABEL, hPage1, 550, "Label1", 20,20,60,20
          END SUB

          Comment


          • #6
            In Cary's test code there are no more controls after the option button so the %WS_GROUP style is added to the first control in the dialog (actually next in the Tab order if you like) as explained in the help file..

            PB Help -> Control Add Option:
            In addition, the first OPTION control in a group should have the style %WS_GROUP (to mark the beginning of a group of buttons) and %WS_TABSTOP.
            The remainder of the OPTION controls in the group should not have %WS_GROUP or %WS_TABSTOP styles.
            However, the very next non-OPTION control to appear in the tab order after the group should be given the %WS_GROUP and %WS_TABSTOP styles (the latter may depend on the type of control it is).
            If there are no other controls after the group, add %WS_GROUP to the first control in the dialog.
            This ensures that keyboard navigation with the arrow keys will operate within the group of OPTION controls, and that the TAB and SHIFT+TAB keys will switch focus between whole groups of controls (instead of individual controls as is common when each group member has the %WS_TABSTOP style).
            Rgds, Dave

            Comment


            • #7
              Thanks for the help guys.

              And you're right, in this example it takes BOTH %WS_Group additions to work correctly.

              But, in general I understood that the inclusion of %WS_Group has to do with whether a group of option controls will work correctly (navigation and focus issues) - not with whether an app will freeze without them.

              For example, here's another example with non-TAB controls - no %WS_Group - and it works fine. I tested all of the other common controls and only the TAB control results in the freeze. That's still a mystery!

              Code:
              #Compile Exe
              #Dim All
              Global hDlg As Dword
              Function PBMain() As Long
                Dialog New Pixels, 0, "Option Test",300,300,300,200, %WS_SysMenu, 0 To hDlg
                Control Add Option, hDlg, 197,"Click Me!", 50,50,100,20
                Control Add Label, hDlg, 198,"Click Me!", 50,80,100,20
                Dialog Show Modal hDlg Call DlgProc
              End Function
              
              CallBack Function DlgProc() As Long
                If Cb.Msg = %WM_Command  Then
                End If
              End Function
              But thanks for the reminder, and for the specific fix. Since it wasn't required with other controls I didn't give it a try.

              Comment


              • #8
                It would be great to see this work with PBFORMS and without the required .PBR.
                Glad you figured out the %WS_GROUP thing. I need to read on that, again.

                Starting with templates/skeletons/wizards can greatly speed up development.
                This is one reason I like the structure of PBForms.
                Last edited by Mike Doty; 17 Sep 2009, 09:09 AM.
                The world is full of apathy, but who cares?

                Comment


                • #9
                  From the CONTROL ADD OPTION documentation.
                  Option buttons are used for presenting a list of choices, only one of which may be selected. So, there is no point in having just a single option button.
                  If more than one CONTROL ADD OPTION statement had been used as the help file indicates it might have been more apparent that something more was needed. You know, something to make them function the way option buttons were meant to, like blanking any other OPTION buttons of the %WS_GROUPing.
                  Rod
                  In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                  Comment


                  • #10
                    What I noticed in your first post was ...
                    Code:
                    Dialog New Pixels, 0, ...TO hDl
                    ... with no "g" at the end of what was supposed to be "hDlg"

                    But I just copied it to make this post, and when pasted the "g" is there!

                    No, really! I still cannot see the 'g' in the first post!

                    [ADDED]
                    Hmm, I get a myself. There's a second scrollbar WITHIN the internal code block and you need to hit that one to see the 'g'.

                    How did you do that? Did you use "code block within code block?" Don't do that.

                    MCM
                    Last edited by Michael Mattias; 17 Sep 2009, 08:06 AM.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      While the WS_GROUP style solves the problem, the behavior is not typical of Windows.

                      If I create two radio controls and a tab control and forget to use WS_GROUP using SDK style code, it does not lock up the app, when using a custom dialog class (forwards messages to actual dialog engine).
                      Chris Boss
                      Computer Workshop
                      Developer of "EZGUI"
                      http://cwsof.com
                      http://twitter.com/EZGUIProGuy

                      Comment


                      • #12
                        Interesting Chris ... so we're still left to wonder why it freezes in a DDT dialog, and why only with a TAB control.

                        MCM, I don't know how I did that double-scroll thing. All I ever do is cut/paste and hit the code button. Does double [code] do that?

                        Code:
                        [code]is this double scrolled
                        [/code]

                        ?Nope - that didn't double scroll - but I'll watch and try to catch how it happened the next time it pops up.

                        Mike - did you mean the All 21 snippet? If so, I'm pretty sure I can make it work without a PBR. Let me know if that's what you wanted.

                        Rodney - I always hate it when Help says something like "there's no point in ..." doing something. It makes me try to think up reasons to do it!

                        Comment


                        • #13
                          Gary, you are doubling up on the code blocks. In your last post, you can clearly see that there are two boxes both preceded by the word "Code:". The reason the second one didn't have a second scroll bar is that the line was too short. If you put in:

                          [ CODE ]
                          [ CODE ]
                          This is a really long test line to make the code window have a scroll bar at the bottom for testing purposes.
                          [ /CODE ]
                          [ /CODE ]

                          you will get:

                          Code:
                          [CODE]
                          This is a really long test line to make the code window have a scroll bar at the bottom for testing purposes.
                          [/CODE]

                          As to the original topic of this thread. I'm thinking that in your original code, something probably has a %WS_GROUP style by default and without that style added to the option button, it thinks it is part of the currently defined group and Windows is possibly treating the other controls as option buttons and trying to clear their state which could lead to your program going off into space.

                          Someone mentioned that this doesn't happen with SDK code but I'm not sure the DDT and SDK equivalents have the same default styles. Someone would have to check on that to be sure they were both doing the same thing.
                          Jeff Blakeney

                          Comment

                          Working...
                          X