如何运用API函数GetWindow()配合GetWindowText()逐一查出各视窗的标题

解决方案 »

  1.   

    var
    hCurrentWindow: HWnd;
    szText: array[0..254] of char; 
    begin
    MyStringList.Clear;
    hCurrentWindow := GetWindow(application.Handle, GW_HWNDFIRST);
    while hCurrentWindow <> 0 do
    begin
    if GetWindowText(hCurrentWindow, @szText, 255) > 0 then
    MyStringList.Add(StrPas(@szText));
    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
    end;
      

  2.   

    如果 @szText 前的那个 @ 不写会怎样?
    为什么要加一个 @ 呢???
      

  3.   

    因为delphi不是c++所以非加@不可
      

  4.   

    我看了一下,好像 szText 与函数参数要求的类型不太一样,如果不加 @ 会出现类型不统一的错误,但加上 @ 后似乎就没有了,为什么???
      

  5.   

    加了 @ 后,好像 szText 类型不一致的错误消失了,不知为什么.
      clipcursor() 中的 TRect 与 PRect 好像也是这样,谁能说说究竟怎么一回事?
      

  6.   

    //逐一查出各视窗的标题可以直接用 EnumWindows API 函数啊!
      

  7.   

    Function MyEnumCallBack (EnumHandle : HWnd; EnumValue : Integer) : Boolean; Stdcall;
    var
      lpBuf : Array [0..255] of char;
    begin
      Result := True;
      if (GetWindowText(EnumHandle,@lpBuf,255) > 0) //then
        and (GetWindowLong(EnumHandle, GWL_EXSTYLE or WS_EX_OVERLAPPEDWINDOW) <> 0 ) then
        begin
          Form1.Memo1.Lines.add('Form Caption -- Form Handle');
          Form1.Memo1.Lines.add(lpBuf + ' -- ' + IntToStr(EnumHandle));
       end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      EnumWindows(@MyEnumCallBack,0);
    end;
      

  8.   

    每本delphi参考书上都有,真是的,是不是 寻开心阿