我想写一个程序,把当前窗口的标题最后加上几个字符。
可是写出来以后,只有我写的这个程序是当前窗口的时候运行有效果。
其他窗口是当前窗口的时候GetForegroundWindow老返回0。
不知道是什么原因。请各位高手帮我看一下。
procedure TForm1.Button1Click(Sender: TObject);
var
handle:integer;
title,right: string;
count,EditLong,TitleLong:integer;
begin
  handle:=GetForegroundWindow;
  TitleLong:=getwindowtextlength(handle);
  setlength(title,TitleLong);
  handle:=GetActiveWindow();
  GetWindowText(handle,pchar(title),256);
  EditLong:=length(edit1.Text);
  right:=rightstr(title,EditLong);
  if (TitleLong<EditLong) or (strcomp(pchar(right),pchar(edit1.text))<>0) then
    begin
      setwindowtext(handle,pchar(title+'-'+edit1.Text))
    end;
end;

解决方案 »

  1.   

    你根本获得不了!因为焦点一转移,它就不能进行那些操作了!你用个TIMER控件测一下,按钮是不可能的!
      

  2.   

    我就是拿timer测试的了,当我的程序是当前窗口才能得到句柄,否则都得到一个0句柄,太奇怪了。 难道GetForegroundWindow只能得到进程内窗口的句柄?
    我换getactivewindow也试验过了,照样不行。