The orphan dialog box

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
G.Grigioni

The orphan dialog box

Post by G.Grigioni » 27 Feb 2008, 18:25

 Posted by:  G.Grigioni 

I've to list all the children of a MDI and I tried using the SAL
functions SalGetFirstChild(hWndMDI,TYPE_Any) +
SalGetNextChild(hChild,TYPE_Any).

It work well with Form Window but it dont show the Dialog Boxes opened
with the function SalModalDialog( dlg, hWndMDI ).

The strange thing is that calling SalParentWindow( hWndForm ) in the
Dialog Box, it returns the correct parent value.

(Source sample attached, TD 3.0)

What's wrong in the code?

Thank you
You do not have the required permissions to view the files attached to this post.

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2370
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: The orphan dialog box

Post by Jeff Luther » 27 Feb 2008, 18:55

 Posted by:  Jeff Luther 

The problem, GG, is confusing 'parent/child' with 'owner' objects. it's
the children (those listed in the Contents section) that are found with
SalGetFirst/NextChild functions, since the relationship is like:

Parent
|
child1 -> child2 -> child3 -> hWndNULL [ie, no next child]

SalParentWindow() works for you because, as TD's help says:
"hWndParent is the parent window handle of hWnd. If hWnd is a top-level
window [which your dlg box is], hWndParent is the window handle of the
*owner* window, as passed [in the 2nd parameter] to SalCreateWindow [or
SalModalDialog]"

I added the "[]" and "*" remarks. SalParentWindow is thus a bit of a
misnomer: It returns the 'parent' handle if the object handle passed is
a child of that parrent; otherwise, the function will return the 'owner'
handle, but... the exception being a call like:

SalModalDialog( dlgFoo, hWndNULL )

means dlgFoo has no owner, so SalParentWindow( dlgFoo ) would return
hWndNULL.

In the case of your sample, dlg1 is modal anyway, so control can't pass
back to the MDI before the user closed the dlg, usually via a pb's call
to SalEndDialog().

Now... if you want to find an open (ie, created) window, I have a little
sample to do just that with Notepad. The code's in v4 so you would need
to back-convert to your v3 with my TD-Convert utility. Click on the link
below and click on "Utilities." That could would allow you to find your
dlg1.

And if you want an analog to get first/next for children--and are
creating either forms or modeless dlg boxes--one solution would be to
keep your own array of windows by catching and managing a list of the
hWnd returns of your SalCreateWindow() calls.

Best Regards,
Jeff @ PC Design
info. & samples: www.JeffLuther.net/unify/

You do not have the required permissions to view the files attached to this post.

G.Grigioni

Re: The orphan dialog box

Post by G.Grigioni » 27 Feb 2008, 19:30

 Posted by:  G.Grigioni 

Jeff Luther ha scritto:

Thank you JL for your excellent and quick reply!

I'll add more informations about my problem.
I'm building a simple screen saver for my TD applications: after a fixed
idle time, a PM_ScreenSaver is sent to the MDI window. The MDI has to
hide all the opened forms and dialog boxes, then prompt the user for a
new re-login dialog box. The SalGet..Child f()s work well with form and
table windows, doesn't work with modal dialog boxes, as said.

Your code is interesting and I'm looking at your sample trying to modify
it for my application. Not easy for me but I'm trying...

This could be a simpler solution: a couple of class functions that keep
track of the handles of the opened dialog boxes.

G.Grigioni

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2370
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: The orphan dialog box

Post by Jeff Luther » 27 Feb 2008, 20:50

 Posted by:  Jeff Luther 

First, realize that you can only be talking about any window you create
with SalCreateWindow(). For SalModalDialog() calls, those dlgs. are
modal, so the user has to close one before coming back to your appl.
That's how modal dlgs. work.

"track of the handles of the opened dialog boxes" - again, those can be
modeless dlgs. only. And a class to handle them, send them a user-def.
(perhaps) PM_HideShowYourself msg. with wParam either TRUE or FALSE sent
to all those opened windows, where the msg. does call SalHideWindow or
SalShowWindow() depending on wParam value, would likely do the trick.

- Jeff

Jim McNamara

Re: The orphan dialog box

Post by Jim McNamara » 27 Feb 2008, 22:30

 Posted by:  Jim McNamara 

Rather than hide everything, why not just quit the app?

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3393
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: The orphan dialog box

Post by Dave Rabelink » 28 Feb 2008, 09:53

I have made a sample application which hopefully does what you need.

Download the sample from here :
https://samples.tdcommunity.net/index.ph ... rch_mode=f

It uses the WinAPI functions EnumThreadWindows and EnumChildWindows
to enumerate all current opened Top Level Windows in the current
running application.
It finds MDI, MDI form/table, modeless/modal dialogs, independent of
parent/child relationships.

The sample shows a MDI, some MDI childs and modal/modeless dialogs.
A timer is set to 5 seconds which will hide all opened windows and
present a Relogin dialog. When this dialog is closed the hidden
windows will be shown again. This is repeated until you close the
application. So when you start the application, just wait 5 secs !

The sample uses CallBack DLL by Christian Schubert. It is needed,
because the Enum API functions need callback functions.
I created the sample in TD1.5, but I added all the other DLL TD
versions for your convenience. First change the DLL name in
Callback.apl to the correct TD version you are using. It should work
in all TD versions (except TD51, you should change some code to get it
to work due to classname changes). For the original CallBack archive
and info go to Christian Schubert website :
http://www.cschubert.net/html/callback.html

I hope you find this usable.

regards,

Dave

G.Grigioni

Re: The orphan dialog box

Post by G.Grigioni » 28 Feb 2008, 10:26

 Posted by:  G.Grigioni 

Jeff Luther ha scritto:

You can have more than one modal dialog box opened at the same time:

mdi calls SalModalDlg( dlg1, hWndMDI)
dlg1 calls SalModalDlg( dlg2, hWndForm)
dlg2 calls ....

G.Grigioni

Re: The orphan dialog box

Post by G.Grigioni » 28 Feb 2008, 10:31

 Posted by:  G.Grigioni 

Thank you all for the sources and the useful hints.

Alexander Traxler

Re: The orphan dialog box

Post by Alexander Traxler » 28 Feb 2008, 15:52

 Posted by:  Alexander Traxler 

Hi!

As I understand your request, you want to get the handles of all open
windows of your application, right?

Maybe here's a quite simple idea:
I assume, you're working with classes for your windows (form and dialog).
So why not sending a message (with hWnd as lParam) to the MDI on
SAM_Create/SAM_Destroy.
This message then un-/registers the received hWnd to a hWnd-array kept in
den MDI.
That should give you all the hWnds, that are open at any time ...

Hope this helps ...
Cheers,
Alex :o)

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests