1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| Unit fmLoadWait;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, Consts;
Type
TLoadWait = Class(TForm)
pbLoad: TProgressBar;
Label1: TLabel;
Public
Function ShowModal(OnShowModal: TNotifyEvent): Integer; Overload;
End;
Var
LoadWait: TLoadWait;
Implementation
{$R *.dfm}
Function TLoadWait.ShowModal(OnShowModal: TNotifyEvent): Integer;
Var
WindowList: Pointer;
SaveFocusState: TFocusState;
SaveCursor: TCursor;
SaveCount: Integer;
ActiveWindow: HWnd;
Begin
CancelDrag;
If Visible Or Not Enabled Or (fsModal In FFormState) Or
(FormStyle = fsMDIChild) Then
Raise EInvalidOperation.Create(SCannotShowModal);
If GetCapture <> 0 Then
SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
ReleaseCapture;
Application.ModalStarted;
Try
Include(FFormState, fsModal);
If (PopupMode = pmNone) And (Application.ModalPopupMode <> pmNone) Then
Begin
RecreateWnd;
HandleNeeded;
End;
ActiveWindow := GetActiveWindow;
SaveFocusState := Forms.SaveFocusState;
Screen.SaveFocusedList.Insert(0, Screen.FocusedForm);
Screen.FocusedForm := Self;
SaveCursor := Screen.Cursor;
Screen.Cursor := crDefault;
SaveCount := Screen.CursorCount;
WindowList := DisableTaskWindows(0);
Try
Show;
Try
SendMessage(Handle, CM_ACTIVATE, 0, 0);
ModalResult := 0;
//--------------------------------------------------------------
If Assigned(OnShowModal) Then
OnShowModal(nil);
//--------------------------------------------------------------
Repeat
Application.HandleMessage;
If Application.Terminated Then
ModalResult := mrCancel
Else
If ModalResult <> 0 Then
CloseModal;
Until ModalResult <> 0;
Result := ModalResult;
SendMessage(Handle, CM_DEACTIVATE, 0, 0);
If GetActiveWindow <> Handle Then
ActiveWindow := 0;
Finally
Hide;
End;
Finally
If Screen.CursorCount = SaveCount Then
Screen.Cursor := SaveCursor
Else
Screen.Cursor := crDefault;
EnableTaskWindows(WindowList);
If Screen.SaveFocusedList.Count > 0 Then
Begin
Screen.FocusedForm := Screen.SaveFocusedList.First;
Screen.SaveFocusedList.Remove(Screen.FocusedForm);
End Else
Screen.FocusedForm := nil;
If ActiveWindow <> 0 Then
SetActiveWindow(ActiveWindow);
RestoreFocusState(SaveFocusState);
Exclude(FFormState, fsModal);
End;
Finally
Application.ModalFinished;
End;
End;
End. |
Partager