Announcement

Collapse
No announcement yet.

How to Disable and enable without flicker?

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

  • How to Disable and enable without flicker?

    In my program the main window must be disabled when a message box appears.
    In this way the user have to answer the message box before he can go on in the main window.
    To do this I wrote the lines 1, 2, 3 and 5 in the callback function Button_Click (see below),
    but the main window was in the background after the message box was answered.
    After I added line 4 the main window gets to the foreground but now there is a little flicker
    because the window disappears and reappears.
    And now my question: Is there a way to disable and enable the main window without a flicker?

    'Here is the program:

    #COMPILE EXE
    #INCLUDE "Win32api.inc"
    GLOBAL hDlg AS LONG
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION Button_Click() AS LONG
    1: DIALOG DISABLE hDlg
    2: MSGBOX("Hallo!")
    3: DIALOG ENABLE hDlg
    4: DIALOG SHOW STATE hDlg, %SW_HIDE
    5: DIALOG SHOW STATE hDlg, %SW_SHOWNORMAL
    END FUNCTION
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN() AS LONG
    DIALOG NEW 0, "Test-Program", 0,0, 640, 480, %WS_SYSMENU OR %WS_EX_TOPMOST TO hDlg
    CONTROL ADD BUTTON, hDlg, 1, "Click me!", 100,100,100,50,,CALL Button_Click
    DIALOG SHOW MODAL hDlg
    END FUNCTION



    ------------------

  • #2
    I think it's better to use the MessageBox API instead. Remove
    all disable/enable code and try the following:
    Code:
      MessageBox hDlg, "Hello", "Title", %MB_OK
    ------------------

    Comment


    • #3
      Instead of using MSGBOX, use the MessageBox() API and specify the original dialog as the parent, that way you should be able to avoid all of the problems with restoring the original window.

      A couple of other notes for you:
      1. There is no need to use a global variable, as CBHNDL will identify the dialog in the callback function.
      2. the %WS_EX_TOPMOST is an extended style, and you are using it in the normal style position.
      3. You need to explicitly test for a click event before processing the callback event... there could be other notification messages sent to your callback, and as it stands, the callback will treat all messages as a clickl without any regard to the real message.
      4. When processing a message in a callback, be sure to return TRUE (non-zero) so that the default handler knows not to pass the message any further (such as to the dialog callback, if one exists, or the default handler itself).

      So, with these points in mind, here is my version of your program...
      Code:
      #COMPILE EXE
      #INCLUDE "Win32api.inc"
      '------------------------------------------------------------------------------
      CALLBACK FUNCTION Button_Click() AS LONG
          IF CBMSG <> %WM_COMMAND AND CBCTLMSG <> %BN_CLICKED THEN EXIT FUNCTION
          MessageBox CBHNDL, "Hello World!", "Caption", %MB_OK
          FUNCTION = 1
      END FUNCTION
      '------------------------------------------------------------------------------
      FUNCTION PBMAIN() AS LONG
          DIM hDlg AS LONG
          DIALOG NEW 0, "Test-Program", 0,0, 160, 120, %WS_SYSMENU OR %WS_CAPTION, %WS_EX_TOPMOST TO hDlg
          CONTROL ADD BUTTON, hDlg, 1, "Click me!", 30,35,100,50,,CALL Button_Click
          DIALOG SHOW MODAL hDlg
      END FUNCTION
      I hope this helps!


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

      Comment


      • #4
        Afaik, he just wants the msgbox modal..

        Use %MB_TASKMODAL for that.
        No hassle with disabled windows.

        ------------------
        [email protected]
        hellobasic

        Comment


        • #5
          Or better

          MessageBox hDlg, "Hello", "Title", %MB_OK OR %MB_TASKMODAL

          ------------------


          [This message has been edited by Gafny Jacob (edited October 22, 2000).]

          Comment


          • #6
            Using MessageBox() does create a modal dialog as long as you give it the parent dialog handle...


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

            Comment


            • #7
              Thank you for your help!
              My problem is solved.

              ------------------

              Comment


              • #8
                Lance,

                Yes modal but i believe for THAT parent window only.
                But if you have multiple windows the taskmodal is better (if needed).

                Now we are talking modal here what about the inputbox$.
                Can't get that one modal..


                ------------------
                [email protected]
                hellobasic

                Comment


                • #9
                  The question specifically concerned a single application window/dialog.

                  InputBox$ is a bit like LINE INPUT... fine for simple tasks where a modal dialog is not required... constructing a replacement that fits your requirements is a cinch with DDT.




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

                  Comment

                  Working...
                  X