Mega Code Archive

 
Categories / Delphi / Forms
 

AskProgramToClose

Title: AskProgramToClose Question: This procedure was created to find a window and send it a message to close, if it had changes made to it then it would popup a dialog box asking the user to confirm that they wanted to close if so then it would detect that it has an owned popupwindow show it then set the Foreground Window to the parent window. Answer: procedure AskProgramToClose(ClassName : string; WindowTitle : string); var ProcessHandle : THandle; ProcessID: Integer; TheWindow : HWND; ClosedApplication : boolean; begin TheWindow := FindWindow(ClassName, WindowTitle); GetWindowThreadProcessID(TheWindow, @ProcessID); ClosedApplication := false; ClosedApplication := PostMessage(FindWindow(ClassName, WindowTitle),WM_CLOSE, 4, 0); if (AnyPopup) then begin ShowOwnedPopups(TheWindow,True); SetForegroundWindow(TheWindow); end; end;