找回密码
 注册会员
查看: 803|回复: 0

delphi中的findwindow函数用法

[复制链接]
发表于 2010-6-25 09:27:04 | 显示全部楼层 |阅读模式
<p>delphi中的findwindow函数用法</p>
<p><img src="http://img.baidu.com/img/iknow/icn_point.gif"> 悬赏分:5 -</p>
<p>解决时间:2010-6-25 09:26</p>
<p>目的:一个带主窗体(不是MDI form)的test.exe如果已经打开了,再启动的时候禁止重新启动起来,而是发一个消息给已经启动的test.exe,test.exe收到该消息激活自己,并使自己回到桌面的最前面。</p>
<p>方法:使用的方法是findwindow(类名,nil)找到窗体句柄,在test.dpr中Application.Initialize之前增加:</p>
<p>【hHandle := FindWindow(APPNAME, nil);</p>
<p>if hHandle > 0 then</p>
<p>begin</p>
<p>PostMessage(hHandle, CM_RESTORE, 0, 0);</p>
<p>Exit;</p>
<p>end;】</p>
<p>并在主窗体main.pas中增加CM_RESTORE消息的处理【  Application.Restore;Application.BringToFront;】</p>
<p>问题:由于标题是变化的,所以只能用类名,例如我的exe名称是test.exe,我的用法是hHandle:=  FindWindow(pchar(\'test\'), nil); 但是跟踪发现hHandle都是0(同样的test.exe已经跑起来了)</p>
<p>提问者: kitlar - 二级</p>
<p>最佳答案</p>
<p>lpClassName</p>
<p>[in]   Pointer   to   a   null-terminated   string   that   specifies   the   class   name   or   a   class   atom   created   by   a   previous   call   to   the   RegisterClass   or   RegisterClassEx   function.   The   atom   must   be   in   the   low-order   word   of   lpClassName;   the   high-order   word   must   be   zero.</p>
<p>If   lpClassName   points   to   a   string,   it   specifies   the   window   class   name.   The   class   name   can   be   any   name   registered   with   RegisterClass   or   RegisterClassEx,   or   any   of   the   predefined   control-class   names.</p>
<p>If   lpClassName   is   NULL,   it   finds   any   window   whose   title   matches   the   lpWindowName   parameter.</p>
<p>lpWindowName</p>
<p>[in]   Pointer   to   a   null-terminated   string   that   specifies   the   window   name   (the   window \'s   title).   If   this   parameter   is   NULL,   all   window   names   match.</p>
<p>以上是对findwindow函数参数的解释,从中可以看出,通过类型查找窗口句柄的话,首先该类必须由RegisterClass或RegisterClassEx注册过,或者是属于预定义的控件类。</p>
<p>0</p>
<p>回答者:</p>
<p>howlshadow - 七级   2010-6-18 11:09</p>
<p>我来评论>></p>
<p>提问者对于答案的评价:</p>
<p>自己有解决,此答案有点参考意义。</p>
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|文字版|手机版|小黑屋|襄阳城

GMT+8, 2025-7-28 10:12

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表