PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 2024 → Starting another program
Starting another program
Iniciado por Bart Van der Elst, nov., 07 2005 9:59 AM - 2 respostas
Publicado em novembro, 07 2005 - 9:59 AM
Hello,
I'm using Windev 8.
I have 2 WinDev programs, let's say program1 and program2.
In program1 I have a button, from wich I want to launch program2.
First I check if program2 is already running or not with the ExeRunning function.
If not, I launch program2 with the ExeRun function. No problem, but
When program2 is already running, I just want to set the focus to program2. How can I do this ?
Thanks in advance,
Bart
Publicado em novembro, 07 2005 - 4:20 PM
In Delphi, I would have to use API's to get the handle of the main window of the other program and then set the focus to that window. I just looked it up in the windev 8 manual and I can't believe how easy they've made it!!!

This is what I copied from the help:

HandleRes = SysWinHandle("Microsoft Word - 2000 Sales.DOC")
FocusRes = SysSetFocus (HandleRes)

Hope this helps... I haven't tested it, but it's the same working principle I use in Delphi and other languages.

Cheers!
ken
Publicado em novembro, 07 2005 - 9:25 PM
Hi,
I have 2 WinDev programs, let's say program1 and program2.
In program1 I have a button, from wich I want to launch program2.
First I check if program2 is already running or not with the ExeRunning function.
If not, I launch program2 with the ExeRun function. No problem, but
When program2 is already running, I just want to set the focus to program2. How can I do this ?

If you know the title of the main window of program2 then something like:
-----------------------
Hwnd is int
Hwnd=SysWinHandle("Progname2Title")
IF Hwnd THEN
SysWinActive(Hwnd)
SysWinShow (Hwnd, swsNormal)
END
-----------------
If you don't know the title then its a little more work
-----------------------
Hwnd, HwndParent are int
ProcID is int; GW_HWNDNEXT is int
sExe is string="C:\MyProgram2.exe"
GW_HWNDNEXT = 2
IF NOT ExeRunning(sExe) THEN
pID=ExeRun(sExe,exeActive,exePID)
ELSE
Hwnd=API("USER32","FindWindowA",Null,Null)
WHILE Hwnd<>0
HwndParent=API("USER32","GetParent",Hwnd)
IF HwndParent=0 THEN
API("USER32", "GetWindowThreadProcessId", Hwnd, &ProcID)
IF pID=ProcID THEN
SysWinActive(Hwnd)
SysWinShow (Hwnd, swsNormal)
BREAK
END
END
Hwnd=API("USER32","GetWindow", Hwnd, GW_HWNDNEXT)
END
END
-----------------
--
Peter