findwindow函数求救!

delbir 2003-10-29 02:24:56
: 一个系统有一个父窗体,N个子窗体。现在我打算实现:在同一个菜单项上点两次,只打开一个相同的字窗体。也就是说,不让他打开重复的字窗体,该怎么办啊?大家教我!
我的想法:在打开子窗体时,先检查看有没有这个窗体的一个实例在运行,如果没有的话才打开,否则什么也不做。
如:
button1.click();
begin
if findwindow('Tform2','singleapp')=0 then
Application.create(Tform2,form2)
end;
这样怎么不行啊?
...全文
14 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cash2000 2003-10-30
  • 打赏
  • 举报
回复
function OpenUniqueMethodHookForm(FormClass:TFormClass; const HookMethod):TForm;
var
i:Integer;
begin
result:=nil;
with Screen, TMethod(HookMethod) do
for i:=0 to Screen.FormCount-1 do
if Forms[i] is FormClass then
if (Forms[i].Tag=Longint(Data))
and (Forms[i].HelpContext=Longint(Code)) then
begin
result:=Forms[i];
break;
end;
if result=nil then
with TMethod(HookMethod) do
begin
result:=FormClass.Create(Application);
result.Tag:=Longint(Data);
result.HelpContext:=Longint(Code);
end
else if result.WindowState=wsMinimized then
result.WindowState:=wsNormal;
result.Show;
end;
XXSingle 2003-10-30
  • 打赏
  • 举报
回复
支持楼上 aiirii(ari) :

if Assigned(form2) then
Form2.show
else
begin
Application.create(Tform2,form2);
Form2.show;
end;
delbir 2003-10-30
  • 打赏
  • 举报
回复
用fastreport做的报表打印事件的代码怎么写啊?
frreport1.prepare;
frreport1.printpreparedreport;
行吗?
高手指点!
aiirii 2003-10-29
  • 打赏
  • 举报
回复
if Assigned(form2) then
Form2.show
else
begin
Application.create(Tform2,form2);
Form2.show;
end;
seashoreboy 2003-10-29
  • 打赏
  • 举报
回复
试试这样行不行:
for I := MDIChildCount-1 downto 0 do
begin
if MDIChildren[I] is Tform2 then
begin
//发现相同观察任务子窗体则设置返回值并退出

bFound := True;
break;
end;
end;
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧