如何使显示的窗体呈不激活状态???(50分)

  • 主题发起人 主题发起人 oldnew
  • 开始时间 开始时间
O

oldnew

Unregistered / Unconfirmed
GUEST, unregistred user!
if not Assigned(MessageForm) then<br> &nbsp; &nbsp;MessageForm := TMessageForm.Create(Self);<br> &nbsp;MessageForm.Show;<br><br>比如我当前在Form1中操作,此时后台线程运行了以上代码显示MessageForm,但MessageForm不要激活,当前焦点还是在Form1中,应该如何才能做到啊???
 
很简单:<br> if not Assigned(MessageForm) then<br> &nbsp; &nbsp;MessageForm := TMessageForm.Create(Self);<br>messageform.parent:=form1.panel1; &nbsp;<br>MessageForm.Show<br><br>form1.panel1; &nbsp;<br>根据需要放个地方就行
 
ShowWindow(MessageForm.Handle, SW_SHOWNA); 代替 MessageForm.Show;
 
这个是ShowModal的源代码,如果激活的时候能够让后面的主窗体有效,就好了<br>你改改了。代替你的SHOW;<br>function TCustomForm.ShowModal: Integer;<br>var<br> &nbsp;WindowList: Pointer;<br> &nbsp;SaveFocusCount: Integer;<br> &nbsp;SaveCursor: TCursor;<br> &nbsp;SaveCount: Integer;<br> &nbsp;ActiveWindow: HWnd;<br>begin<br> &nbsp;CancelDrag;<br> &nbsp;if Visible or not Enabled or (fsModal in FFormState) or<br> &nbsp; &nbsp;(FormStyle = fsMDIChild) then<br> &nbsp; &nbsp;raise EInvalidOperation.Create(SCannotShowModal);<br> &nbsp;if GetCapture &lt;&gt; 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0);<br> &nbsp;ReleaseCapture;<br> &nbsp;Include(FFormState, fsModal);<br> &nbsp;ActiveWindow := GetActiveWindow;<br> &nbsp;SaveFocusCount := FocusCount;<br> &nbsp;Screen.FSaveFocusedList.Insert(0, Screen.FFocusedForm);<br> &nbsp;Screen.FFocusedForm := Self;<br> &nbsp;SaveCursor := Screen.Cursor;<br> &nbsp;Screen.Cursor := crDefault;<br> &nbsp;SaveCount := Screen.FCursorCount;<br> &nbsp;WindowList := DisableTaskWindows(0);<br> &nbsp;try<br> &nbsp; &nbsp;Show;<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;SendMessage(Handle, CM_ACTIVATE, 0, 0);<br> &nbsp; &nbsp; &nbsp;ModalResult := 0;<br> &nbsp; &nbsp; &nbsp;repeat<br> &nbsp; &nbsp; &nbsp; &nbsp;Application.HandleMessage;<br> &nbsp; &nbsp; &nbsp; &nbsp;if Application.FTerminate then ModalResult := mrCancel else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ModalResult &lt;&gt; 0 then CloseModal;<br> &nbsp; &nbsp; &nbsp;until ModalResult &lt;&gt; 0;<br> &nbsp; &nbsp; &nbsp;Result := ModalResult;<br> &nbsp; &nbsp; &nbsp;SendMessage(Handle, CM_DEACTIVATE, 0, 0);<br> &nbsp; &nbsp; &nbsp;if GetActiveWindow &lt;&gt; Handle then ActiveWindow := 0;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;Hide;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;if Screen.FCursorCount = SaveCount then<br> &nbsp; &nbsp; &nbsp;Screen.Cursor := SaveCursor<br> &nbsp; &nbsp;else Screen.Cursor := crDefault;<br> &nbsp; &nbsp;EnableTaskWindows(WindowList);<br> &nbsp; &nbsp;if Screen.FSaveFocusedList.Count &gt; 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Screen.FFocusedForm := Screen.FSaveFocusedList.First;<br> &nbsp; &nbsp; &nbsp;Screen.FSaveFocusedList.Remove(Screen.FFocusedForm);<br> &nbsp; &nbsp;end else Screen.FFocusedForm := nil;<br> &nbsp; &nbsp;if ActiveWindow &lt;&gt; 0 then SetActiveWindow(ActiveWindow);//更换激活窗体<br> &nbsp; &nbsp;FocusCount := SaveFocusCount;<br> &nbsp; &nbsp;Exclude(FFormState, fsModal);<br> &nbsp;end;<br>end;
 
to 差不多算了: 是要弹出另一个窗体哦! 又不是在本身的窗体中显示<br><br>to dreamisx: 调用这句后,怎么弹出的窗体是一片灰色啊? 窗体里的控件也消失了,而且还不能close,怎么回事啊? 是不是还要调用什么语句啊?<br><br>to 蓝叶菱: 好复杂啊好复杂,怎么改啊怎么改?
 
ShowWindow(MessageForm.Handle, SW_SHOWNOACTIVATE);
 
调用ShowWindow(MessageForm.Handle,SW_SHOWNOACTIVATE);后,怎么弹出的窗体一片灰色啊?里面的控件都消失了??? 而且还不能close!!!<br><br>现象跟ShowWindow(MessageForm.Handle, SW_SHOWNA);一样<br><br>是不是还要调用什么语句啊???
 
就象MSN或者QQ的那种提示弹出窗口效果啊……应该怎么做啊???
 
www.2ccc.com 上搜索 TMsnPopup 组件, 跟那效果一样。呵呵
 
我也碰到过这种问题了,没去找原因,直接把控件放到窗体上就没问题,先在窗体上加pnl就是不行
 
“直接把控件放到窗体上就没问题,先在窗体上加pnl就是不行”<br>是什么意思啊? 应该怎么做才能让弹出的窗口不获得焦点呢???
 
这么复杂,太麻烦了<br>这样行不:<br>先 <br>MessageForm.show;//窗体置顶层,那局怎么写的我忘了<br>完了再<br>Form1.show;<br>这样焦点不又回到Form1了吗?
 
已经搞定了!<br>再加上Visible := True;即可!噢耶
 
后退
顶部