在一个外部程序的窗口中有一个ToolBar,在ToolBar上有一个ToolBotton,现在需要设计一个程序,去单击这个外部程序中的ToolBotton,明白了吗?

解决方案 »

  1.   

    看我必杀★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
          Wnd:=FindWindow(nil,'Function');
          if Wnd=0 then
           begin
            POSTMessage(TWnd,WM_LBUTTONDOWN, 0, MAKEWPARAM(184,17));
            POSTMessage(TWnd,WM_LBUTTONUP, 0, MAKEWPARAM(184,17));
           end;★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★Wnd 是Form 的句柄你只能按坐标点来实现点击,用  SPY++  侦测你的鼠标消息,
    再将你的鼠标在按键上移支,
    可知按键大概的坐标
      

  2.   

    用SendMessage的方法是没有错了。
    先用FindWindow找到主窗体,再用GetNextWindow()查找按钮,然后发消息模拟点击或按键。
    if (hwnd=FindWindow(NULL,"Untitled - It3e for Windows95/NT"))   //查找标题为Untitled - It3e for Windows95/NT,类名以Afx:400000开头的窗体
        {
            GetClassName(hwnd,text,255);//取类名
            if (strncmp(text,MainFormClassName,10)!=0) Found = false;
        }
        else
            Found = false;
        if (!Found) //不存在则运行IT3EW32.EXE
        {
            hwnd=ShellExecute(Handle,"open",(StartPath+"IT3EW32.EXE").c_str(),"",GetCurrentDir().c_str(),SHOWHIDE);
            if (int(hwnd)<=32)
            {
                MessageBox(Handle,("不能执行"+StartPath+"\\IT3EW32.EXE\r错误代码:"+IntToStr(int(hwnd))).c_str(),NULL,MB_OK|MB_ICONSTOP);
                exit(1);
            }
            Sleep(1000);
            do
            {
                Application->ProcessMessages();
                hwnd = FindWindow(NULL,"Untitled - It3e for Windows95/NT");
                GetClassName(hwnd,text,255);
            }while (!hwnd || strncmp(text,MainFormClassName,10)!=0);
            ShowWindow(hwnd,SHOWHIDE);
            //MessageBox(Handle,"Execute OK.","",MB_OK);
        }
        Label1->Caption = "已连接";    PostMessage(hwnd,WM_COMMAND,ReceiveFormMsgID,0);    //*Msg:32772*激活接收对话框(Receive File)
        HWND hwnd2,hwnd3;
        char text1[255],text2[255];
        do
        {
            Application->ProcessMessages();
            hwnd2 = FindWindow(NULL,"Receive File");
        }while (hwnd2==0);//GetParent(hwnd2)!=hwnd);    //查找"文件名"输入框
        hwnd3 = GetTopWindow(hwnd2);
        //GetWindowText(hwnd3,text1,255);
        GetClassName(hwnd3,text2,255);
        while (/*AnsiString(text1)!="(file)" || */AnsiString(text2)!="Edit")
        {
            Application->ProcessMessages();
            hwnd3 = GetNextWindow(hwnd3,GW_HWNDNEXT);
            //GetWindowText(hwnd3,text1,255);
            GetClassName(hwnd3,text2,255);
        }
        //输入文件名
    //*
        char cDataFileName[255],*pFileName;
        pFileName = cDataFileName;
        strncpy(cDataFileName,(StartPath+"IrData.txt").c_str(),255);
        //MessageBox(Handle,pFileName,"",MB_OK);
        SendMessage(hwnd3,WM_SYSKEYDOWN,8,NULL);
        while (*pFileName)
        {
            SendMessage(hwnd3,WM_CHAR,*pFileName,NULL);
            pFileName++;
        }
    //*/
        //SetWindowText(hwnd3,(StartPath+"IrData.txt").c_str());    //查找"保存"按钮
        hwnd3 = GetTopWindow(hwnd2);
        GetWindowText(hwnd3,text1,255);
        GetClassName(hwnd3,text2,255);
        while (AnsiString(text1)!="保存(&S)" || AnsiString(text2)!="Button")
        {
            //MessageBox(Handle,(AnsiString(text1)+AnsiString(text2)).c_str(),"",MB_OK);
            Application->ProcessMessages();
            hwnd3 = GetNextWindow(hwnd3,GW_HWNDNEXT);
            GetWindowText(hwnd3,text1,255);
            GetClassName(hwnd3,text2,255);
        }    SendMessage(hwnd3,WM_SYSKEYDOWN,13,NULL);  //点击"保存"按钮
        SendMessage(hwnd3,WM_LBUTTONDOWN,NULL,NULL);
        PostMessage(hwnd3,WM_LBUTTONUP,NULL,NULL);
        Label1->Caption = "接收中...";
    .....(略)
      

  3.   

    又错了不是,TToolButton是从TGraphicControl继承的,哪来的句柄?
      

  4.   

    菜单也没有句柄呀,我上面的程序不照样打开它了。
    你先找到Toolbar的句柄,然后将SendMessage(hwnd,WM_COMMAND,i,0)放到循环中,i由0到65535,不用它跑完,你就能穷举出各TToolButton对应的编号了
      

  5.   

    呵呵,死办法:
    使用API
    SetCursorPos
    mouse_event