Announcement

Collapse
No announcement yet.

Need Help with ERROR 546

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

  • Need Help with ERROR 546

    Have the following code

    CONTROL ADD BUTTON, hDlg, %BU8, "&0 CANCEL",440, 45, 50, 14, CALL Record_Cancel

    CALLBACK FUNCTION Record_Cancel()
    DIALOG END hDlg, 1
    CALL MAINMENU
    END FUNCTION

    error 546 contains the following info:
    To reference it indirectly, send an appropriate window message using CONTROL SEND or DIALOG SEND. To send custom messages, be sure to use message values higher than %WM_USER+500 to avoid conflicts with other notification mess

    Here is where I am stuck, use CONTROL SEND or DIALOG SEND.

    CONTROL SEND hDlg, %ID_BTN1, %BU8_CLICK, 0, 0
    If I use CONTROL SEND not sure how to use this.

    DIALOG SEND CB.HNDL, %WM_USER, VARPTR(Param1&), VARPTR(Param2&)
    If I use DIALOG SEND do not understand this. What to plug in VARPTR(Param1&), VARPTR(Param2&)??
    Robert

  • #2
    Are you having a problem with the code you posted ?

    The only thing that I would wonder about is that since you are using hDlg,
    did you make hDlg GLOBAL ? If not, you could use CBHNDL (I guess it's CB.HNDL in version 9) instead of hDlg.

    Although you can have a callback for each control, I prefer, personally,
    1 Callback function for all controls using select/end select. In my opinion, it's
    much easier to understand control send/dialog send within the one callback.

    I would post an example but there are so many already available that would be much better that what I would post so I will not post an example.

    The Call MainMenu in the callback function is probably not the best place to put it.
    I would suggest after the Dialog Show statement but without more code, a specific placement would be difficult to state.
    Last edited by Fred Buffington; 23 Sep 2009, 11:08 PM.
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page

    Comment


    • #3
      Robert,
      See the help file topic "Callbacks' for more detail but here's some test code that might help you..
      Code:
      #DIM ALL
      #Compile Exe
      #Include "WIN32API.INC"
       
      %BU8  = 101
      %BU9  = 102
      %BU10 = 103
      Global hDlg As Dword
      '------------------/
       
      CallBack Function Record_Cancel()   ' BU8 CallBack
       'DIALOG END hDlg, 1
       'CALL MAINMENU
       'CALL DlgProc    <= illegal. Can't call a CallBack Function directly - Error 546
         If Cb.Msg = %WM_COMMAND AND Cb.CtlMsg = %BN_CLICKED Then
           WinBeep 800,500 
           Dialog Send hDlg, %WM_SYSCOMMAND, %SC_CLOSE, Mak(DWORD, 0, -1)
           'Dialog Send Cb.Hndl, %WM_SYSCOMMAND, %SC_CLOSE, Mak(DWORD, 0, -1)
           Function = 1
         End If
      End Function
      '------------------/Record_Cancel
       
      CallBack Function Indirect()        ' BU9 CallBack
        Select Case Cb.Msg
          Case %WM_Command
            If Cb.CtlMsg = %BN_Clicked Or Cb.CtlMsg = 1 Then
              WinBeep 400,500 
              Control Send hDlg, %BU8, %BM_CLICK, 0, 0
              'Control Send Cb.Hndl, %BU8, %BM_CLICK, 0, 0
            End If
        End Select
      End Function 
      '------------------/Indirect
       
      CallBack Function DlgProc()         ' Dialog CallBack
        Select Case As Long Cb.Msg 
          Case %WM_COMMAND
            Select Case As Long Cb.Ctl
              Case %BU10
                If Cb.CtlMsg = %BN_CLICKED Or Cb.CtlMsg = 1 Then
                  WinBeep 200,500
                  Control Send hDlg, %BU9, %BM_CLICK, 0, 0
                  'Control Send Cb.Hndl, %BU9, %BM_CLICK, 0, 0
                End If
            End Select
          Case %WM_SYSCOMMAND
            If (Cb.WParam AND &HFFF0) = %SC_CLOSE Then
              Dialog End hDlg, 1
              'Dialog End Cb.Hndl, 1
            End If
        End Select
      End Function 
      '------------------/DlgProc
       
      Function PBMain() As Long 
       'Local hDlg As Dword ' use Local hDlg here and Cb.Hndl in Callbacks as alternative to Global hDlg
        Dialog New 0, "Test", , , 500, 150, %WS_Caption Or %WS_SysMenu, 0 To hDlg
          CONTROL ADD BUTTON, hDlg, %BU8, "&0 CANCEL",440, 45, 50, 14, CALL Record_Cancel  ' ENABLES CallBack here
          CONTROL ADD BUTTON, hDlg, %BU9, "Indirect",440, 65, 50, 14, CALL Indirect        ' ENABLES CallBack here
          CONTROL ADD BUTTON, hDlg, %BU10, "Via DlgProc",440, 85, 50, 14
        Dialog Show Modal hDlg, Call DlgProc                                               ' ENABLES CallBack here too
      End Function
      '------------------/PbMain
      Rgds, Dave

      Comment


      • #4
        >Here is where I am stuck, use CONTROL SEND or DIALOG SEND.

        If it's a private (to your application) message ("%BU8_CLICK"), you use the form which routes your message to the callback procedure where you have coded the handling of that message.

        If it's a predefined message ("%BM_CLICK") you send the message to the destination specified by the documentation for that message. eg, "%BM_CLICK" is sent directly to child button controls.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          "be sure to use message values higher than %WM_USER+500 to avoid conflicts with other notification mess"

          WM_USER plus 500?

          There should not be any conflicts (other than self-inflicted) with messages greater than WM_USER plus zero.

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

          Comment


          • #6
            Originally posted by Robert Alvarez View Post
            Have the following code

            CONTROL ADD BUTTON, hDlg, %BU8, "&0 CANCEL",440, 45, 50, 14, CALL Record_Cancel

            CALLBACK FUNCTION Record_Cancel()
            DIALOG END hDlg, 1
            CALL MAINMENU
            END FUNCTION
            Robert, I think you are going to have to show more code. As I understand what you have shown, as soon as any reference to %Bub is made (by Windows doing stuff in the background (updating, redrawing, etc.) or user), the Dialog will end. and won't even get to MAINMENU.

            Unless of course it's in a different thread but we can't tell from the code shown.

            ========================================
            "Three o'clock is always too late or
            too early for anything you want to do."
            Jean-Paul Sartre (1905-1980)
            ========================================
            It's a pretty day. I hope you enjoy it.

            Gösta

            JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
            LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

            Comment


            • #7
              >WM_USER plus 500?

              See help file topic Dialog Post..
              To post a custom message to a dialog, use a message value in the range of (%WM_USER + 500) to (%WM_USER + &H07FFF), or use the RegisterWindowMessage API to obtain a unique message value from the operating system. Using messages with a numeric value of less then %WM_USER + 500 may conflict with Windows Common Control messages.
              Rgds, Dave

              Comment


              • #8
                Using messages with a numeric value of less then %WM_USER + 500 may conflict with Windows Common Control messages.
                ???

                Just off the top of my head, there is but one (1) Common Controls notification message: WM_NOTIFY (value 0x4E, which is less than WM_USER at 0x400).

                And when you SEND a message to a control, who cares what its value is? So what if a button does not do the same thing with a message numbered 1234 as will a listbox or toolbar?

                Oh, well, I guess this help file suggestion shall just have to remain one of Life's Great Mysteries.

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

                Comment


                • #9
                  FWIW from the SDK:
                  Windows reserves message-identifier values in the range 0x0000 through 0x03FF (the value of WM_USER - 1) and 0x8000 through 0xBFFF for system-defined messages. Applications cannot use these values for private messages.
                  Values in the range 0x0400 (the value of WM_USER) through 0x7FFF are available for message identifiers defined by an application for its own use. Values in the range 0xC000 through 0xFFFF are available for message identifiers defined by an application for use in communicating with windows in other applications.
                  Rod
                  In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                  Comment


                  • #10
                    Looks like the fix is going to be complex. I am working on a small sample test program to post, hope to finish during weekend. The program I am working on is to large to post (about 8700 lines).
                    Robert

                    Comment


                    • #11
                      There should not be any conflicts (other than self-inflicted) with messages greater than WM_USER plus zero.
                      Self-inflicted?
                      Posting or sending messages in the range WM_USER + 0x0000 - WM_USER + 0x0064 to a window is going to get
                      you into trouble with the dialog box manager. For example, the IsDialogMessage function sends the following
                      messages to a window to deal with default buttons.
                      Code:
                      DM_GETDEFID      = WM_USER + 0
                      DM_SETDEFID      = WM_USER + 1
                      The following message handles the positioning of a top-level dialog.
                      Code:
                      DM_REPOSITION    = WM_USER + 2
                      That quote from the Help file is a strange one.
                      For example, the TB_ENABLEBUTTON message that is used to enable or disable a button in the common control
                      kown as the toolbar is defined thus
                      Code:
                      TB_ENABLEBUTTON             = WM_USER + 1
                      This is a class-specific message. That is, it is a message that is sent to a toolbar. The only way a conflict
                      can arise is if a programmer subclasses or superclasses a toolbar, sends a user defined message with the same
                      value as TB_ENABLEBUTTON to the toolbar, writes code that sings his praises, and then wonders why he or she
                      can no longer enable or disable a button.
                      Dominic Mitchell
                      Phoenix Visual Designer
                      http://www.phnxthunder.com

                      Comment


                      • #12
                        The DM_xxxx would appear to conflict with a 'WM_USER + 0' minimum, for a private message posted to a window of the dialog class .

                        WM_USER + 1 would only be a problem for a message sent to a Toolbar control

                        So maybe WM_USER + 100 would be a better 'minimum.'

                        I guess the SDK doc does not think of 'dialogs' as 'windows'.. or at the very least treats them as second-class windows.


                        >Self-inflicted [conflict]?
                        ===>
                        Code:
                        %WM_MY_FIRST_MESSAGE    =  WM_USER + 10
                        %WM_MY_SECOND_MESSAGE =  WM_USER + 10
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          ok here is the sample test code that shows error 546 and would like to see if there is a way to fix it.

                          Code:
                          #COMPILE EXE
                          #DIM ALL
                          
                          GLOBAL hDlg  AS LONG, TEXT1 AS STRING
                          
                          CALLBACK FUNCTION RecordInputCANCEL() AS LONG
                          DIALOG END hDlg, 1
                          CALL Record1                                  '<<  error 546 HERE, want to go back to  Record1, if change to MAINMENU no error
                          END FUNCTION
                          
                          CALLBACK FUNCTION RecordInput() AS LONG
                          LOCAL result AS LONG
                          DIALOG END hDlg, 1
                          DIALOG NEW 0, "RECORD INPUT",,, 520, 200, 0, 0 TO hDlg
                          CONTROL ADD BUTTON, hDlg, 100,"XXXX",430, 10, 60, 14, 'CALL XXXX  << this would process code and end like  RecordInputCANCEL error
                          CONTROL ADD BUTTON, hDlg, 101,"&CANCEL" ,430, 30, 60, 14, CALL RecordInputCANCEL
                          CONTROL SET FOCUS   hDlg, 101
                          DIALOG SHOW MODAL  hDlg TO result
                          END FUNCTION
                          
                          CALLBACK FUNCTION RECORD1CANCEL() AS LONG
                          DIALOG END hDlg, 1
                          CALL MAINMENU
                          END FUNCTION
                          
                          CALLBACK FUNCTION Record1() AS LONG
                          SELECT CASE CBMSG            'this code would be ignored or skeped on second call
                           CASE %WM_COMMAND AND CBCTL = 100
                                 CONTROL GET TEXT hDlg, 100 TO TEXT1
                          END SELECT
                          
                          DIALOG END hDlg, 1
                          LOCAL result AS LONG
                          DIALOG NEW 0, "RECORDS1",,, 520, 200, 0, 0 TO hDlg
                          CONTROL ADD BUTTON, hDlg, 100,"RECORDS INPUT",430, 10, 80, 14, CALL RECORDINPUT
                          CONTROL ADD BUTTON, hDlg, 101,"&CANCEL" ,430, 30, 60, 14, CALL RECORD1CANCEL
                          CONTROL SET FOCUS   hDlg, 101
                          DIALOG SHOW MODAL  hDlg TO result
                          END FUNCTION
                          
                          CALLBACK FUNCTION ENDPROG()
                          DIALOG END hDlg, 1
                          DIALOG END CBHNDL, 15
                          END FUNCTION
                          
                          FUNCTION MAINMENU() AS LONG
                          DIALOG END hDlg, 1
                          LOCAL result AS LONG           '
                          DIALOG NEW 0, "Test1"  ,,,400, 270,, 0 TO hDlg
                          CONTROL ADD BUTTON,hDlg,100,"Records"    ,155, 50, 90, 14, CALL Record1
                          CONTROL ADD BUTTON,hDlg,101,"End Program",155,200, 90, 14, CALL ENDPROG
                          CONTROL SET FOCUS hDlg, 101
                          DIALOG SHOW MODAL hDlg TO result
                          END FUNCTION
                          
                          FUNCTION PBMAIN () AS LONG
                          PBMAIN=15
                          CALL MAINMENU
                          END FUNCTION
                          Robert

                          Comment


                          • #14
                            From the help file: (my bold)
                            CALLBACK
                            Specifies that this is a callback function, which is used only to receive messages from the operating system. It may never be called directly from your code. Details about the message sent to the callback are retrieved using the CB group of PowerBASIC functions. Callback functions may not include parameters, and always return a long integer result. For example:

                            CALLBACK FUNCTION DlgProc AS LONG
                            ' Callback code goes here
                            END FUNCTION

                            Callback functions have the unique ability to optionally return two distinct values when necessary for certain Windows messages. This allows them to return the value zero (0) as a function result, while still specifying that the message has been processed. See the section CALLBACK RETURN VALUE (below) and the CALLBACKS page for more details.
                            Rod
                            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                            Comment


                            • #15
                              I've quickly redone your code using PBForms, try running this to see if it does what you want, at least for the most part.

                              Code:
                              #PBFORMS CREATED V1.51
                              '------------------------------------------------------------------------------
                              ' The first line in this file is a PB/Forms metastatement.
                              ' It should ALWAYS be the first line of the file. Other
                              ' PB/Forms metastatements are placed at the beginning and
                              ' end of "Named Blocks" of code that should be edited
                              ' with PBForms only. Do not manually edit or delete these
                              ' metastatements or PB/Forms will not be able to reread
                              ' the file correctly.  See the PB/Forms documentation for
                              ' more information.
                              ' Named blocks begin like this:    #PBFORMS BEGIN ...
                              ' Named blocks end like this:      #PBFORMS END ...
                              ' Other PB/Forms metastatements such as:
                              '     #PBFORMS DECLARATIONS
                              ' are used by PB/Forms to insert additional code.
                              ' Feel free to make changes anywhere else in the file.
                              '------------------------------------------------------------------------------
                              
                              #COMPILE EXE
                              #DIM ALL
                              
                              '------------------------------------------------------------------------------
                              '   ** Includes **
                              '------------------------------------------------------------------------------
                              #PBFORMS BEGIN INCLUDES
                              #IF NOT %DEF(%WINAPI)
                                  #INCLUDE "WIN32API.INC"
                              #ENDIF
                              #PBFORMS END INCLUDES
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              '   ** Constants **
                              '------------------------------------------------------------------------------
                              #PBFORMS BEGIN CONSTANTS
                              %IDD_DIALOG1      =  101
                              %IDC_ENDPROGRAM   = 1002
                              %IDC_RECORDS      = 1001
                              %IDCANCEL         =    2
                              %IDD_DIALOG2      =  102
                              %IDC_RECORDSINPUT = 1003
                              %IDD_DIALOG3      =  103
                              %IDC_XXXX         = 1004
                              #PBFORMS END CONSTANTS
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              '   ** Main Application Entry Point **
                              '------------------------------------------------------------------------------
                              FUNCTION PBMAIN()
                                  ShowDIALOG1 %HWND_DESKTOP
                                  
                                  
                              END FUNCTION
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              '   ** CallBacks **
                              '------------------------------------------------------------------------------
                              CALLBACK FUNCTION ShowDIALOG1Proc()
                              
                                  SELECT CASE AS LONG CBMSG
                                      CASE %WM_INITDIALOG
                                          ' Initialization handler
                              
                                      CASE %WM_NCACTIVATE
                                          STATIC hWndSaveFocus AS DWORD
                                          IF ISFALSE CBWPARAM THEN
                                              ' Save control focus
                                              hWndSaveFocus = GetFocus()
                                          ELSEIF hWndSaveFocus THEN
                                              ' Restore control focus
                                              SetFocus(hWndSaveFocus)
                                              hWndSaveFocus = 0
                                          END IF
                              
                                      CASE %WM_COMMAND
                                          ' Process control notifications
                                          SELECT CASE AS LONG CBCTL
                                              CASE %IDC_RECORDS
                                                  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              '                        MSGBOX "%IDC_RECORDS=" + FORMAT$(%IDC_RECORDS), _
                              '                            %MB_TASKMODAL
                                                     ShowDIALOG2 %HWND_DESKTOP     'calls your records1
                                                  END IF
                              
                                              CASE %IDC_ENDPROGRAM
                                                  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                      MSGBOX "%IDC_ENDPROGRAM=" + FORMAT$(%IDC_ENDPROGRAM), _
                                                          %MB_TASKMODAL
                                                  END IF
                              
                                              CASE %IDCANCEL
                                                  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                      DIALOG END CBHNDL, 0
                                                  END IF
                              
                                          END SELECT
                                  END SELECT
                              END FUNCTION
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              CALLBACK FUNCTION ShowDIALOG2Proc()
                              
                                  SELECT CASE AS LONG CBMSG
                                      CASE %WM_INITDIALOG
                                          ' Initialization handler
                              
                                      CASE %WM_NCACTIVATE
                                          STATIC hWndSaveFocus AS DWORD
                                          IF ISFALSE CBWPARAM THEN
                                              ' Save control focus
                                              hWndSaveFocus = GetFocus()
                                          ELSEIF hWndSaveFocus THEN
                                              ' Restore control focus
                                              SetFocus(hWndSaveFocus)
                                              hWndSaveFocus = 0
                                          END IF
                              
                                      CASE %WM_COMMAND
                                          ' Process control notifications
                                          SELECT CASE AS LONG CBCTL
                                              CASE %IDC_RECORDSINPUT
                                                  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              '                        MSGBOX "%IDC_RECORDSINPUT=" + _
                              '                            FORMAT$(%IDC_RECORDSINPUT), %MB_TASKMODAL
                                                     ShowDIALOG3 %HWND_DESKTOP   'calls your records input
                                                  END IF
                              
                                              CASE %IDCANCEL
                                                  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                      DIALOG END CBHNDL, 0
                                                  END IF
                              
                                          END SELECT
                                  END SELECT
                              END FUNCTION
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              CALLBACK FUNCTION ShowDIALOG3Proc()
                              
                                  SELECT CASE AS LONG CBMSG
                                      CASE %WM_INITDIALOG
                                          ' Initialization handler
                              
                                      CASE %WM_NCACTIVATE
                                          STATIC hWndSaveFocus AS DWORD
                                          IF ISFALSE CBWPARAM THEN
                                              ' Save control focus
                                              hWndSaveFocus = GetFocus()
                                          ELSEIF hWndSaveFocus THEN
                                              ' Restore control focus
                                              SetFocus(hWndSaveFocus)
                                              hWndSaveFocus = 0
                                          END IF
                              
                                      CASE %WM_COMMAND
                                          ' Process control notifications
                                          SELECT CASE AS LONG CBCTL
                                              CASE %IDC_XXXX
                                                  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                      MSGBOX "%IDC_XXXX=" + FORMAT$(%IDC_XXXX), _
                                                          %MB_TASKMODAL
                                                  END IF
                              
                                              CASE %IDCANCEL
                                                  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                      DIALOG END CBHNDL, 0
                                                  END IF
                              
                                          END SELECT
                                  END SELECT
                              END FUNCTION
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              '   ** Dialogs **
                              '------------------------------------------------------------------------------
                              FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                  LOCAL lRslt AS LONG
                              
                              #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                                  LOCAL hDlg  AS DWORD
                              
                                  DIALOG NEW hParent, "Test1", 0, 0, 400, 270, %WS_POPUP OR %WS_BORDER OR _
                                      %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS _
                                      OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE _
                                      OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
                                      %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                                  CONTROL ADD BUTTON, hDlg, %IDC_RECORDS, "Records", 155, 50, 90, 14
                                  CONTROL ADD BUTTON, hDlg, %IDC_ENDPROGRAM, "End Program", 155, 200, 90, _
                                      14
                                  CONTROL ADD BUTTON, hDlg, %IDCANCEL, "EXIT", 175, 225, 50, 15
                              #PBFORMS END DIALOG
                              
                                  DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                              
                              #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                              #PBFORMS END CLEANUP
                              
                                  FUNCTION = lRslt
                              END FUNCTION
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              FUNCTION ShowDIALOG2(BYVAL hParent AS DWORD) AS LONG
                                  LOCAL lRslt AS LONG
                              
                              #PBFORMS BEGIN DIALOG %IDD_DIALOG2->->
                                  LOCAL hDlg  AS DWORD
                              
                                  DIALOG NEW hParent, "Records1", 0, 0, 520, 200, %WS_POPUP OR %WS_BORDER _
                                      OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
                                      %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                                      %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                                      OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                                  CONTROL ADD BUTTON, hDlg, %IDC_RECORDSINPUT, "Records Input", 430, 10, _
                                      80, 14
                                  CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 430, 30, 60, 14
                              #PBFORMS END DIALOG
                              
                                  DIALOG SHOW MODAL hDlg, CALL ShowDIALOG2Proc TO lRslt
                              
                              #PBFORMS BEGIN CLEANUP %IDD_DIALOG2
                              #PBFORMS END CLEANUP
                              
                                  FUNCTION = lRslt
                              END FUNCTION
                              '------------------------------------------------------------------------------
                              
                              '------------------------------------------------------------------------------
                              FUNCTION ShowDIALOG3(BYVAL hParent AS DWORD) AS LONG
                                  LOCAL lRslt AS LONG
                              
                              #PBFORMS BEGIN DIALOG %IDD_DIALOG3->->
                                  LOCAL hDlg  AS DWORD
                              
                                  DIALOG NEW hParent, "RecordInput", 0, 0, 520, 200, %WS_POPUP OR _
                                      %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
                                      %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                                      %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                                      OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                                  CONTROL ADD BUTTON, hDlg, %IDC_XXXX, "XXXX", 430, 10, 60, 14
                                  CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 430, 30, 60, 14
                              #PBFORMS END DIALOG
                              
                                  DIALOG SHOW MODAL hDlg, CALL ShowDIALOG3Proc TO lRslt
                              
                              #PBFORMS BEGIN CLEANUP %IDD_DIALOG3
                              #PBFORMS END CLEANUP
                              
                                  FUNCTION = lRslt
                              END FUNCTION
                              '------------------------------------------------------------------------------
                              Rod
                              In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                              Comment


                              • #16
                                thanks eveyone for you responses.

                                Rodney, I tested you code and it does what wanted, but I like to close dialog boxes as I open a new one, keeping only the current dialog box open.

                                I tried adding
                                FUNCTION ShowDIALOG2(BYVAL hParent AS DWORD) AS LONG
                                DIALOG END hDlg, 1 '<< my code
                                to all dialogshow functions but it did not close any dialogs.

                                You code is more advance than my simple code that I do. I could ask many question but before asking I need to study your code to better understand many parts of it.

                                I have PBforms but have not master this one yet. For now I only use it to cut and paste code from it on new dialog designs I might need.
                                Robert

                                Comment


                                • #17
                                  Rather than closing the dialog, maybe try the
                                  Code:
                                  DIALOG SHOW STATE hDlg, showstate&
                                  Rod
                                  In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                                  Comment


                                  • #18
                                    Robert, at the place the program fails you are calling a callback function.

                                    Why would you do that ?

                                    If you rem out CALL Record1

                                    Code:
                                    CALLBACK FUNCTION RecordInputCANCEL() AS LONG
                                        DIALOG END hDlg, 1
                                        'CALL Record1                                  '<<  error 546 HERE, want to go back to  Record1, if change to MAINMENU no error
                                    END FUNCTION
                                    The program seems to work with the call record1 remmed (or deleted)

                                    The only place you normally 'call' a callback function in a modal dialog (in DDT) is in the dialog show statement.
                                    But, since you have separate callbacks for each control rather than one callback for all controls; that is, of course, not necessary. I also changed GLOBAL hDlg as LONG to GLOBAL hDlg AS DWORD which has been the preferred way since ver 7.
                                    If you are still using version 6 or below then hdlg AS LONG is correct.
                                    Last edited by Fred Buffington; 26 Sep 2009, 11:01 AM.
                                    Client Writeup for the CPA

                                    buffs.proboards2.com

                                    Links Page

                                    Comment


                                    • #19
                                      Robert, in your example you are using a Callback to call another Callback -
                                      Code:
                                       
                                      [B]CallBack Function [/B]RecordInputCANCEL() As Long
                                      Dialog End hDlg, 1
                                      Call [B]Record1[/B]                                  '<<  error 546 HERE, want to go back to  Record1, if change to MAINMENU no error
                                      End Function 
                                      ...
                                      [B]CallBack Function Record1[/B]() As Long
                                      Select Case CbMsg            'this code would be ignored or skeped on second call
                                       Case %WM_COMMAND And CbCtl = 100
                                             Control Get Text hDlg, 100 To TEXT1
                                      End Select
                                      I don't think that's allowed. As Fred said if you Rem the call to Record1 it will work as it is supposed to.
                                      It's a pretty day. I hope you enjoy it.

                                      Gösta

                                      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                      Comment


                                      • #20
                                        'DIALOG SHOW STATE hDlg, showstate&' was the fix I was looking for. Below are changes made to sample test file.

                                        Fred you asked 'why I would do that'. In my programs when I open another dialog box I close the last one. I like to work on my desktop with only one dialog box and not have multiple dialog boxes which have disabled buttons or dialogs box that are disabled while filling out information on other dialog box.

                                        Only time I have two dialog boxes is when the program puts out a warning or message.

                                        Code:
                                        #COMPILE EXE
                                        #DIM ALL
                                        
                                        GLOBAL hDlg, hDlg2 AS LONG, TEXT1 AS STRING
                                        
                                        CALLBACK FUNCTION RecordInputCANCEL() AS LONG
                                        DIALOG END hDlg2, 1
                                        DIALOG SHOW STATE hDlg, %SW_RESTORE                          '<< CODE ADDED
                                        END FUNCTION
                                        
                                        CALLBACK FUNCTION RecordInput() AS LONG
                                        LOCAL result2 AS LONG
                                        DIALOG SHOW STATE hDlg, %SW_HIDE                              '<< CODE ADDED
                                        DIALOG NEW 0, "RECORD INPUT",,, 520, 200, 0, 0 TO hDlg2       '<< CODE CHANGED  hDlg2
                                        CONTROL ADD BUTTON, hDlg2, 100,"XXXX",430, 10, 60, 14, 'CALL XXXX
                                        CONTROL ADD BUTTON, hDlg2, 101,"&CANCEL" ,430, 30, 60, 14, CALL RecordInputCANCEL
                                        CONTROL SET FOCUS   hDlg2, 101
                                        DIALOG SHOW MODAL  hDlg2 TO result2
                                        END FUNCTION
                                        
                                        CALLBACK FUNCTION RECORD1CANCEL() AS LONG
                                        DIALOG END hDlg, 1
                                        CALL MAINMENU
                                        END FUNCTION
                                        
                                        CALLBACK FUNCTION Record1() AS LONG
                                        SELECT CASE CBMSG
                                         CASE %WM_COMMAND AND CBCTL = 100
                                               CONTROL GET TEXT hDlg, 100 TO TEXT1
                                        END SELECT
                                        
                                        DIALOG END hDlg, 1
                                        LOCAL result AS LONG
                                        DIALOG NEW 0, "RECORDS1",,, 520, 200, 0, 0 TO hDlg
                                        CONTROL ADD BUTTON, hDlg, 100,"RECORDS INPUT",430, 10, 80, 14, CALL RECORDINPUT
                                        CONTROL ADD BUTTON, hDlg, 101,"&CANCEL" ,430, 30, 60, 14, CALL RECORD1CANCEL
                                        CONTROL SET FOCUS   hDlg, 101
                                        DIALOG SHOW MODAL  hDlg TO result
                                        END FUNCTION
                                        
                                        CALLBACK FUNCTION ENDPROG()
                                        DIALOG END hDlg, 1
                                        DIALOG END CBHNDL, 15
                                        END FUNCTION
                                        
                                        FUNCTION MAINMENU() AS LONG
                                        DIALOG END hDlg, 1
                                        LOCAL result AS LONG           '
                                        DIALOG NEW 0, "Test1"  ,,,400, 270,, 0 TO hDlg
                                        CONTROL ADD BUTTON,hDlg,100,"Records"    ,155, 50, 90, 14, CALL Record1
                                        CONTROL ADD BUTTON,hDlg,101,"End Program",155,200, 90, 14, CALL ENDPROG
                                        CONTROL SET FOCUS hDlg, 101
                                        DIALOG SHOW MODAL hDlg TO result
                                        END FUNCTION
                                        
                                        FUNCTION PBMAIN () AS LONG
                                        PBMAIN=15
                                        CALL MAINMENU
                                        END FUNCTION
                                        Robert

                                        Comment

                                        Working...
                                        X