Announcement

Collapse
No announcement yet.

DDT: LABEL won't show on dialog

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

    DDT: LABEL won't show on dialog

    Here is a problem I cannot seem to figure out. Using PB.DLL 6.0, DDT style:

    I have a dialog which I SHOW MODAL ; it works fine.

    In a callback function for one of the buttons, I want to create a modeless dialog to show that I am processing a long function.

    The idea is to do this:

    Code:
    GLOBAL ghDlg AS LONG, ghWaitDlg AS LONG
    ...
    
    CALLBACK FUNCTION DoItCallBack() AS LONG
    
        IF CBMSG = %BN_CLICKED  THEN
          DIALOG NEW ghDlg, "Caption....",%CW_USEDEFAULT, %CW_USEDEFAULT, 150, 60, %DS_CENTER OR %WS_CAPTION TO ghWaitDlg
          CONTROL ADD LABEL, ghWaitDlg, -1, "Please Wait...",   10, 30, 100, 14, %SS_LEFT 
    
          DIALOG SHOW MODELESS ghWaitDlg TO WaitResult ' paints without the caption
    '>> tried DIALOG DOEVENTS here, tried DIALOG SHOW STATE, too
          Stat = LongRunningFunctionWhichDoesNOGUI (parms...)
          DIALOG END ghWaitDlg
        END IF
    END FUNCTION

    What is happening is the modeless dialog is launched and dies at the correct time with the caption, but the "LABEL" on that dialog does not appear. I just get a blank "dialog client area" (below the caption).

    I have tried using LOCAL and GLOBAL dialog handles, real ID's and -1 for the LABEL control, inserting a DIALOG DOEVENTS, even played with the X and Y of the DIALOG NEW statement itself.

    I even tried creating (DIALOG NEW..CONTROL ADD..) the modeless dialog in WinMain when I create the "main" dialog and then just doing the DIALOG SHOW in the above callback function.


    On one try and one try only did I get the text to appear, but that was when I made a mistake and did a DIALOG END of the WRONG dialog.

    Eventually I want to change the LABEL control into a "progress bar" control, but until I can get a simple label to show up I'm a little reluctant to go hacking up my main processing code (to keep track of the percent done).


    Can anyone tell me what I am missing here?

    Is it something simple? Will I be saying, "duh?"


    Thanks,






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

    #2
    In 'Control Add Label..' you have overridden the default style-setting with %SS_LEFT as your only style.
    You have to add %WS_CHILD at least.


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Comment


      #3
      Good thought, and it's one I did not try because my "main" dialog uses only %SS_LEFT on six other lables and everything shows up just fine.

      But...

      I made it %SS_%LEFT OR %WS_CHILD OR %WS_VISIBLE, and I get the same results as before.

      Any other ideas?

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

      Comment


        #4
        Michael...

        Change

        IF CBMSG = %BN_CLICKED

        to

        IF CBCTLMSG = %BN_CLICKED THEN

        So the code will execute... Also note that Lance has always
        stated that a modeless dialog needs a message pump. I don't know
        if that comes into play in this situation but I would assume so.



        ------------------
        Jim..
        [email protected]
        Jim..

        Comment


          #5
          Well, I missed that you were showing a modless dialog in a
          callback function.
          Your callback will not return <=> no messages handled until
          you have ended your modless dialog.
          You will need a lot of Dialog DoEvents in your 'LongRunningFunctionWhichDoesNOGUI '

          I am not doing that much DDT, so I cannot tell if this is a less efficient
          way to do it.
          I prefere to start this kind of operations in a seperate thread and
          let this Thread set a flag when finished.
          Code:
              DIALOG SHOW MODELESS ghWaitDlg TO WaitResult 
          Dim P as MyThreadUDT
              P.RetCode = 0
              P.OtherParms = ...
              Thread Create LongRunningFunctionWhichDoesNOGUI(Byval VarPtr(P)) to ThreadId&
              Thread Close ThreadId& to ThreadId&
              Do
                  ' Allow messages to be dispatched
                  Dialog DoEvents
                  ' Query the Thread global flag
              Loop While P.RetCode = 0

          ------------------
          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Comment


            #6
            Michael,

            Maybe the following code will help... I put the message pump inside
            your longRunningSub()

            Code:
            #COMPILE EXE
            #DIM ALL
            #INCLUDE "win32api.INC"
            DECLARE CALLBACK FUNCTION DoItCallBack()
            DECLARE SUB longRunningSub()
            GLOBAL ghDlg AS LONG, ghWaitDlg AS LONG
            
            FUNCTION PBMAIN
               LOCAL hDlg AS LONG
               DIALOG NEW 0, "Test", , , 200, 85, %WS_SYSMENU + %WS_CAPTION TO ghDlg
               CONTROL ADD BUTTON, ghDlg, %IDOK, "&Ok", 5, 20, 90, 14
               DIALOG SHOW MODAL ghDlg CALL DoItCallBack
            END FUNCTION
            
            CALLBACK FUNCTION DoItCallBack() AS LONG
               LOCAL waitResult AS LONG
               SELECT CASE CBMSG
               CASE %WM_COMMAND
                  SELECT CASE CBCTL
                     CASE %IDOK
                        DIALOG NEW ghDlg, "Caption....", , , 150, 60, %DS_CENTER OR %WS_CAPTION TO ghWaitDlg
                        CONTROL ADD LABEL, ghWaitDlg, -1, "Please Wait...",   10, 30, 100, 14, %SS_LEFT
                        DIALOG SHOW MODELESS ghWaitDlg
                        longRunningSub
                        DIALOG END ghWaitDlg
                     END SELECT
               CASE %WM_DESTROY
                  DIALOG END ghWaitDlg
               END SELECT
            END FUNCTION
            
            SUB longRunningSub()
               LOCAL i AS LONG
               FOR i = 1 TO 2000
                  DIALOG DOEVENTS
               NEXT i
            END SUB
            ------------------

            Comment


              #7
              Well, guys, putting some DIALOG DOEVENTS in the LargeSubWhichDoesNoGUI did the trick; thanks for the tips.

              I had to "tune" how often I did it, or it got real slow.

              Now that I got the label working, I can at least ship it out to the customer; he can use it "as is" until I get the Progress Bar working to replace the simple label.

              PB should really think about adding some documentation on this:
              Who'd a thunk "DIALOG SHOW" would *not* show all the controls unless you call DIALOG DOEVENTS several times???

              MCMMCM

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

              Comment


                #8
                Michael, the section on modeless dialogs in the chapter "Dynamic Dialog Tools" does describe using a message pump, and a simplistic example of a message pump. However, I'll ask the documentation department to make this point clearer in the next update to the documentation.

                Also I should point out that the ADDRESS.BAS example code also shows how to create a message pump for a modeless dialog too.

                Finally, it is worth noting that DDT modeless dialogs operate just like conventional SDK-style modeless dialogs, in that a message pump must be running for messages in the message queue to be dispatched and processed. Most (if not all!) Windows GUI programming books explain modal and modeless dialog theory in great detail. Having such a book in your collection can often prove a valuable addition to the reference library you no-doubt already have!

                I hope this helps.

                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment


                  #9
                  Why, yes, I do have a good reference library, and I have used it to learn "the API way" of doing Windows(r) programs.

                  This little excursion is a good example of "why it's good to learn the long way before using a programming tool such as DDT."

                  Intuitively, I thought DIALOG SHOW would, well, "show" the whole dialog with all its controls, essentially taking over the system until the modeless dialog reached input idle, having processed all the messages associated with the creation and presentation of a dialog box.

                  But that's not how DIALOG SHOW MODELESS works.

                  Well, that's why we experiment: to see what happens.

                  At least it's not as "hidden" as some of those "objectname.thingtodo" syntax items in certain other development products.

                  MCM


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

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎