Send start up parameters from one program to another Program

Just starting out? Need help? Post your questions and find answers here.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Send start up parameters from one program to another Program

Post by yrreti »

I have this probably simple problem that I would appreciate some help on.
I run this first program, and then use special keys to start up this second program (a ruler program ) which I use for measuring things on my first program.
What I wanted to do, is to get and send to the second program, the first windows top Y position and left X position, so when I start up the second
program, I can use those values to adjust where to open up and place the second programs window. Otherwise I have to always reposition that second
programs window, to line it up to where I need to place it, so I can make measurements more accurately.
The frustrating part, is that I seem to remember having been able to do this in the past, but I forgot how to do it, and can't find my code. :(
I know that you can use RunProgram to start a program, and that you can pass parameters to the program your starting using it.
But what I forgot is, what does the ''program that's starting up, needs in it's code'' to be able to retrieve that parameter information in order to use it?
Thanks very much for any help, in showing me how to do this.
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Send start up parameters from one program to another Pro

Post by infratec »

The program which you start with parameters needs to know what to do with the parameters :wink:
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: Send start up parameters from one program to another Pro

Post by yrreti »

Thanks for your reply Infratec
That's precisely the point. I wrote the second program, so I know what and where I need to use those parameters.
But I need help with the code needed in order to retrieve the parameters that were sent.
I forgot how to do it ? :oops: :oops:
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Send start up parameters from one program to another Pro

Post by Marc56us »

ProgramParameter()

:wink:
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: Send start up parameters from one program to another Pro

Post by yrreti »

Thanks for your reply Marc56us
But I thought that was mainly for use with console programs, unless I am looking at it wrong?
I will try using it later as I have to leave in a few minutes.
But I distinctly remember doing a different way some time ago from help from one of those old time experts
from the past on this forum. But it was definitely a windows way and not console way.
Thanks
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: Send start up parameters from one program to another Pro

Post by BarryG »

ProgramParameter() is not just for console programs. You can use it with normal windowed apps.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Send start up parameters from one program to another Pro

Post by Marc56us »

yrreti wrote:But I thought that was mainly for use with console programs, unless I am looking at it wrong?
A quick look at help may help :wink:
https://www.purebasic.com/documentation ... meter.html

Remarks

This function is especially useful for console programs, where the user passes one or more parameter at the program start.

Note: Relying on the return of an empty string to detect the last parameter is not a good practice, since the function also returns an empty string if an empty string was passed in "" on the command-line. The prefered method which should be used to get all parameters, is to get the count with CountProgramParameters() and then to call ProgramParameter() as often as needed.
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: Send start up parameters from one program to another Pro

Post by PureLust »

If you want to communicate between programs (e.g. to send the initial Data to your measuring program and to send the results back to the main program), PIPES are a nice solution.

Because they are not included in PB and also rarely used, it's a bit fiddly to get them work.

But because I needed a high speed communication between separate programs (~6GByte/Sec), I've written a simple to use 'InterCom' Module for PB, to communicate between several programs on the same machine.

PIPES should also work over the network, so they could also be an easy way to communicate over the Network (e.g. to split workload between several machines), but I never tested this, because I had no use for it.

If you are interested in high speed interprogram communication, I could upload my 'InterCom' Module onto one of my servers if you like.

Greets, PL.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Send start up parameters from one program to another Pro

Post by RASHAD »

I hope it will suite you
Also you can run the external program inside the Main using SetParent_()

Code: Select all

Global Handle

Procedure extProg(application$ ,x,y,w,h)
  RunProgram(application$,"","",#PB_Program_Hide )
  Repeat
    Handle = FindWindow_("notepad", 0)
  Until Handle
  SetWindowPos_(Handle, 0,x ,y ,w,h, #SWP_NOZORDER)
  ShowWindow_(Handle,#SW_SHOW	)
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(0,10,370,60,24,"RUN")
  ButtonGadget(1,80,370,60,24,"CLOSE")  
  
  x = WindowX(0)+WindowWidth(0)
  y = WindowY(0)
  w = 500
  h = 500
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            extProg("notepad.exe" ,x,y,w,h)  ;Use your external programe Title
            
          Case 1
            SendMessage_(Handle,#WM_CLOSE,0,0)
        EndSelect
    EndSelect
  ForEver
EndIf
# 2:

Code: Select all

Global Handle

Procedure extProg(application$ ,x,y,w,h)
  ;SetActiveWindow(0)
  RunProgram(application$,"","",#PB_Program_Hide )
  Repeat
    Handle = FindWindow_("notepad", 0)
  Until Handle
  SetParent_(Handle, WindowID(0))
  SetWindowPos_(Handle, 0,400,0,400,600, #SWP_NOZORDER)
  ShowWindow_(Handle,#SW_SHOW	)
  Delay(10)
  SetActiveWindow(0)
EndProcedure

If OpenWindow(0, 0, 0, 800, 600, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(0,10,570,60,24,"RUN")
  ButtonGadget(1,80,570,60,24,"CLOSE")  
  
  x = WindowX(0)+WindowWidth(0)
  y = WindowY(0)
  w = 500
  h = 500
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            extProg("notepad.exe" ,x,y,w,h)  ;Use your external programe Title
            
          Case 1
            SendMessage_(Handle,#WM_CLOSE,0,0)
        EndSelect
    EndSelect
  ForEver
EndIf
Egypt my love
Post Reply