hello_zhangh

博客园 首页 新随笔 联系 订阅 管理

C#
[DllImport("user32.dll", EntryPoint = "FindWindow")]
        public static extern int FindWindow(
            string lpClassName,
            string lpWindowName
        );

[DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(
            int hwnd,
            int wMsg,
            IntPtr wParam,
            string lParam
        );
        public const int WM_SETTEXT = 0xC;

int hwnd = FindWindow(null, "无标题 - 记事本");
            string s = "要修改的名字";
            if (hwnd != 0)
            {
                SendMessage(hwnd, WM_SETTEXT, IntPtr.Zero, s);
            }
            else
            {
                MessageBox.Show("记事本没有运行");
            }

 

Delphi

 

var
  a,b:PAnsiChar; h:HWND;
begin
  h:= FindWindow(nil,'无标题 - 记事本');
  if (h <> 0) then begin

    SendMessage(h,WM_SETTEXT,255,Integer(PChar('要修改的名字)));
  end
  else begin
    ShowMessage('记事本没有运行');
  end;
end;

 

posted on 2010-06-21 16:49  弓二  阅读(466)  评论(0编辑  收藏  举报