Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
8
Erster Beitrag:
vor 11 Monaten
Letzter Beitrag:
vor 10 Monaten, 4 Wochen
Beteiligte Autoren:
Rik, Fabrice Harari, Tor-Bjarne

Close by Handle

Startbeitrag von Rik am 24.06.2017 10: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

Antworten:

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 two global procedures:

PROCEDURE GprLinkerMuisknopHandle()
teller is int = 0
WHILE NOT ThreadState("LinkermuisknopThread"+teller) = threadUnknown
teller++
END
ThreadExecute("LinkermuisknopThread"+teller,threadNormal,GprLinkerMuisKnop)


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

von Rik - am 24.06.2017 13:38
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)

//Thisprocedure resides in each sub-window
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

von Tor-Bjarne - am 24.06.2017 18:51
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

von Rik - am 27.06.2017 10:06
Hi Rik,

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

Cheers
Tor-Bjarne

von Tor-Bjarne - am 27.06.2017 10:59
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

von Fabrice Harari - am 27.06.2017 11:27
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

von Rik - am 29.06.2017 09:01
Hi Rik

sorry about that

the backup system is NOT cooperating :-(

Website is up and running again

von Fabrice Harari - am 29.06.2017 13:49
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.