如何给其他程序的工具栏上的按钮发送点击消息用代码示之~~~谢谢!

解决方案 »

  1.   

    转自DelphiBBS:第一步:找到Button所在窗口句柄:
    var HWin: THandle;
    HWin := FindWindow(nil, '程序Caption');
    第二步:找到Button句柄:
    EnumChildWindows(HBtn, @EnumerateChildWindows, 0);
    第三步:发送消息:
    SendMessage(HBtn, WM, 0, 0);程序参考:
    //回调函数,列出所有子窗口句柄
    var
      HBtn: THandle;function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL;
    var
      WindowCaption: Array[0..254] of Char;
    begin
      GetWindowText(Hwnd, WindowCaption, 255);
      if WindowCaption = '按钮Caption' then 
        HBtn:= Hwnd;
      Result := true;
    end;procedure TFindForm.Button2Click(Sender: TObject);
    var
      H: HWnd;
      I: Integer;
    begin
      H := FindWindow(nil, '程序Caption');
      if H = 0 then
        Exit;
      EnumChildWindows(H, @EnumerateChildWindows, 0);
      SendMessage(HBtn, BM_CLICK, 0, 0);
    end;
      

  2.   

    什么意思,你的意思是击工具栏中的按扭, 执行代码功能两次
    var
      i:integer;
    begin
      i:=1;
     if i<=2 then
       begin
        ShowMessage('信息提示');
        i:=i+1;
       end;
    end;
      

  3.   

    怎么 给 其他exe程序的 工具栏上的按钮 发送点击消息呢?
      

  4.   

    SendMessage(HBtn, BM_CLICK, 0, 0);//这个就是发送点击消息。关键在于能否获取到BUTTON的句柄
    POSTMESSAGE都可以的。
      

  5.   

    FindWindow
    EnumChildWindows
    SendMessage3#很正確,就是用這3個函數,另外要寫一個回調函數
      

  6.   

    我说的是ToolButton,不是Button。Button 的句柄能找到,ToolButton 不能。找不到句柄怎么发送呢?
      

  7.   

    delphi工具栏中没有像VC里的IDC值,所以枚举完子窗口后给工具栏可以发个模拟点击的消息也许是最方便的
    postmessage(hwnd, WM_LBUTTONDOWN,1,1);
    postmessage(hwnd, WM_LBUTTONUP,1,1);