TCHAR buf[WINDOW_TEXT_LENGTH];  
SendMessage(hWnd, WM_GETTEXT, WINDOW_TEXT_LENGTH, (LPARAM)buf);  
wprintf(L"%s/n", buf);  
TRACE("控件子窗口名字!--");OutputDebugString(buf);TRACE("\r\n"); CString strtemp=_T("");
CWnd* p = CWnd::FromHandle(hWnd);
p->GetWindowText(strtemp);
TRACE("窗口名字!--");OutputDebugString(strtemp);TRACE("\r\n");

解决方案 »

  1.   

    GetWindowText内部貌似也是发送WM_GETTEXT消息
      

  2.   

    两个确实出现了不一样的现象窗口所在进程的id:0x00000534 1332窗口的id:0x00010eea  69354窗口名字!--testwindow
    窗口名字!--testwindow控件所在进程的id:0x00000534 1332控件子窗口的id:0x00010eee 69358控件子窗口名字!--OK
    窗口名字!--OK控件所在进程的id:0x00000534 1332控件子窗口的id:0x00010ef0 69360控件子窗口名字!--Button1
    窗口名字!--Button1窗口所在进程的id:0x00000534 1332窗口的id:0x00010ef2  69362窗口名字!--Mutton1
    窗口名字!--M窗口所在进程的id:0x00000534 1332窗口的id:0x00010eec  69356窗口名字!--Default IME
    窗口名字!--Default IME以上为我自己跟踪程序的结果,该程序是由我自己写的。里面的窗口有个叫mutton1的,拿到了两个不同的名字
      

  3.   

    MSDN上说的很清楚If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to be sent to the specified window or control. If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text. If the window does not have a caption, the return value is a null string. This behavior is by design. It allows applications to call GetWindowText without becoming unresponsive if the process that owns the target window is not responding. However, if the target window is not responding and it belongs to the calling application, GetWindowText will cause the calling application to become unresponsive. To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead of calling GetWindowText. 
      

  4.   

    visual evleven 总是这么犀利,还好我英语过关,对了,照片是你的姑娘