[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to close dialogs open on main form - *from* the main form

Posted on 2005-04-26
1
Medium Priority
?
250 Views
Last Modified: 2010-04-05
I have searched EE and have not found a suitable solution. I have also googled with no luck yet.

When my application receives a certain wm_Timer message,
I want to close all the dialogs over the main form of my application
Important: There may be 2 levels of dialogs (e.g. dialog1 which has an opendialog showing).
The solution needs to be abstract, I will _not_ have variable names (fdialog1) nor classnames (tfdialog1) to use

I already have the wm_timer part

private
    procedure WMTimer( var Msg : TMessage ); message wm_timer;
...
procedure TForm1.WMTimer(var Msg: TMessage);
    begin
        if msg.wParam = 101 then
        begin
// close modal dialog boxes here
        end;
    end;
0
Comment
Question by:TheRealLoki
1 Comment
 
LVL 26

Accepted Solution

by:
Russell Libby earned 750 total points
ID: 13871410
This following code should do as requested, just call it in your routine:

eg:
    if msg.wParam = 101 then
        begin
           // close modal dialog boxes here
           CloseModalWindows(Form1);
        end;

Regards,
Russell


function CloseModalWindowsProc(Handle: HWND; Param: HWND): BOOL; stdcall;
begin
  // Don't touch the application handle
  if (Handle <> Application.Handle) then
  begin
     // Check the owner window handle
     if (GetWindow(Handle, GW_OWNER) = Application.Handle) then
     begin
        // Don't close the caller window
        if (Handle <> Param) then SendMessage(Handle, WM_CLOSE, 0, 0);
     end;
  end;
  // Keep going
  result:=True;
end;

procedure CloseModalWindows(Caller: TForm);
begin
  EnumWindows(@CloseModalWindowsProc, Caller.Handle);
end;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 10 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question