C
cheka
Unregistered / Unconfirmed
GUEST, unregistred user!
/* 连动窗口就是像WinAmp的三个窗体那样可以跟着跑的 */<br><br><br>一.首先,在单元文件Private段加入如下代码:<br><br>void __fastcall LinkWindow(TWMWindowPosChanged &Msg) ;<br><br>BEGIN_MESSAGE_MAP<br> MESSAGE_HANDLER(WM_WINDOWPOSCHANGED,<br> TWMWindowPosChanged,LinkWindow)<br>END_MESSAGE_MAP(TForm); //消息映射,<br><br>//其中WM_WINDOWPOSCHANGED为位置发生变化的消息<br><br>二.然后,在单元实现的文件头中加入如下声明: const flag=SWP_NOACTIVATE||SWP_NOZORDER<br>||SWP_NOMOVE||SWP_NOSIZE;<br><br>//其中大写的都为显示窗口位置的消息,记录窗口是否会发生变化.<br><br>三.最后,在单元实现中加入如下代码:<br><br>void __fastcall TForm1::changed(TWMWindowPosChanged &Msg)<br>{<br>//连动了俩个窗口<br><br>TRect *Rect2,*Rect3;<br>int x2,y2,cx2,cy2;<br>int x3,y3,cx3,cy3;<br>UINT flag2,flag3;<br>// Link Form2;<br>if(Form2!=NULL)<br>{<br>Rect2=new TRect;<br>GetWindowRect(Form2->Handle,Rect2);<br>x2=Msg.WindowPos->x+Msg.WindowPos->cx;<br>y2=Msg.WindowPos->y;<br>cx2=Form2->Width;<br>cy2=Msg.WindowPos->cy;<br>flag2=flag;<br>if(Rect2->Left!=x2||Rect2->Top!=y2)<br>flag2=flag2&&!SWP_NOMOVE;<br>if(Rect2->Right-Rect2->Left!=cx2||Rect2->Bottom-Rect2->Top!=cy2)<br>flag2=flag2&&!SWP_NOSIZE;<br>if(flag2!=flag)<br>SetWindowPos(Form2->Handle,0,x2,y2,cx2,cy2,flag2);<br><br>}<br>//Link Form3<br>if(Form3!=NULL)<br>{<br>Rect3=new TRect;<br>GetWindowRect(Form3->Handle,Rect3);<br>x3=Msg.WindowPos->x-Form3->Width;<br>y3=Msg.WindowPos->y;<br>cx3=Form3->Width;<br>cy3=Msg.WindowPos->cy;<br>flag3=flag;<br>if(Rect3->Left!=x3||Rect3->Top!=y3)<br>flag3=flag3&&!SWP_NOMOVE;<br>if(Rect3->Right-Rect3->Left!=cx3||Rect3->Bottom-Rect3->Top!=cy3)<br>flag3=flag3&&!SWP_NOMOVE;<br>if(flag3!=flag)<br>SetWindowPos(Form3->Handle,0,x3,y3,cx3,cy3,flag3);<br><br>}<br>}<br>四.别忘了把Form2,Form3包含进来.<br><br>#include "unit2.h"<br>#include "unit3.h"<br><br>五.最后在Form2和Form3的OnClose事件中加入如下代码:<br><br>Form2=NULL;<br>delete Form2;<br>//释放Form2占的内存空间<br><br>Form3=NULL;<br>delete Form3;<br>//释放Form3所占用空间<br><br>六.Form1能带Form2,Form3一起动不?<br><br><br>//<br><br>这篇文章是针对C++ Buider的,<br>我也不是很懂BCB,看个大概,想来最大的区别就是<br><br>这段宏<br>BEGIN_MESSAGE_MAP<br> MESSAGE_HANDLER(WM_WINDOWPOSCHANGED,<br> TWMWindowPosChanged,LinkWindow)<br>END_MESSAGE_MAP(TForm); //消息映射,<br><br>以及 LinkWindow 应该改写成TForm1的成员方法, 当然是消息处理类型的,<br>像这样:<br>Type<br>TForm1: public TForm<br>....<br>procedure LinkWindow (var Msg:TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;<br> <br><br><br>