如何判断有Modal窗体? |
尚未結案
|
mustapha.wang
資深會員 發表:89 回覆:409 積分:274 註冊:2002-03-13 發送簡訊給我 |
因为用TrayIcon元件,它没有写好。如果在有ShowModal出来的Form或Windows.MessageBox出来的window,TrayIcon的popupmenu还是能弹出来,这样就会有麻烦:可能弹出多个About
procedure TKsCoolTrayIcon.PopupAtCursor; var CursorPos: TPoint; H:THandle; Found:Boolean; SL:TStringList; begin if Assigned(PopupMenu) then if PopupMenu.AutoPopup then if GetCursorPos(CursorPos) then begin Application.ProcessMessages; // if not (csDesigning in ComponentState) then if (Screen.ActiveControl <> nil) then begin if (Screen.ActiveControl.Owner is TWinControl) then SetForegroundWindow((Screen.ActiveControl.Owner as TWinControl).Handle); end; // Now make the menu pop up PopupMenu.PopupComponent := Self; PopupMenu.Popup(CursorPos.X, CursorPos.Y); PostMessage((Owner as TWinControl).Handle, WM_NULL, 0, 0); end; end;所以我想问: 1,如何检测到有modal的window 2,或者TryIcon要接受啥消息,在某个window以modal方式出现时,自动disable掉 久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
------
江上何人初见月,江月何年初照人 |
jest0024
高階會員 發表:11 回覆:310 積分:224 註冊:2002-11-24 發送簡訊給我 |
|
mustapha.wang
資深會員 發表:89 回覆:409 積分:274 註冊:2002-03-13 發送簡訊給我 |
if (Application.MainForm<>nil) and (Windows.IsWindowEnabled(Application.MainForm.Handle)) then //add by wxh begin // Now make the menu pop up SetForegroundWindow(Handle); PopupMenu.PopupComponent := Self; PopupMenu.Popup(CursorPos.X, CursorPos.Y); PostMessage((Owner as TWinControl).Handle, WM_NULL, 0, 0); end; end;如果这样,有个问题,在Application.ShowMainForm是设为true的话,即使有Modal窗体,Windows.IsWindowEnabled(Application.MainForm.Handle))还是返回true 久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
------
江上何人初见月,江月何年初照人 |
jest0024
高階會員 發表:11 回覆:310 積分:224 註冊:2002-11-24 發送簡訊給我 |
引言:我試過,是沒這樣的問題!!~而且ShowMainForm本來就為True(這樣程式開啟才能顯示MainForm),據以下測試..皆可行!!~不知??if (Application.MainForm<>nil) and (Windows.IsWindowEnabled(Application.MainForm.Handle)) then //add by wxh begin // Now make the menu pop up SetForegroundWindow(Handle); PopupMenu.PopupComponent := Self; PopupMenu.Popup(CursorPos.X, CursorPos.Y); PostMessage((Owner as TWinControl).Handle, WM_NULL, 0, 0); end; end;如果这样,有个问题,在Application.ShowMainForm是设为true的话,即使有Modal窗体,Windows.IsWindowEnabled(Application.MainForm.Handle))还是返回true 久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听 procedure TForm1.Timer1Timer(Sender: TObject); //用來判斷是否有效!! begin if IsWindowEnabled(Application.MainForm.Handle)then Caption:='OK' else Caption:='NO'; end; procedure TForm1.Button1Click(Sender: TObject); //測試一 begin MessageBox(Handle,'','',0); end; procedure TForm1.Button1Click(Sender: TObject); //測試二 begin Form2.ShowModal; end; |
mustapha.wang
資深會員 發表:89 回覆:409 積分:274 註冊:2002-03-13 發送簡訊給我 |
|
jest0024
高階會員 發表:11 回覆:310 積分:224 註冊:2002-11-24 發送簡訊給我 |
當ShowMainForm:=False時..
1.Send視窗為MainForm時..有效
2.Send視窗為非MainForm時,無效,但可藉由Send的視窗判斷!!
function IsWinEnabled:Boolean; var i:Integer; begin Result:=False; With Application do for i:=0 to ComponentCount-1 do if Components[i] is TWinControl then if Not IsWindowEnabled(TWinControl(Components[i]).Handle)then Exit; Result:=True; end;發表人 - jest0024 於 2005/03/26 14:06:54 |
mustapha.wang
資深會員 發表:89 回覆:409 積分:274 註冊:2002-03-13 發送簡訊給我 |
procedure TKsCoolTrayIcon.PopupAtCursor; var CursorPos: TPoint; H:THandle; begin if Assigned(PopupMenu) then if PopupMenu.AutoPopup then if GetCursorPos(CursorPos) then begin { Win98 (but not Win95/WinNT) seems to empty a popup menu before closing it. This is a problem when the menu is about to display while it already is active (two click-events following each other). The menu will flicker annoyingly. Calling ProcessMessages fixes this. } Application.ProcessMessages; { Bring the main form or its modal dialog to the foreground. This also ensures the popup menu closes after it loses focus. } // if not (csDesigning in ComponentState) then { if (Screen.ActiveControl <> nil) then begin if (Screen.ActiveControl.Owner is TWinControl) then SetForegroundWindow((Screen.ActiveControl.Owner as TWinControl).Handle); end; //delete by wxh,对opendialog等非delphi的form,会把form盖在modal form上 } Application.Restore; //add by wxh Application.BringToFront; //add by wxh if (Windows.GetForegroundWindow<>Windows.GetActiveWindow) or ((Application.MainForm<>nil) and (Windows.IsWindowVisible(Application.MainForm.Handle)) and (Windows.IsWindowEnabled(Application.MainForm.Handle))) then //add by wxh begin // Now make the menu pop up SetForegroundWindow(Handle); PopupMenu.PopupComponent := Self; PopupMenu.Popup(CursorPos.X, CursorPos.Y); PostMessage((Owner as TWinControl).Handle, WM_NULL, 0, 0); end; end; end;最后乱try一番,加了这样的判断,好像正常了。 但不知道Windows.GetForegroundWindow<>Windows.GetActiveWindow到底啥原因 久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
------
江上何人初见月,江月何年初照人 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |