procedure TForm1.Button1Click(Sender: TObject);
var a:hwnd;
b:pchar;
c:integer;
begin
//a:=findwindow(pchar(#32770),0);//这是用来找QQ的窗口的。窗体可以找到,可是不可以获得窗口标题。一用getwindowtext就内存报错。
a:=findwindow(0,'Form1');
if a<>0 then showmessage('fff');
try//因为格式化和QQ的窗口类名都是用的#32770(为什么QQ要这么做呢?)为了不让别人格我的硬盘,而可以上QQ。我要找窗口标题来区分一下,可是用了这个try后,放现我找到的form1(我自己做的一个窗体)标题显示的是一个乱码,而去掉try就可以找到如约的'form1'郁闷。
c:=getwindowtext(a,b,255);
except
b:='Errar';
c:=0;
end;
edit1.Text:=b;
end;

解决方案 »

  1.   

    //这个是我自己写的查找QQ发送消息时候的窗口的代码
    //看看对你是否有帮助
    function GetWnd:HWND;
    var
      hCurrentWindow: HWND;
      WndText: string;
    begin
      hCurrentWindow := GetWindow(Application.Handle,GW_HWNDFIRST);
      while hCurrentWindow <> 0 do
      begin
        WndText:= GetWndText(hCurrentWindow);
        if(Pos('发送消息',WndText) > 0) then
        //查找含有‘发送消息’字样的窗口
        begin
          Result := HCurrentWindow;//返回
          Exit;
        end;
        hCurrentWindow := GetWindow(hCurrentWindow,GW_HWNDNEXT);//重复
      end;
      Result := 0;
    end;
      

  2.   

    >>因为格式化和QQ的窗口类名都是用的#32770(为什么QQ要这么做呢?)没啥,因为它是拿VC开发的,你自己也用MFC默认的Dialog就长这样当然出错,你还没给传进去的字符串分配内存.