char str[255]="";
GetCursorPos(&point);
HWND hwnd=(HWND)WindowFromPoint(point);
long i=GetWindowLong(hwnd,GWL_STYLE);//为什么获取总是0??我设置了password属性
if(i&ES_PASSWORD)
{
::SendMessage(hwnd,WM_GETTEXT,255,(LPARAM)str);
SetDlgItemText(IDC_EDIT1,str);
}char str[255]="";
GetCursorPos(&point);
HWND hwnd=(HWND)WindowFromPoint(point);
long i=GetWindowLong(hwnd,GWL_STYLE);
::SendMessage(hwnd,WM_GETTEXT,255,(LPARAM)str);
SetDlgItemText(IDC_EDIT1,str);
改成这样还是不能获取文本!

解决方案 »

  1.   

    GetCursorPos(&point);
    point的值不对,是相对的,不是绝对。
    是相对于父窗体,如果是主窗体就是相对于荧屏,这往往就是错觉的来源。
      

  2.   

    是同一个程序的 edit 吗?外部程序的是不能这样做的。
      

  3.   

    选调试下看看hwnd中是否有值吧
      

  4.   

    WindowFromPoint
    The return value is a handle to the window that contains the point. If no window exists at the given point, the return value is NULL. If the point is over a static text control, the return value is a handle to the window under the static text control. hwnd 是指向IDC_EDIT1的嘛?
    取出IDC_EDIT1 中的handle 和你的hWnd比较下吧 是否一致。
      

  5.   

    至少密码框发WM_GETTEXT,外部程序是得不到的。
      

  6.   

    (HWND)WindowFromPoint(point)看到这里的类型强制,我就想你可能是在CWnd继承类来调用的,因此调用的是CWnd的成员函数,返回类型是CWnd*,不能强制转换为HWND。