Page 1 of 1
Send start up parameters from one program to another Program
Posted: Thu Nov 05, 2020 9:01 pm
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.
Re: Send start up parameters from one program to another Pro
Posted: Thu Nov 05, 2020 9:06 pm
by infratec
The program which you start with parameters needs to know what to do with the parameters

Re: Send start up parameters from one program to another Pro
Posted: Thu Nov 05, 2020 9:12 pm
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 ?

Re: Send start up parameters from one program to another Pro
Posted: Thu Nov 05, 2020 9:21 pm
by Marc56us
ProgramParameter()

Re: Send start up parameters from one program to another Pro
Posted: Thu Nov 05, 2020 9:32 pm
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
Re: Send start up parameters from one program to another Pro
Posted: Thu Nov 05, 2020 9:42 pm
by BarryG
ProgramParameter() is not just for console programs. You can use it with normal windowed apps.
Re: Send start up parameters from one program to another Pro
Posted: Fri Nov 06, 2020 7:15 am
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
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.
Re: Send start up parameters from one program to another Pro
Posted: Wed Nov 11, 2020 10:32 pm
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.
Re: Send start up parameters from one program to another Pro
Posted: Thu Nov 12, 2020 3:19 am
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