为什么以下代码在没有窗体的程序中就会提示Handle错误

ye12 2012-04-25 03:26:01
procedure CTall;
var
hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin

hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if (GetWindowText(hCurrentWindow, @szText, 255)> 0) and isWindowVisible(hCurrentWindow) then
hCurrentWindow := GetWindow(GetDesktopWindow(), GW_HWNDNEXT);
sendMessage(hCurrentWindow,wm_sysCommand,sc_close,0);

end;
end;


用这个代码来关闭所有已打开的窗口,为什么这个代码加到一个按纽事情就可以关闭
...全文
139 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ye12 2012-05-04
  • 打赏
  • 举报
回复
高手还在放假吗,那位指点一下
ye12 2012-04-25
  • 打赏
  • 举报
回复
改成这样,hCurrentWindow := GetWindow(GetDesktopWindow(), GW_HWNDFIRST);,可以编译运行,但是还是不会把打开的窗口关闭呢,我想要的结果是自动关闭已打开的所有窗口。
s11ss 2012-04-25
  • 打赏
  • 举报
回复
把Handle改成GetDesktopWindow()
s11ss 2012-04-25
  • 打赏
  • 举报
回复
hCurrentWindow := GetWindow(GetDesktopWindow(), GW_HWNDFIRST);
ye12 2012-04-25
  • 打赏
  • 举报
回复
那我这个控制台的程序,这里要如何改呢
s11ss 2012-04-25
  • 打赏
  • 举报
回复
Handle是个属性,加到按钮事件的时候,被编译器解释为Self.Handle

16,747

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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