关于前置窗口的问题(100分)

  • 主题发起人 主题发起人 sentiment
  • 开始时间 开始时间
S

sentiment

Unregistered / Unconfirmed
GUEST, unregistred user!
很多程序运行都有一定的时间,且中间不能间断,比如报表的生成。<br>这个时候程序会弹出一个前置窗口,使得用户不能够终止程序的运行。同时这个窗口要<br>一直得到焦点。也就是它的ZORDER最高。似乎只有SHOWMODAL出来的窗口有这样的性质,<br>但如果用SHOWMODAL的话,程序就停了。而如果在被SHOWMODAL出来的窗口中调用程序,则<br>没有普适性。我想如果能用SHOW方法SHOW出一个窗口,而且知道它关闭一直在最前,这样就<br>能让所有的程序都使用一个前置窗口了。不知道有什么办法没有。
 
procedure AlwaysOnTop(Form: TForm; OnTop: Boolean); <br>begin <br>if OnTop then <br>SetWindowPos(Form.Handle, HWND_TOPMOST, 0, 0, 0, 0, <br>SWP_NOMOVE or SWP_NOSIZE) <br>else <br>SetWindowPos(Form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, <br>SWP_NOMOVE or SWP_NOSIZE) <br>end; <br>仅适用normal窗体
 
将form的formstyle设为fsStayOnTop,试一下。
 
那就用多线程来做吧。
 
const<br>&nbsp; CM_MSG_CLOSE &nbsp;= WM_USER+402;<br><br>var<br>&nbsp; msg:TMsg;<br>&nbsp; CanExit:Boolean;<br>begin<br>&nbsp; CanExit:=True;<br>&nbsp; with TMsgForm.Create(Application) do<br>&nbsp; begin<br>&nbsp; &nbsp; Show;<br>&nbsp; &nbsp; while CanExit &nbsp;do<br>&nbsp; &nbsp; &nbsp; if PeekMessage(msg, 0, 0, 0, 1) then<br>&nbsp; &nbsp; &nbsp; &nbsp; if (msg.message = CM_MSG_CLOSE) then &nbsp;//Msg窗体可以有个中断按钮,发送这个消息就中断<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CanExit:=False<br>&nbsp; &nbsp; &nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //处理你要做的事<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TranslateMessage(msg);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DispatchMessage(msg);<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; WaitMessage;<br>&nbsp; &nbsp; result:=CheckOK;<br>&nbsp; end;<br>end;<br>
 
在前<br>&nbsp; &nbsp; SetWindowPos(self.handle, HWND_TOPMOST,<br>&nbsp; &nbsp; &nbsp; self.Left, self.Top, self.Width, self.Height,0);<br>取消在前<br>&nbsp; &nbsp; SetWindowPos(self.handle, HWND_NOTOPMOST,<br>&nbsp; &nbsp; &nbsp; &nbsp;self.Left, self.Top, self.Width, self.Height,0);<br>
 
后退
顶部