線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1543
推到 Plurk!
推到 Facebook!

如何判断有Modal窗体?

尚未結案
mustapha.wang
資深會員


發表:89
回覆:409
積分:274
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-03-24 16:22:22 IP:218.80.xxx.xxx 未訂閱
因为用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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-03-25 03:21:41 IP:211.74.xxx.xxx 未訂閱
判斷主視窗Enabled if IsWindowEnabled(Handle) then ShowMessage('目前能操作') else ShowMessage('目前不能操作');
mustapha.wang
資深會員


發表:89
回覆:409
積分:274
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-03-25 08:45:25 IP:218.80.xxx.xxx 未訂閱
        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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-03-25 11:51:09 IP:211.74.xxx.xxx 未訂閱
引言:
        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 久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
我試過,是沒這樣的問題!!~而且ShowMainForm本來就為True(這樣程式開啟才能顯示MainForm),據以下測試..皆可行!!~不知??
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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-03-26 13:24:34 IP:218.1.xxx.xxx 未訂閱
这个元件有个StartMinimized属性,如果选True,程序执行后,MainForm就不显示,只有右下角的TrayIcon     久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
------
江上何人初见月,江月何年初照人
jest0024
高階會員


發表:11
回覆:310
積分:224
註冊:2002-11-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-03-26 14:00:56 IP:211.74.xxx.xxx 未訂閱
當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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-03-29 09:06:35 IP:218.80.xxx.xxx 未訂閱
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到底啥原因 久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
------
江上何人初见月,江月何年初照人
系統時間:2024-04-29 6:50:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!