怎么寻找mdi子窗体?(50分)

  • 主题发起人 主题发起人 book523
  • 开始时间 开始时间
B

book523

Unregistered / Unconfirmed
GUEST, unregistred user!
主窗体frmMain,为frmMdiForm窗体,其中有一子窗体类名为TfrmOperater,窗体name为<br>frmOperater,标题为‘操作员管理’,我用下面的api函数怎么找不到该窗体?<br>FindWindowEx(frmMain.handle,0,'TfrmOperater','frmOperater');<br>或<br>FindWindowEx(frmMain.handle,0,'TfrmOperater','操作员管理');<br>或<br>FindWindowEx(frmMain.handle,0,'TfrmOperater',nil);<br>都找不到,返回的值都为0,应该怎么找才能到mdi子窗体?
 
for i := 0 to MDICount - 1 do<br>&nbsp; &nbsp; &nbsp; MDIChildren<br>
 
function TMainForm.ExistsForm(MDIFormCaption:String):boolean;<br>var<br>&nbsp; i:byte;<br>begin<br>&nbsp; result:=true;<br>&nbsp; for i:=0 to MDIChildCount-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; if MDIChildren.Caption=MDIFormCaption<br>&nbsp; &nbsp; then result:=false;<br>&nbsp; end;<br>end;
 
bubble is right!<br>
 
不错啊,这样确实可以找到,如果要激活该窗体怎办?setactivewindow好象不行,<br>setwindowpos也好象不行啊!
 
&nbsp;for i := 0 to MDICount - 1 do<br>&nbsp; &nbsp; if Tform(MDIChildren).Name = '窗体的名字' then<br>&nbsp; &nbsp; &nbsp; Tform(MDIChildren).BringToFront;<br>也可由此得到此窗体的句柄:Tform(MDIChildren).Handle
 
procedure OpenForm(FormClass: TFormClass; var fm; AOwner:TComponent);<br>var<br>&nbsp; i: integer;<br>&nbsp; Child:TForm;<br>begin<br>&nbsp; for i := 0 to Screen.FormCount -1 do<br>&nbsp; &nbsp; &nbsp; if Screen.Forms.ClassType=FormClass then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Child:=Screen.Forms;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Child.WindowState=wsMinimized then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(Child.handle,SW_SHOWNORMAL)<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(Child.handle,SW_SHOWNA);<br>&nbsp; &nbsp; &nbsp; &nbsp; if (not Child.Visible) then Child.Visible:=True;<br>&nbsp; &nbsp; &nbsp; &nbsp; Child.BringToFront;<br>&nbsp; &nbsp; &nbsp; &nbsp; Child.Setfocus;<br>&nbsp; &nbsp; &nbsp; &nbsp; TForm(fm):=Child;<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; Child:=TForm(FormClass.NewInstance);<br>&nbsp; TForm(fm):=Child;<br>&nbsp; Child.Create(AOwner);<br>end;
 
多人接受答案了。
 
后退
顶部