是IsIconic的问题吗(75分)

  • 主题发起人 主题发起人 gy1969
  • 开始时间 开始时间
G

gy1969

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下(防止程序运行多个实例)。<br>虽然能够防止程序运行多个实例,但不能恢复最小化的窗口<br>program App1;<br><br>uses<br>&nbsp; Forms,<br>&nbsp; Windows,<br>&nbsp; UForm1 in 'Unit1.pas' {MainForm};<br><br>{$R *.res}<br><br>procedure Running_Enumwindows;<br>&nbsp; function EnumApps(Wnd: HWND; LPARAM: DWord): Boolean; StdCall;<br>&nbsp; var<br>&nbsp; &nbsp; WndCaption: array[0..254] of Char;<br>&nbsp; begin<br>&nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; GetWindowText(Wnd, @WndCaption, 254);<br>&nbsp; &nbsp; if (Pos('App1', WndCaption) &gt;= 1) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if IsIconic(Wnd) then &nbsp;//这里有什么问题吗<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowWindow(Wnd, SW_RESTORE)<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; SetForeGroundWindow(Wnd); &nbsp;//这里没问题<br>&nbsp; &nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; &nbsp; Halt;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>begin<br>&nbsp; EnumWindows(@EnumApps, 0);<br>end;<br><br>begin<br>&nbsp; Running_Enumwindows;<br>&nbsp; Application.Initialize;<br>&nbsp; Application.Title := 'App1';<br>&nbsp; Application.CreateForm(TForm1, Form1);<br>&nbsp; Application.Run;<br>end.
 
最小化的窗口用OPENICON这个API函数可以激活的。先用isiconic判断这个窗口是否最小化<br>了,是的话就用OPENICON,<br>上次我有个朋友也是问我这个问题,我试过,可以的^_^
 
换了OpenIcon还是不行<br>我怀疑是IsIconic不起作用<br>我的系统环境是2000 pro + delphi 6
 
还不行?我用的是2000 SERVER+D5,没用过D6,不过,都是调用API而已,应该没问题的?<br>想不通。
 
中间一段改动如下:<br>&lt;b&gt;<br>if IsIconic(Wnd) then<br>&nbsp; OpenIcon(Wnd) <br>else begin<br>&nbsp; Beep;<br>&nbsp; SetForeGroundWindow(Wnd);<br>end;<br>&lt;/b&gt;<br>不管什么情况,都有“叮”的一声
 
这样?在OPENICON那加断点试试看有没有执行。<br>总不成2000 SERVER+D5 和2000 PRO + D6在执行同样的API函数会有不同吧(我这也没有<br>这个环境来试)
 
不知什么原因,IsIconic返回值总是false
 
确定那个窗口肯定是最小化了吗?
 
肯定<br>我在D5中试了,没问题<br>难道真是D6的问题
 
不会吧,看看在D5和D6中的WINDOWS。PAS文件里,这两个地方对ISICONIC的声明有什么不同<br>(我这没有D6)。实在想不同,调用一个API函数,怎么会D5和D6中不同呢?<br>不如问问大家:)<br>
 
刚才发现Application的title和主Form的caption一样就有问题
 
这样就解决了<br>function EnumApps(Wnd: HWND; LPARAM: DWord): Boolean; StdCall;<br>&nbsp; var<br>&nbsp; &nbsp; WndCaption: array[0..254] of Char;<br>&nbsp; &nbsp; ClassName: array[0..30] of Char;<br>&nbsp; begin<br>&nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; GetWindowText(Wnd, @WndCaption, 254); &nbsp; &nbsp; <br>&nbsp; &nbsp; if (Pos('Form1 - ', WndCaption) &gt;= 1) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; GetClassName(Wnd, ClassName, 30);<br>&nbsp; &nbsp; &nbsp; if ClassName = 'TApplication' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if IsIconic(Wnd) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowWindow(Wnd, SW_RESTORE)<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetForeGroundWindow(Wnd);<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; &nbsp; &nbsp; Halt;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;
 
me //faint,这都行。
 
结束了,结束了
 
后退
顶部