首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

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

2012-04-28 
为什么以下代码在没有窗体的程序中就会提示Handle错误procedureCTallvarhCurrentWindow:HWndszText:arra

为什么以下代码在没有窗体的程序中就会提示Handle错误
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;


用这个代码来关闭所有已打开的窗口,为什么这个代码加到一个按纽事情就可以关闭

[解决办法]
Handle是个属性,加到按钮事件的时候,被编译器解释为Self.Handle

热点排行