我用enumchildwindows尋找窗體上所有句柄,但在combobox卻顯示出7個一樣的數字(3471),請問是什麼問題,源碼如下,謝謝.
function proc(h:hwnd;l:lparam):bool;
begin
form1.combobox1.items.add(inttostr(h));
result:=true;
end;procedure form1.button1click(sender:tobject);
begin
enumchildwindows(handle,@proc,0);
end;

解决方案 »

  1.   

    proc声明为stdcall

    function OnEnumWindows(AHandle: THandle; AParam: Cardinal): Bool; stdcall;
    begin
      Form1.Memo1.Lines.Add(IntToStr(AHandle));
      Result := True;
    end;
      

  2.   

    function proc(h: HWnd; l: LParam): bool; stdcall;
    var
      s: string;
    begin
      SetLength(s, 255);
      GetWindowText(h, PChar(s), 256);
      s := PChar(s);
      Form1.ComboBox1.Items.Add(s);
      result:=true;
    end;procedure TForm1.button1click(sender:tobject);
    begin
      enumchildwindows(handle,@proc,0);
      //enumwindows(@proc,0);
    end;
      

  3.   

    句柄本来就是整数,所以你在这里看到的都是一些数。如果想看到Caption之类的信息,需要另外的方法
      

  4.   

    問題解決了.
    想知道stdcall的作用是什麼??
    另外bool & boolean是同樣的類型嗎??