How to programmatically close all previously opened windows?

This forum is for eXpress++ general support.
Message
Author
User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: How to programmatically close all previously opened wind

#11 Post by Auge_Ohr »

Eugene Lutsenko wrote:How to use PostAppevent() to force the closure of the previously open Windows from outside (like from task Manager) in the menu, like this, like me?
Taskmanager can close Apps not Windows :!:
Xbase++ Windows only appear when set o:Tastlist := .T. which is the Main (Top-) Window

Code: Select all

PostAppevent(xbeP_Close,,, oWindow)
you must have open Windows Object ("oWindow") to send Event to and your Code must react on it.
be careful not to close a Windows when Work is in progress ...
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to programmatically close all previously opened wind

#12 Post by rdonnay »

How to use PostAppevent() to force the closure of the previously open Windows from outside (like from task Manager) in the menu, like this, like me?
You can close separate applications from outside.
Look at \exp20\samples\taskkill

You can close all windows from another application by writing to the registry and then reading the registry in another thread.
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to programmatically close all previously opened wind

#13 Post by Eugene Lutsenko »

rdonnay wrote:
How to use PostAppevent() to force the closure of the previously open Windows from outside (like from task Manager) in the menu, like this, like me?
You can close separate applications from outside.
Look at \exp20\samples\taskkill

You can close all windows from another application by writing to the registry and then reading the registry in another thread.
Hey, Roger!

Apparently it is very similar to the solution of the problem. But that in itself is a problem for me. The thing is, I don't have a folder like that at all along the way. I guess I have some outdated version of the Express. I have only c:\exp20\Samples\TASKLIST and then there is already: c:\exp20\Samples\Threads.

Maybe I can use the DOS command: https://www.computerhope.com/taskkill.htm? To do this, I need to programmatically know the name of the thread with the window open before running the next window.

And it is better to upgrade to Express...

And in xdemo.exe no such example?

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to programmatically close all previously opened wind

#14 Post by Eugene Lutsenko »

Auge_Ohr wrote:be careful not to close a Windows when Work is in progress ...
I understand this, so I gave users the appropriate messages. But usually nothing else is done in other Windows when a new one opens. They just hang on the screen and you have to close them all at once. Interrupting processes in the task Manager also never led to undesirable consequences

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to programmatically close all previously opened wind

#15 Post by rdonnay »

Here is a program that allows you to view and kill running tasks.

It will not kill individual windows within an Xbase++ program.

BTW - Are your dialog windows running in separate threads?
Attachments
tasks.zip
(1.56 KiB) Downloaded 706 times
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to programmatically close all previously opened wind

#16 Post by Eugene Lutsenko »

Thank You, Roger! It won't just be me using it... Entry point not found. Procedure entry point not found in library
Attachments
Безымянный.jpg
Безымянный.jpg (23.08 KiB) Viewed 11747 times

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to programmatically close all previously opened wind

#17 Post by rdonnay »

Code: Select all

// This function loads a CSV file into an array

FUNCTION DC_CSV2Array( cCsvFileName )

LOCAL nHandle, cLine, aTokens, aCSV[0]

nHandle := DC_TxtOpen( cCsvFileName )

IF  nHandle <= 0
  RETURN {}
ENDIF

DO WHILE !DC_TxtEof(nHandle)
  cLine := DC_TxtLine(nHandle,Chr(10))
  aTokens := DC_TokenArray(cLine,',',.t.)
  AAdd( aCSV, aTokens )
  DC_TxtSkip(nHandle,1,Chr(10))
ENDDO

DC_TxtClose( nHandle )

RETURN aCSV
The eXpress train is coming - and it has more cars.

Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: How to programmatically close all previously opened wind

#18 Post by Victorio »

Eugene,

You want close windows mean close other external applications ?
If yes, I used this system (can post source but tomorrow, because need "extract" it from more source files)

I run tasks, and save program list to text CSV file,

Code: Select all

RunShell('/C TaskList.Exe /V /FO CSV > tasklist.csv',,.T.,.T.)
aTasks := DC_Csv2Array('tasklist.csv')
and read to arr
and with modify

Code: Select all

ARemove( aTasks,1 )

aHeader:={"Image Name","PID","Session Name","Session#","Mem Usage","Status","User Name","CPU Time","Window Title"}
aWidths := Array(Len(aTasks[1]))
AFill(aWidths,10)
aWidths[1] := 25
aWidths[2] := 5
aWidths[3] := 5
aWidths[4] := 6
aWidths[9] := 40



note ! I had problem with header on France localisation Windows 10, then need use "own" header because some umlauts was problem when read CSV

then search if some of programs for example Acrord.exe is running
when found, taskkill him.

Code: Select all

RunShell('/F /IM ' + "mview.exe",'C:\windows\system32\TaskKill.Exe',.t.,.f.)
When some problems on 64bit windows, can use NIRCMD utility, which are 32 and also 64 bit.

Maybe something as this can help you.

Viktor

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to programmatically close all previously opened wind

#19 Post by Eugene Lutsenko »

rdonnay wrote:

Code: Select all

// This function loads a CSV file into an array

FUNCTION DC_CSV2Array( cCsvFileName )

LOCAL nHandle, cLine, aTokens, aCSV[0]

nHandle := DC_TxtOpen( cCsvFileName )

IF  nHandle <= 0
  RETURN {}
ENDIF

DO WHILE !DC_TxtEof(nHandle)
  cLine := DC_TxtLine(nHandle,Chr(10))
  aTokens := DC_TokenArray(cLine,',',.t.)
  AAdd( aCSV, aTokens )
  DC_TxtSkip(nHandle,1,Chr(10))
ENDDO

DC_TxtClose( nHandle )

RETURN aCSV
[/size]
Thanks Roger! Now your example works. But how can I use this to close previously opened Windows menus on startup from the same new feature menu?

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to programmatically close all previously opened wind

#20 Post by Eugene Lutsenko »

Victorio wrote:Eugene,

You want close windows mean close other external applications ?
If yes, I used this system (can post source but tomorrow, because need "extract" it from more source files)

I run tasks, and save program list to text CSV file,

Code: Select all

RunShell('/C TaskList.Exe /V /FO CSV > tasklist.csv',,.T.,.T.)
aTasks := DC_Csv2Array('tasklist.csv')
and read to arr
and with modify

Code: Select all

ARemove( aTasks,1 )

aHeader:={"Image Name","PID","Session Name","Session#","Mem Usage","Status","User Name","CPU Time","Window Title"}
aWidths := Array(Len(aTasks[1]))
AFill(aWidths,10)
aWidths[1] := 25
aWidths[2] := 5
aWidths[3] := 5
aWidths[4] := 6
aWidths[9] := 40



note ! I had problem with header on France localisation Windows 10, then need use "own" header because some umlauts was problem when read CSV

then search if some of programs for example Acrord.exe is running
when found, taskkill him.

Code: Select all

RunShell('/F /IM ' + "mview.exe",'C:\windows\system32\TaskKill.Exe',.t.,.f.)
When some problems on 64bit windows, can use NIRCMD utility, which are 32 and also 64 bit.

Maybe something as this can help you.

Viktor
Thank You, Victor! The information you provided is helpful. But that's not what I'm trying to understand. I am trying to force close previously opened from menu (given above in this topic) windows when launching from it new windows.

Post Reply