Announcement

Collapse
No announcement yet.

Making a Shelled-to program the dominant one on the desktop.

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

  • Making a Shelled-to program the dominant one on the desktop.

    Am sure that this has been discussed in detail on here but search bar is missing on my webview.

    The issue is that whenever I shell into a program, running the below lines don't always place it on the desktop as the dominant program. For example if there are other applications open on the desktop, my program is placed behind it and the user has to click the toolbar icon to get my one displayed on top.

    I've messed about with numerous switches to no avail.

    GRAPHIC WINDOW END hWin02' clear old window
    GRAPHIC WINDOW" MINDEXii - "+MODULE$,ScreenLeft,ScreenTop,1050,670 TO hWin02
    GRAPHIC ATTACH hWin02,0' make this the active window
    GRAPHIC WINDOW STABILIZE hWin02' prevent use of 'x'

  • #2
    Owen, what happens if you use SHELL in either its statement form in synchronous mode or in its function form in asynchronous mode ?
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

    Comment


    • #3
      Originally posted by Steve Hutchesson View Post
      Owen, what happens if you use SHELL in either its statement form in synchronous mode or in its function form in asynchronous mode ?
      Hi Steve,

      Am using SHELL (destprog, 3)

      No difference in asynchronous or synchronous. Have tried 0 thru 6 but none provide a maximised with focus as '3' is supposed to do.

      Comment


      • #4
        Owen,

        Give this a blast.
        Code:
            ShowWindow hWnd,%SW_HIDE
        
            var = Shell("yourapp.exe",1)
        
            ShowWindow hWnd,%SW_SHOW
        hutch at movsd dot com
        The MASM Forum

        www.masm32.com

        Comment


        • #5
          Mmmmm, doing this from the calling prog:

          DOLINE$=NEXTPROG$+" "+STR_SN$ ' str_sn$ must be passed so that NEXTPROG$ can read STR_SN$.TMP *
          LOCAL VAR AS WORD
          ShowWindow hWin02,%SW_HIDE
          VAR = SHELL(DOLINE$,1)
          ShowWindow hWin02,%SW_SHOW

          Doesn't pass the variable STR_SN$ to NEXTPROG$ and continues attempting to do so

          Comment


          • #6
            Owen,
            Your original post said:
            Am using SHELL (destprog, 3)
            Your calling program would wait for program to terminate. Is that what you want?
            Steve gave you a solution.

            ----------------------------------------------------------------------------------------------------------------------------
            New question
            Mmmmm, doing this from the calling prog:

            DOLINE$=NEXTPROG$+" "+STR_SN$ ' str_sn$ must be passed so that NEXTPROG$ can read STR_SN$.TMP *
            LOCAL VAR AS WORD
            ShowWindow hWin02,%SW_HIDE
            VAR = SHELL(DOLINE$,1)
            ShowWindow hWin02,%SW_SHOW

            Doesn't pass the variable STR_SN$ to NEXTPROG$ and continues attempting to do so
            Endless loop?

            What is the value of DoLine$
            What is the value of NextProg$
            What is the value of STR_SN$
            What is your called to program receiving in Command$ ?


            We have nothing to test. Could you supply 2 little test programs?
            Code:
            REM #DIM ALL
            
            FUNCTION PBMAIN () AS LONG
             LOCAL DoLine   AS STRING
             LOCAL NextProg AS STRING
            REM  LOCAL STR_SN$  AS STRING 'invalid string
             DOLINE=NEXTPROG+" "+STR_SN$ ' str_sn$ must be passed so that NEXTPROG$ can read STR_SN$.TMP *
            
            END FUNCTION



            We don't know what the value of sDoLine is before the shell.
            We don't know what called program is receiving in COMMAND$
            Example:
            Code:
            #DIM ALL
            
            FUNCTION PBMAIN () AS LONG
            
             LOCAL pid         AS DWORD
             LOCAL sDoLine     AS STRING
             LOCAL sNextProg   AS STRING
             LOCAL sN          AS STRING
            '
            ' set variables
            '
            
             sDoLine = sNextProg + " " + sN ' str_sn$ must be passed so that NEXTPROG$ can read STR_SN$.TMP *
             ? sDoLine
             pid = SHELL(sDoLine,3)
            
            END FUNCTION
            https://duckduckgo.com instead of google

            Comment


            • #7
              Owen,

              I just made 2 test pieces, one the caller, the other the called. From the caller I used this code to test both synchronous and asynchronous methods with SHELL.
              Code:
                      ' -----------------
                      ' Tool Bar Messages
                      ' -----------------
                        Case 50
                          Shell "called.exe I am the command line being passed"
              
                        Case 51
                          var = Shell("called.exe I am the command line being passed",1)
              The statement form of SHELL locked up the caller and started the called app which obtained the command tail with COMMAND$. The ansychronous version started the called app and the command line was obtained the same way. In both instances the called window had the focus, this is normal behaviour for Windows executables created with CreateWindowEx().

              You would have to ask some of the guys who write DDT code if its the same but I suspect that it is.
              hutch at movsd dot com
              The MASM Forum

              www.masm32.com

              Comment


              • #8
                Originally posted by Mike Doty View Post
                Owen,
                Your original post said:

                Your calling program would wait for program to terminate. Is that what you want?
                Steve gave you a solution.

                ----------------------------------------------------------------------------------------------------------------------------
                New question

                Endless loop?

                What is the value of DoLine$
                What is the value of NextProg$
                What is the value of STR_SN$
                What is your called to program receiving in Command$ ?


                We have nothing to test. Could you supply 2 little test programs?
                Code:
                REM #DIM ALL
                
                FUNCTION PBMAIN () AS LONG
                LOCAL DoLine AS STRING
                LOCAL NextProg AS STRING
                REM LOCAL STR_SN$ AS STRING 'invalid string
                DOLINE=NEXTPROG+" "+STR_SN$ ' str_sn$ must be passed so that NEXTPROG$ can read STR_SN$.TMP *
                
                END FUNCTION



                We don't know what the value of sDoLine is before the shell.
                We don't know what called program is receiving in COMMAND$
                Example:
                Code:
                #DIM ALL
                
                FUNCTION PBMAIN () AS LONG
                
                LOCAL pid AS DWORD
                LOCAL sDoLine AS STRING
                LOCAL sNextProg AS STRING
                LOCAL sN AS STRING
                '
                ' set variables
                '
                
                sDoLine = sNextProg + " " + sN ' str_sn$ must be passed so that NEXTPROG$ can read STR_SN$.TMP *
                ? sDoLine
                pid = SHELL(sDoLine,3)
                
                END FUNCTION
                Doline$ is "S:\MINDEX.SYS\MINDEX_2.EXE 628886"
                The called to program (MINDEX_2.EXE) should receive "628886" in command. If it receives nothing then it terminates.

                I'll produce two demo programs to demonstrate how it all works. The fundamental problem is that the callED program is not maximised with focus as '3' is said to do.

                Comment


                • #9
                  This is a variation on the synchronous version of SHELL.
                  Code:
                            Case 50
                              ShowWindow hWin,%SW_HIDE
                              Shell "called.exe I am the command line being passed"
                              ShowWindow hWin,%SW_SHOW
                  hutch at movsd dot com
                  The MASM Forum

                  www.masm32.com

                  Comment


                  • #10
                    Doline$ is "S:\MINDEX.SYS\MINDEX_2.EXE 628886"
                    The called to program (MINDEX_2.EXE) should receive "628886" in command. If it receives nothing then it terminates.

                    I'll produce two demo programs to demonstrate how it all works. The fundamental problem is that the callED program is not maximised with focus as '3' is said to do.
                    form1.exe shelling back and forth to form2.exe using ,3
                    It works with and without DIALOG MAXIMIZE CB.HNDL in %wm_initdialog

                    I didn't want to stack up many programs so used a DIALOG END CB.HNDL after the shell in each program.
                    A counter named gCounter is incremented and displayed in the caption of both programs.

                    pid = SHELL("FORM1.EXE " + STR$(gCounter),3) 'tested with STR$ and FORMAT$ to be sure extra space didn't cause a problem.

                    > The fundamental problem is that the callED program is not maximised with focus as '3' is said to do.
                    It sounds like you are receiving the command trailer so be sure there is no MSGBOX statement executed before displaying a dialog.

                    Maybe you can compare this to your code.

                    Code:
                     'save as form1.bas
                    %BTN_BUTTON1 = 1001
                    GLOBAL gCounter AS LONG
                    
                    FUNCTION PBMAIN()
                     gCounter = VAL(COMMAND$)
                     ShowDIALOG1 %HWND_DESKTOP
                    END FUNCTION
                    
                    CALLBACK FUNCTION ShowDIALOG1Proc()
                      SELECT CASE AS LONG CB.MSG
                        CASE %WM_INITDIALOG
                         'DIALOG MAXIMIZE CB.HNDL
                         DIALOG SET TEXT CB.HNDL,COMMAND$ + " in " + EXE.FULL$
                        CASE %WM_COMMAND
                          SELECT CASE AS LONG CB.CTL
                            CASE %BTN_BUTTON1
                              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                               LOCAL pid AS DWORD
                               INCR gCounter
                               pid = SHELL("FORM2.EXE " + STR$(gCounter),3)
                               SLEEP 250
                               DIALOG END CB.HNDL
                               FUNCTION = 1
                              END IF
                          END SELECT
                      END SELECT
                    END FUNCTION
                    
                    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                      LOCAL lRslt AS LONG
                      LOCAL hDlg  AS DWORD
                    
                      DIALOG NEW PIXELS, hParent, EXE.NAME$, 794, 451, 400, 400, _
                        %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
                        %DS_SETFONT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR _
                        OR %WS_EX_CONTROLPARENT, TO hDlg
                      CONTROL ADD BUTTON, hDlg, %BTN_BUTTON1, "SHELL FORM2", 8, 8, 85, 24
                    
                      DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                      FUNCTION = lRslt
                    END FUNCTION'
                    Code:
                    'save as form2.bas
                    %BTN_BUTTON1 = 1001
                    GLOBAL gCounter AS LONG
                    
                    FUNCTION PBMAIN()
                     gCounter = VAL(COMMAND$)
                     ShowDIALOG1 %HWND_DESKTOP
                    END FUNCTION
                    
                    CALLBACK FUNCTION ShowDIALOG1Proc()
                      SELECT CASE AS LONG CB.MSG
                        CASE %WM_INITDIALOG
                         'DIALOG MAXIMIZE CB.HNDL
                         DIALOG SET TEXT CB.HNDL,COMMAND$ + " in " + EXE.FULL$
                        CASE %WM_COMMAND
                          SELECT CASE AS LONG CB.CTL
                            CASE %BTN_BUTTON1
                              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                               LOCAL pid AS DWORD
                               INCR gCounter
                               pid = SHELL("FORM1.EXE " + STR$(gCounter),3)
                               SLEEP 250
                               DIALOG END CB.HNDL
                               FUNCTION = 1
                              END IF
                          END SELECT
                      END SELECT
                    END FUNCTION
                    
                    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                      LOCAL lRslt AS LONG
                      LOCAL hDlg  AS DWORD
                    
                      DIALOG NEW PIXELS, hParent, EXE.NAME$, 794, 451, 400,400, _
                        %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
                        %DS_SETFONT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR _
                        OR %WS_EX_CONTROLPARENT, TO hDlg
                      CONTROL ADD BUTTON, hDlg, %BTN_BUTTON1, "SHELL FORM1", 8, 8, 85, 24
                    
                      DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                      FUNCTION = lRslt
                    END FUNCTION'
                    https://duckduckgo.com instead of google

                    Comment


                    • #11
                      This worked on my test piece, passes a command line AND maximizes the called window.
                      Code:
                                  var = Shell("called.exe I am the command line being passed",1)
                                  SleepEx 500,0
                                  hAtv = GetForegroundWindow()
                                  ShowWindow hAtv,%SW_MAXIMIZE
                      Note that it must have the delay so that the called window is up and running.
                      hutch at movsd dot com
                      The MASM Forum

                      www.masm32.com

                      Comment


                      • #12
                        Here is a better version that reduces the lag. The "hWnd" is the calling app's handle.
                        Code:
                                  Case 51
                                    var = Shell("called.exe I am the command line being passed",1)
                                    While GetForegroundWindow() = hWnd
                                      SleepEx 10,0
                                    Wend
                                    hAtv = GetForegroundWindow()
                                    ShowWindow hAtv,%SW_MAXIMIZE
                        hutch at movsd dot com
                        The MASM Forum

                        www.masm32.com

                        Comment

                        Working...
                        X