旅途

如果想飞得高,就该把地平线忘掉

几种获取 EDIT 文本的方法

1. GetWindowText
2. SendMessage

//刚刚发现,这个有问题。
//无法成功。。。,不知为什么
//3. DispatchMessage
//MSG msg;
//msg.hwnd = hedit;
//msg.message = WM_GETTEXT;
//msg.wParam = (WPARAM)cchTextMax;
//msg.lParam = (LPARAM)lpszText;
//DispatchMessage(&msg);

4.GetWindowLong
LONG lWndProc;
if (NULL != (lWndProc = GetWindowLong(hedit, GWL_WNDPROC)))
  CallWindowProc((WNDPROC)lWndProc, hedit, WM_GETTEXT, (WPARAM)cchTextMax, (LPARAM)lpszText);

 

6.GetClassInfo、GetClassInfoEx(两者有部分差异)
//GetClassInfo
WNDCLASS wc;
GetClassInfo(hInstance, "EDIT", &wc);
CallWindowProc(wc.lpfnWndProc, hedit, WM_GETTEXT, (WPARAM)cchTextMax, (LPARAM)lpszText);
//GetClassInfoEx 参看 GetClassInfo

 

6.自己写 EDIT 窗口文本获取的处理过程
可以从 windows 的源码中发现, 我在 editec.c 和 edecrare.c 中摘的,详细情况自己看吧 ^_^
case WM_GETTEXT:

        /*
         * wParam - max number of _bytes_ (not characters) to copy
         * lParam - buffer to copy text to. Text is 0 terminated.
         */
        lreturn = (LONG)ECGetText(ped, wParam, (LPSTR)lParam, TRUE);
        break;
/////////////////////////////////////////////////////////////////////////////
/***************************************************************************\[!--empirenews.page--]
* ECGetText AorW
*
* Copies at most maxCchToCopy chars to the buffer lpBuffer. Returns
* how many chars were actually copied. Null terminates the string based
* on the fNullTerminate flag:
* fNullTerminate --> at most (maxCchToCopy - 1) characters will be copied
* !fNullTerminate --> at most (maxCchToCopy) characters will be copied
*
* History:
\***************************************************************************/

ICH ECGetText(
    PED ped,
    ICH maxCchToCopy,
    LPSTR lpBuffer,
    BOOL fNullTerminate)
{
    PSTR pText;

    if (maxCchToCopy) {

        /*
         * Zero terminator takes the extra byte
         */
        if (fNullTerminate)
            maxCchToCopy--;
        maxCchToCopy = min(maxCchToCopy, ped->cch);

        /*
         * Zero terminate the string
         */
        if (ped->fAnsi)
            *(LPSTR)(lpBuffer + maxCchToCopy) = 0;
        else
            *(((LPWSTR)lpBuffer) + maxCchToCopy) = 0;

        pText = ECLock(ped);
        RtlCopyMemory(lpBuffer, pText, maxCchToCopy*ped->cbChar);
        ECUnlock(ped);
    }

    return maxCchToCopy;
}

PHP has encountered an Access Violation at 01F80AFD

posted on 2007-07-18 00:35 旅途 阅读(736) 评论(0)  编辑 收藏 引用 所属分类: 深入windows


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理