TApplication 在打開模態 TForm 時觸發事件 OnModalBegin。
有沒有辦法在非模態 TForm 以相同的方式顯示/打開 TApplication.OnModalBegin 時得到通知?
uj5u.com熱心網友回復:
您可以捕獲一些訊息,這些訊息TApplicationEvents可以幫助您檢測何時創建/顯示新表單。
OnMessage在組件事件上使用此代碼TApplicationEvents。
procedure TFormMain.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
f:TCustomForm;
function GetFormByHandle(const AHandle:Hwnd):TCustomForm;
var
i:Integer;
begin
Result := nil;
for i := 0 to (Screen.FormCount - 1) do
if (Screen.Forms[i].Handle = AHandle) then
Result := Screen.Forms[i];
end;
begin
if (Msg.message = WM_DWMNCRENDERINGCHANGED) then begin // detect new form
f := GetFormByHandle(Msg.hwnd); // Search on Scren by handle
if Assigned(f) then
Memo1.Lines.Add(' Name:' f.Name ' - Handle: ' IntToStr(Msg.hwnd) ' - Classname: ' f.ClassName); /7 show info
end;
end;
創建新表單時,您可以使用句柄(帶有訊息引數)獲取他的資訊并詢問Screen物件(創建單例)。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/444769.html
