Announcement

Collapse
No announcement yet.

How to disable all other dialogs when a selected child dialog is active

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

  • How to disable all other dialogs when a selected child dialog is active

    I need a child dialog to be the only active dialog when I can enter data into it and then I can exit this child dialog and then all other
    dialogs can be reactivated. How to disable all other dialogs as I need to concentrate on one child dialog ?

    My prog is listed :
    Code:
    ' Main 2Childs.bas
    
      ' Mod from
      ' https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/818678-how-to-drag-a-modeless-child-dialog?p=818680#post818680
    
          ' Program to demonstrate data entry into Main and 2 other child dialogs
    
          ' Here the Main dialog can be dragged together with the child dialog1
          ' in a lock
          ' While the child dialog2 cannot be dragged at all
    
    
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE ONCE "WIN32API.INC"
    
     #RESOURCE MANIFEST, 1, "XPTheme.xml"
    
     ENUM equates SINGULAR
             ID_ExplainLbl  = 2000
             ID_ExplainLbl2
    
             ID_LanChild1_Btn
             ID_LanChild2_Btn
    
             ID_ExitBtn
             ID_DoneBtn
             ID_DoneBtn2
    
    
             ID_MainTbox
    
    
             ID_Ch1Tbox
             ID_Ch2Tbox
    
    
     END ENUM
    
    
    
    
     GLOBAL hbDlg, hDlgChd1 ,hDlgChd2   AS DWORD
    
     GLOBAL chst1 , chst2  , MainSt AS STRING
    
    
    
    
    
    
    
    ' Main
     FUNCTION PBMAIN () AS LONG
    
        DIALOG NEW PIXELS , 0, "Main Dialog", 60,60 , 280,600 TO hbDlg
    
           CONTROL ADD LABEL, hbDlg, %ID_ExplainLbl, _
          "This is the Main Dialog" + $$CRLF + _
           "with 2 child dialogs.", 5, 5, 140, 90
    
    
         CONTROL ADD TEXTBOX, hbDlg, %ID_MainTbox , "", 10, 70, 223, 82, _
         %ES_LEFT OR %ES_MULTILINE  OR %ES_WANTRETURN OR _
         %WS_VSCROLL OR %WS_GROUP, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
    
    
          CONTROL ADD BUTTON, hbDlg, %ID_LanChild1_Btn, _
                   "Child1", 75, 290, 60, 20
    
          CONTROL ADD BUTTON, hbDlg, %ID_LanChild2_Btn, _
                   "Child2", 75, 390, 60, 20
    
          CONTROL ADD BUTTON, hbDlg, %ID_ExitBtn, _
                   "Exit", 75, 490, 30, 20
    
      DIALOG SHOW MODAL hbDlg CALL DlgProc
    
    END FUNCTION
    
    
    
    
    
    
    CALLBACK FUNCTION DlgProc() AS LONG
     ' these lock up the main and child dialog
      LOCAL  pMainRect  AS RECT POINTER
      LOCAL  ChildRectm  AS RECT
      LOCAL  MainRectm   AS RECT
      STATIC DeltaXm     AS LONG
      STATIC DeltaYm     AS LONG
    
      SELECT CASE CB.MSG
          CASE %WM_INITDIALOG
    
    
    
    
          CASE %WM_MOVING
        'https://forum.powerbasic.com/forum/user-to-user-discussions/dynamic-dialog-tools-ddt/53921-ws_child-dialog-question?p=641990#post641990
       ' this will make the Main dialog move with the child dialog together in tandem
         pMainRect = CB.LPARAM
         SetWindowPos(hDlgChd1, 0, @pMainRect.nLeft - DeltaXm, @pMainRect.nTop - DeltaYm, _
                      0, 0, %SWP_NOSIZE OR %SWP_NOACTIVATE)
    
    
           CASE %WM_COMMAND
               SELECT CASE AS LONG CB.CTL
                  'better with AS LONG, AS CONST only if
                  'CASE values are consecutive
    
                CASE %ID_LanChild1_Btn
                   ' dialog disable cb.hndl
                      ' launch child1 dialog
                         ShowChild1
                       ' gets the positions of main and child dialogs to lock  them up in tandem
                        GetWindowRect(hbDlg, MainRectm)
                        GetWindowRect(hDlgChd1, ChildRectm)
                        DeltaXm = MainRectm.nLeft - ChildRectm.nLeft
                        DeltaYm = MainRectm.nTop  - ChildRectm.nTop
                    ' dialog enable cb.hndl
    
                CASE %ID_LanChild2_Btn
                    ' launch child2 dialog
                      ShowChild2
    
    
                CASE %ID_ExitBtn
                     ' Exit button was pressed -- fade out the window very slowly
                      AnimateWindow CB.HNDL, 3500, %AW_CENTER OR %AW_hide
                      DIALOG END CB.HNDL
    
    
           END SELECT
    
      END SELECT
    END FUNCTION
    
    
    
    
    
    ' display the child dialog1
    SUB ShowChild1()
    
      ' for child dialog you need to have a reference handle to its
      ' parent dialog,  hence we use " DIALOG NEW hbDlg "
      ' rather than " DIALOG NEW 0 "
    
    
      '  %DS_3DLOOK OR  %DS_MODALFRAME OR %DS_SYSMODAL OR _
      '     %WS_DLGFRAME OR %WS_POPUP, _
      '      %WS_EX_LEFT OR %WS_EX_LTRREADING,  TO hDlgChd1
      '
    
      DIALOG NEW PIXELS, hbDlg, "", 250, 0, 360, 200, %WS_POPUP,  TO hDlgChd1
    
         'note to use style %DS_SYSMODAL I also had to "OR"
         ' the default styles that
         'that I want to use. "Default" is only if no
         ' other styles are used.
         '
        CONTROL ADD LABEL, hDlgChd1, %ID_ExplainLbl, _
         " This is Child Dialog 1", _
            10, 15, 170, 30
    
    
       CONTROL ADD TEXTBOX, hDlgChd1, %ID_Ch1Tbox, "",_
                10, 120, 203, 22
    
    
    
        CONTROL ADD BUTTON, hDlgChd1, %ID_DoneBtn, _
                 "Exit", 65, 178, 65, 20
    
    
     '   Note that MODAL will make this child dialog dominant
     '   so equal footing put MODELESS
      '   dialog show modal hDlgChd1 call DlgChd1_Proc
    
         DIALOG SHOW MODELESS hDlgChd1 CALL DlgChd1_Proc
    
    END SUB
    
    
    
    
    
    CALLBACK FUNCTION DlgChd1_Proc() AS LONG
       LOCAL hDC1 AS LONG
    
     ' these are for locking up the main and child dialogs in tandem
       LOCAL  pChildRect AS RECT POINTER
       LOCAL  ChildRect  AS RECT
       LOCAL  MainRect   AS RECT
       STATIC DeltaX     AS LONG
       STATIC DeltaY     AS LONG
    
    
       SELECT CASE AS LONG CB.MSG
         CASE %WM_INITDIALOG
                ' Initialization handler
                ' gets the positions of main and child dialogs
                  GetWindowRect(hbDlg, MainRect)
                  GetWindowRect(hDlgChd1, ChildRect)
                  DeltaX = ChildRect.nLeft - MainRect.nLeft
                  DeltaY = ChildRect.nTop  - MainRect.nTop
    
    
    
     CASE %WM_MOVING
        'https://forum.powerbasic.com/forum/user-to-user-discussions/dynamic-dialog-tools-ddt/53921-ws_child-dialog-question?p=641990#post641990
       ' this will make the Main dialog move with the child dialog together in tandem
         pChildRect = CB.LPARAM
         SetWindowPos(hbDlg, 0, @pChildRect.nLeft - DeltaX, @pChildRect.nTop - DeltaY, _
                      0, 0, %SWP_NOSIZE OR %SWP_NOACTIVATE)
    
           CASE %WM_ERASEBKGND
                 hDC1 = CB.WPARAM
                 DrawGradient hDC1, 1
                 FUNCTION = 1
                 EXIT FUNCTION
    
    
           CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CB.CTL
                  IF (CB.MSG = %WM_COMMAND) AND CB.CTL = %ID_DoneBtn THEN
                    ' Exit button was pressed -- fade out the window VERY slowly
                      AnimateWindow CB.HNDL, 3500, %AW_CENTER OR %AW_hide
                      DIALOG END CB.HNDL
                  END IF
    
                END SELECT
       END SELECT
    
    
    END FUNCTION
    
    
    
    
    
    ' display the child dialog2
    SUB ShowChild2()
    
      ' for child dialog you need to have a reference handle to its
      ' parent dialog,  hence we use " DIALOG NEW hbDlg "
      ' rather than " DIALOG NEW 0 "
    
    
       '  %DS_3DLOOK OR  %DS_MODALFRAME OR %DS_SYSMODAL OR _
       '    %WS_DLGFRAME OR %WS_POPUP, _
       '     %WS_EX_LEFT OR %WS_EX_LTRREADING,  TO hDlgChd2
    
    
      DIALOG NEW PIXELS, hbDlg, "", 250, 201, 360, 250,%WS_POPUP,TO hDlgChd2
    
         'note to use style %DS_SYSMODAL I also had to "OR"
         ' the default styles that
         'that I want to use. "Default" is only if no
         ' other styles are used.
         '
        CONTROL ADD LABEL, hDlgChd2, %ID_ExplainLbl2, _
         " Child2 dialog where " + _
         " all good stuff are located", _
            10, 15, 170, 40
    
        CONTROL ADD TEXTBOX, hDlgChd2, %ID_Ch2Tbox, "", 10, 80, 203, 22
    
    
        CONTROL ADD BUTTON, hDlgChd2, %ID_DoneBtn2, _
                 "Exit", 65, 125, 65, 20
    
    
     '   Note that MODAL will make this child dialog dominant
     '   so equal footing put MODELESS
      '  dialog show modal hDlgChd2 call DlgChd2_Proc
    
         DIALOG SHOW MODELESS hDlgChd2 CALL DlgChd2_Proc
    
    END SUB
    
    
    
    '=========================================
    CALLBACK FUNCTION DlgChd2_Proc() AS LONG
       LOCAL hDC2 AS LONG
    
       SELECT CASE AS LONG CB.MSG
         CASE %WM_INITDIALOG
                ' Initialization handler
    
           CASE %WM_ERASEBKGND
                 hDC2 = CB.WPARAM
                 DrawGradient hDC2, 2
                 FUNCTION = 1
                 EXIT FUNCTION
    
    
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CB.CTL
                  IF (CB.MSG = %WM_COMMAND) AND CB.CTL = %ID_DoneBtn2 THEN
                    ' Exit button 2 was pressed -- fade out the window slowly
                      AnimateWindow CB.HNDL, 1500, %AW_CENTER OR %AW_HIDE
                      DIALOG END CB.HNDL
                  END IF
    
                END SELECT
       END SELECT
    
    END FUNCTION
    
    
    
    
    
    
    
    
    
    ' Shade the dialog background
     SUB DrawGradient (BYVAL hDC AS DWORD, BYVAL p AS LONG)
      LOCAL rectFill AS RECT
      LOCAL rectClient AS RECT
      LOCAL fStep AS SINGLE
      LOCAL hBrush AS DWORD
      LOCAL lOnBand AS LONG
    
      GetClientRect WindowFromDC(hDC), rectClient
      fStep = rectClient.nbottom / 200
    
      FOR lOnBand = 0 TO  239 '199
        SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
    
        SELECT CASE p
          CASE 1
            hBrush = CreateSolidBrush(RGB(250, 239, 255 - lOnBand))
          CASE 2
            hBrush = CreateSolidBrush(RGB(250, 255 - lOnBand, 220))
          CASE ELSE
    
            hBrush = CreateSolidBrush(RGB(255 - lOnBand, 251, 240))
        END SELECT
    
        Fillrect hDC, rectFill, hBrush
        DeleteObject hBrush
      NEXT
    
    END SUB​


    in my code above, I tried to use control disable cb.hndl after launching the child dialog1 and then control enable cb.hndl
    upon finishing the child dialog1 but not successful

    I would like to know how to shut off all other dialogs when I'm inside child dialog1 ?
    and when I exit this child dialog1 , these dialogs are to be active again.

    Code:
    CASE %ID_LanChild1_Btn
                   ' dialog disable cb.hndl
                      ' launch child1 dialog
                         ShowChild1
                       ' gets the positions of main and child dialogs to lock  them up in tandem
                        GetWindowRect(hbDlg, MainRectm)
                        GetWindowRect(hDlgChd1, ChildRectm)
                        DeltaXm = MainRectm.nLeft - ChildRectm.nLeft
                        DeltaYm = MainRectm.nTop  - ChildRectm.nTop
                    ' dialog enable cb.hndl​

  • #2
    Have you seen DIALOG DISABLE in Help?
    Dale

    Comment


    • #3
      Mannish,

      A "MODAL" dialog will do this normally. Just look up your dialog setting and set the one you want to a modal dialog.
      hutch at movsd dot com
      The MASM Forum - SLL Modules and PB Libraries

      http://www.masm32.com/board/index.php?board=69.0

      Comment


      • #4
        Initial response deleted.

        Too many other issues with the posted code to come up with a working solution
        (For a start -Click on a chile button a few times and you get multiple instances of the child child dialog stacked on top of each other)

        Comment


        • #5
          This statement:
          ' Note that MODAL will make this child dialog dominant
          ' so equal footing put MODELESS​
          twice in code.

          Then this request:
          I would like to know how to shut off all other dialogs when I'm inside child dialog1 ?
          and when I exit this child dialog1 , these dialogs are to be active again.​
          directly oppose each other.

          How about desired operation in words.

          Both child dialogs have bDlg as parent. If parent is DISABLEed the button to get other child won't work. So only one child at a time. Could have stayed with MODAL in the first place!
          Dale

          Comment


          • #6
            And define "exit this child dialog1". Close it or click on another window somewhere else on the screen (if you disabled the other dialogs, you can't click on them.)

            Comment


            • #7
              Mannish,

              It looks like you need to do some architectural changes to your multiple dialogs. I am not really up to date with the wrapper style dialogs since its about 12 or 13 years since I was on the BETA team for the current versions of PowerBASIC but just a quick look up in the help files gives you the two basic styles you need to what you appear to be trying to do.

              Withthe DIALOG NEW command, you can set a style, The modeless dialog allows you to run multiple dialogs at the same time. The modal dialog does what you need, it blocks that other dialog that it is called from until it is closed. One of the members who write that style of code may be able to help you, my background is Windows system code and while the logic is the same, the notation is different.


              hutch at movsd dot com
              The MASM Forum - SLL Modules and PB Libraries

              http://www.masm32.com/board/index.php?board=69.0

              Comment


              • #8
                Thanks all, my codes are in a mess!

                Comment


                • #9
                  Nice example by Kurt Kuzba, not saying it's the final answer, but it will give you clues. HTH

                  An input box routine with the capacity to filter characters Additional functions: ESC to exit without saving; ENTER to accept; CTRL/N to clear input. Implementing a greater degree of control for specific uses would be simple, using a method such as this. A time and date setting routine, for instance, moving with TAB or cursor

                  Comment


                  • #10
                    Thanks Jules, this InputBox is probably what I needed

                    Comment

                    Working...
                    X