小弟是菜鸟,请各位大侠详细指点:
问题解决马上给分。请帮我看一下下面的程序有什么问题?桌面上开了窗口但返回的wname总是空的。function EnumWindowsProc(hw: hwnd): Boolean; stdcall;
var
  wname: array[0..40] of char;
begin
  wname:= '';
  if hw<> null then begin
    getwindowtext( hw, wname, 40);
    form1.ListBox1.Items.Add( string( wname));
  end
  else
    showmessage( 'no handle');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  enumwindows( @EnumWindowsProc, 0);
end;

解决方案 »

  1.   

    有些窗口本身没有Caption,所以得到空值很正常。
      

  2.   

    我现在没有工具,所以没办法帮你测试,你试用
    EnumChildWindows 参数Parent Window Handle值传0即可
      

  3.   

    晕,看看EnumWindowsProc的help就知道了。
    To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.
    你没return true程序就结束了。
      

  4.   

    之所以为空是因为程序枚举的第一个窗口标题为空,然后程序结束了,不继续callback了。
    所以只要在EnumWindowsProc最后加上result:= true;就可以了。
      

  5.   

    谢谢xixuemao(乱) ( ) 信誉:112 
    unsigned(僵哥(VB群:11141442,D群:21590636,SQL:21590536)) ( )问题解决了,谢谢 result:= true; ok