PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Close by Handle
Close by Handle
Débuté par Rik, 24 juin 2017 12:54 - 7 réponses
Posté le 24 juin 2017 - 12:54
Hello all,

Is there an alternative to the close() function where I can use the Handle() of a window?
In the Windev help I can only find the close() function which is only compatible by the window name.

I would like to create something like this:
id is system int = Handle(CurrentWindow()) "Close the window" Close(id)
Or is there some function which translates the Handle to window name?

Best Regards,
Rik
Posté le 24 juin 2017 - 15:38
Maybe its easier if I give the idea behind this problem.
I would like to close all windows which are open from upon a certain point in time (in my case the first window).

I already wrote the first part of the code looking like this. If I can find the solution others can use this code too if they like.
Project initilisation code:
EXTERN "WinConst.WL" EXTERN "KeyConst.WL" arrGeopendeWindows is dynamic array of system int gnVorigeWindow is system int = 0 Event(GprSluitVensters,"*.*",WM_KEYDOWN) Event(GprSluitVensters,"*.*",WM_SYSKEYDOWN) Event(GprLinkerMuisknopHandle,"*.*",WM_LBUTTONDOWN) Event(GprLinkerMuisknopHandle,"*.*",WM_CLOSE)
The first of two global procedures:
PROCEDURE GprLinkerMuisKnop() ThreadPause(50) id is system int = Handle(CurrentWin()) //SysGetDC(SysWinActive()) IF NOT id = gnVorigeWindow THEN IF ArraySeek(arrGeopendeWindows,asLinear,id) = -1 THEN ArrayAdd(arrGeopendeWindows,id) ELSE ArrayDelete(arrGeopendeWindows,ArrayCount(arrGeopendeWindows)) END END gnVorigeWindow = id
The not working global procedure because it does not work with Handle:
PROCEDURE GprSluitVensters() IF KeyPressed(VK_F10,False) THEN aantal is int = ArrayCount(arrGeopendeWindows) IF aantal < 2 THEN RETURN END FOR i = 2 TO aantal Close(arrGeopendeWindows[aantal-i+2]) END END
Regards,
Rik
Posté le 24 juin 2017 - 20:51
Hi

I would post a message with wparam set to INT-handle.

Then in the event-code of each window if would have something like

Event(CloseW,"*.*","CLOSEWINDOW") //Somwhere in code Postmessage(MainWinHandle,"CLOSEWINDOW",nHandleToClose,0) // Procedure CloseW(imsg,WParam,Lparam) if handle(mywindow) = wparam close() end
You could also check out EXEPid, SysWinTitle etc. or use the API DestroyWindow from M$.

Cheers
Tor-Bjarne
Posté le 27 juin 2017 - 12:06
Hey Tor-Bjarne,

Thank you for your quick response.

I really like the idea but. Your solution requires code in every window, would there be someway to keep the global?
What I mean is not having any code in subsequent windows, but only in the project code.

Best regards,
Rik
Posté le 27 juin 2017 - 12:59
Hi Rik,

You could build a global array containing handle and Windowsname.
Then seek on Handle and use WinClose(Windowsname)

Cheers
Tor-Bjarne
Posté le 27 juin 2017 - 13:27
Hi Rik

you can have a look in WXEDM. In order to be able to do something similar, I'm using only wlanguage (no api or anything system).

The principle is:
- I created global procedures overwriting the openxxx functions. They save information about the windows in a global array
- I also overwrote the close function to remove stuff from the aray
- And of course, because I know the name/alais of each open window, I can do global stuff (display all the windows in an horizontal looper/menu), close all open windows, etc...

the good thing is that it's already coded and working.

Best regards
Posté le 29 juin 2017 - 11:01
Hello Tor-Bjarne and Fabrice,

Thank you for your responses!

@Fabrice: I am unable to take a look at WXEDM because your site gives an error at the moment, something about your disk space being full.

@Tor-Bjarne: I tried the dynamic two dimensional array, which works great. But it just closes one window at the time.

If I put the Close function directly in the FOR-Loop it will just stop after 1 iteration.
If I put the Close function in a seperate function which will be ThreadExecuted every loop, the thread will only run once for some reason...

Probably WXEDMs rewritten close function will do the trick.

Regards,
Rik
Posté le 29 juin 2017 - 15:49
Hi Rik

sorry about that

the backup system is NOT cooperating :-(

Website is up and running again