我已经获得窗体的句柄,
这个窗体的一个编辑控件CEDIT的ID是IDC_EDIT1
请问,我如何得到其中的内容?
急:请给出代码,谢谢!HWND    hTarget;
DWORD   dwProcessID, dwThreadID;
HANDLE  hProcess;//根据窗口标题获取进程窗口句柄
hTarget = ::FindWindow(NULL, "学校考勤数据集成系统客户端");
dwThreadID = ::GetWindowThreadProcessId(hTarget, &dwProcessID);
if(hTarget)
{
...
}

解决方案 »

  1.   

    GetWindowText只能获取自身的吧?
    我是想获取外部程序的。
      

  2.   

    大概这个样子
    hTarget = ::FindWindow(NULL, "学校考勤数据集成系统客户端");
    dwThreadID = ::GetWindowThreadProcessId(hTarget, &dwProcessID);
    if(hTarget)
    {
        char s[50];
        HWND hWnd = ::FindWindowEx(hTarget,NULL,"EDIT","");
        ::GetWindowText(hWnd,s);
    }
      

  3.   

    不是CWnd的GetWindowText,而是系统API
      

  4.   

    已经知道外部程序的CEDIT的ID是IDC_EDIT1
    该如何得到IDC_EDIT1的句柄呢?
      

  5.   

    请问:forover(天下无吥散dě宴席)
    能否详细一些,谢谢!
      

  6.   

    汗,我上面不是帖出来了吗
    下面这句
    HWND hWnd = ::FindWindowEx(hTarget,NULL,"EDIT","");
      

  7.   

    问题是我不只是一个CEDIT,有许多个,不知道哪个对哪个
    HWND hWnd = ::FindWindowEx(hTarget,NULL,"EDIT","");
    得到的是哪个CEDIT的句柄呢?
      

  8.   

    这个:
    用EnumChildWindow函数,可以获得该窗口的每个子控件的HWND。
    然后在回调函数里面用GetDlgCtrlID( hWnd, nID);
    如果匹配,就可以进行相应的操作。
    绝对可以达到你的要求。
      

  9.   

    顺便说:如果要确定类型,可以用IsKindOf( RUNTIME_CLASS(...))来做。
      

  10.   

    ::GetWindowText(hWnd,s);
    不行啊
      

  11.   

    hWnd = ::WindowFromPoint(point);//得到光标(point)所在点的窗口句柄
      

  12.   

    EnumChildWindow()不可能不行啊
      

  13.   

    HWND hWnd =::FindWindowEx(hTarget,NULL,"CEdit","");
    if(hWnd)
    {
      AfxMessageBox("找到了!");
    }
    else
    {
      AfxMessageBox("找不到句柄!");
    }
    结果找不到句柄!
    也不知道是哪里错了?
      

  14.   

    CString strText;
    char s[50];
    HWND hWnd =::FindWindowEx(hTarget,NULL,"Edit","");
    if(hWnd)
    {
      ::GetDlgItemText(hWnd2,IDC_EDIT1,s,40);
      strText.Format("%s",s);
      AfxMessageBox(strText);
    }句柄已经得到了
    可是还是得不到IDC_EDIT1的内容
      

  15.   

    ::GetDlgItemText(hWnd2,IDC_EDIT1,s,40);hWnd2 哪冒出来D?应该是hWnd吧加上UpdateData( TRUE )试下
      

  16.   

    char szText[256];
    memset(szText,0,256);
    ::SendMessage(hTarget,WM_GETTEXT,(WPARAM)256,(LPARAM)szText);
    printf("%s\n",szText);
      

  17.   

    感谢 bobob(静思)(PDFViewer2.0 Release拉!) 的答案
    可以获取内容了
    不过还不是我想要的IDC_EDIT1的内容
    有三个CEDIT,分别是IDC_EDIT1,IDC_EDIT2,IDC_EDIT3
    我只想得到IDC_EDIT1的内容
      

  18.   

    if(IDC_EDIT1 == GetDlgCtrlID(hTarget))
    {
    char szText[256];
    memset(szText,0,256);
    ::SendMessage(hTarget,WM_GETTEXT,(WPARAM)256,(LPARAM)szText);
    printf("%s\n",szText);
    }
      

  19.   

    GetDlgItemText
    The GetDlgItemText function retrieves the title or text associated with a control in a dialog box. UINT GetDlgItemText(
      HWND hDlg,       // handle to dialog box
      int nIDDlgItem,  // control identifier
      LPTSTR lpString, // pointer to buffer for text
      int nMaxCount    // maximum size of string
    );
      

  20.   

    if(IDC_EDIT1 == GetDlgCtrlID(hTarget))
    {
    char szText[256];
    memset(szText,0,256);
    ::SendMessage(hTarget,WM_GETTEXT,(WPARAM)256,(LPARAM)szText);
    printf("%s\n",szText);
    }这个判断是没错!
    可是该如何遍历每个符合
    HWND hWnd =::FindWindowEx(hTarget,NULL,"Edit",NULL);
    的控件呢?
      

  21.   

    枚举窗口
    #include <windows.h>
    #include <STDIO.H>
    BOOL myEnumWindow(HWND hwnd);
    int  main()
    {
    myEnumWindow(hDlg);//这里给dialog的句柄
    return 0;
    }BOOL myEnumWindow(HWND inHwnd)
    {
    char szText[256];HWND hTarget= NULL;
    while(hwndAfter = ::FindWindowEx(inHwnd,hTarget,NULL,NULL))
    {
    if(IDC_EDIT1 == GetDlgCtrlID(hTarget))
    {
    memset(szText,0,256);
    ::SendMessage(hTarget,WM_GETTEXT,(WPARAM)256,(LPARAM)szText);
    printf("%s\t",szText);
    }
    }
    return 1;
    }
      

  22.   

    你这是枚举窗口
    我要的是枚举一个窗口里的所有符合Edit的控件
      

  23.   

    bobob的方法是对的,EDIT也是窗口啊。
      

  24.   

    自己写去吧
    The GetDlgItem function retrieves a handle to a control in the specified dialog box. HWND GetDlgItem(
      HWND hDlg,       // handle to dialog box
      int nIDDlgItem   // control identifier
    );
    Parameters
    hDlg 
    [in] Handle to the dialog box that contains the control. 
    nIDDlgItem 
    [in] Specifies the identifier of the control to be retrieved. 
    Return Values
    If the function succeeds, the return value is the window handle of the specified control. If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.
      

  25.   

    先获得外部程序的句柄,再发送消息GetWindowText