我的程序在后台运行,怎样才能获得当前活动窗口(另一个应用程序的)的Edit控件的句柄,并给它传递一个字符串呢?用户已经在Edit里设置了插入符号
    我试了很多方法,由于不知道窗口名,FindWindow都不能用啊,即使找到该窗体,又怎样得知用户设置插入符号的Edit句柄呢?
    请各位大侠伸出援助之手,帮帮小弟.

解决方案 »

  1.   

    知道窗体的句柄,知道Edit控件的ID也可。或者通过窗体的句柄来获得它的子的句柄。然后判断是哪个Edit根据它里面已经设置的插入符号。
    GetNextWindow()或许能帮助你
      

  2.   

    to: Pipi0714(老顽童) 
    有没有函数获得当前活动窗体(另一个应用程序)的句柄啊,又怎么能判断出是哪个edit设置了插入符号呢
      

  3.   

    GetWindow循环得到所有的子窗体的句柄
      

  4.   

    Thank lixiaosan(小三),
    现在能够得到最上层用户活动的窗口了,但仍然不知道用户已经设置插入符号的Edit控件的句柄或ID啊
      

  5.   

    EnumChildWindows()可以枚举子控件,
    再去查找你想要的Edit.
      

  6.   

    大家来看看我的代码哪里有问题
             HWND hWnd = GetForegroundWindow()->GetSafeHwnd();
             if( hWnd != NULL )
    {
    RECT rcClient;
    ::GetClientRect(hWnd,&rcClient);
    EnumChildWindows(hWnd,EnumChildProc, (LPARAM) rcClient);           //这里为什么编译不过去呢,提示说第二个参数类型不对
    }
    //下面是回调函数
    BOOL CALLBACK CTest2Dlg::EnumChildProc(HWND hwndChild, LPARAM lParam)
    {
    int ChildID = GetWindowLong(hwndChild,GWL_ID);
    CString s;
    s.Format("%d ",ChildID);
    AfxMessageBox(s);
    return true;
    }
      

  7.   

    如果没有容器覆盖的话,直接用GetWindow(GW_CHILD)和GetWindow(GW_HWNDNEXT)遍历子窗体吧。还可以用GetClassName获得遍历的窗口类的名称。
      

  8.   

    The GetFocus function retrieves the handle to the window that has the keyboard focus, if the window is associated with the calling thread's message queue. 
     
    Res
    Even if GetFocus returns NULL, another thread's queue may be associated with a window that has the keyboard focus. Use the GetForegroundWindow function to retrieve the handle to the window with which the user is currently working. You can associate your thread's message queue with the windows owned by another thread by using the AttachThreadInput function. 
      

  9.   

    感觉问题越来越明朗了,GetFocus只能返回本进程的获得焦点控件的句柄,所以要获得其他应用程序的控件句柄,需要AttachThreadInput绑定两个进程的消息队列
    不过遗憾的是,对于浏览器打开的网页,地址栏可以接收到消息,而网页里面的EDIT控件却接不到消息,难道这个Edit不是属于该窗口的?
      

  10.   

    浏览器中网页上的Edit控件是不是浏览器的子窗口呢,好象不是,我该怎样访问它呢
      

  11.   

    没试过,如果用getwindow找不到的话就试试realchildwindowfrompoint吧