怎样建立模式子窗体 ( 积分: 100 )

  • 主题发起人 主题发起人 fclouds
  • 开始时间 开始时间
F

fclouds

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样建立模式子窗体
 
怎样建立模式子窗体
 
if not Assigned(frmMainForm) then
frmMainForm := TfrmMainForm.Create(Self);
frmMainForm.Show;
 

谢谢 我说的是 模式窗体
 
模式窗体和非模式窗体没什么区别的,只是用ShowModal显示
 
uses forms
function TCustomForm.ShowModal: Integer;
var
WindowList: Pointer;
SaveFocusCount: Integer;
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;
Include(FFormState, fsModal);
ActiveWindow := GetActiveWindow;
SaveFocusCount := FocusCount;
Screen.FSaveFocusedList.Insert(0, Screen.FFocusedForm);
Screen.FFocusedForm := Self;
SaveCursor := Screen.Cursor;
Screen.Cursor := crDefault;
SaveCount := Screen.FCursorCount;
WindowList := DisableTaskWindows(0);
try
Show;
try
SendMessage(Handle, CM_ACTIVATE, 0, 0);
ModalResult := 0;
repeat
Application.HandleMessage;
if Application.FTerminate 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.FCursorCount = SaveCount then
Screen.Cursor := SaveCursor
else
Screen.Cursor := crDefault;
EnableTaskWindows(WindowList);
if Screen.FSaveFocusedList.Count >
0 then
begin
Screen.FFocusedForm := Screen.FSaveFocusedList.First;
Screen.FSaveFocusedList.Remove(Screen.FFocusedForm);
end else
Screen.FFocusedForm := nil;
if ActiveWindow <>
0 then
SetActiveWindow(ActiveWindow);
FocusCount := SaveFocusCount;
Exclude(FFormState, fsModal);
end;
end;
 
1.模式窗体 :打开一个窗体后,用户无法与应用程序的其它部分交互,知道用户关闭了这个窗体才可,这样的是模式窗体。大多数情况下应该使用模式窗体。显示一个模式窗体用ShowModal();
2.无模式窗体:打开一个窗体后,可以在这个窗体和其它窗体间切换,这样的窗体是无模式窗体。打开它,用Show()。
二者的区别是用户能否在打开的窗体与其他窗体之间切换.
 
var
MyForm:TfrmMainForm;
begin
MyForm := TfrmMainForm.Create(Self);
MyForm.ShowModal;
end;
 
Form2.ShowModal;
 
接受答案了.
 
后退
顶部