各位大虾,小弟在子类化edit控件的时候遇到点麻烦,
我在 WM_INITDIALOG 消息下将一个edit 控件子类化:hEdit = GetDlgItem(hDlg,IDC_EDIT1);
lpOldEditProc = (WNDPROC)SetWindowLong(hEdit,GWL_WNDPROC,(LONG)EditProc);自定义的窗口过程如下:LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CHAR:
MessageBox(hFrontWnd,"hfddf","dfhjdf",MB_OK);
break;
default:
CallWindowProc(lpOldEditProc,hWnd,message, wParam, lParam);
return 1; }
return 0;
}编译能通过,但一运行就堆栈溢出,就在EditProc里出d的错,当我删掉SetWindowlong那一句后,程序就能运行正常了.请各位帮忙解决一下.当然,如果有谁能给出关于SetWindowLong函数的列程那就再好不过了~

解决方案 »

  1.   

    大哥们,帮帮忙吧~,有SetWindowLong函数的列程也行!
      

  2.   

    改成如下,没有出现你所说的问题
    pOldEditProc = (WNDPROC)SetWindowLong(hEdit->m_hWnd ,GWL_WNDPROC,(LONG)EditProc);但是WM_CHAR你映射了也没有用,当键被按下时,不会发送WM_CHAR给你的程序.
    映射WM_KEYDOWN还是可以的.
      

  3.   

    default:
    return CallWindowProc(lpOldEditProc,hWnd,message, wParam, lParam);
    改为这样试试,你无论什么消息都返回1这不太妥当.
      

  4.   

    ylredsun兄,哪个hEdit->m_hWnd 是啥意思呀,
     _foo(void)兄,我照你那样改了,但还是老样子,不过还是要谢谢大家
      

  5.   

    The SetWindowLong function changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory. Note  This function has been superseded by the SetWindowLongPtr function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use SetWindowLongPtr. LONG SetWindowLong(
      HWND hWnd,       // handle to window
      int nIndex,      // offset of value to set
      LONG dwNewLong   // new value
    );
    m_hWnd是CWnd的一个数据成员,它存放的是指向的当前窗口的句柄.
      

  6.   

    你综合我的和 
    _foo(void)            //莫名函数:) ( ) 
    的进行修改就行了.不行的话,你找我算帐吧.pOldEditProc = (WNDPROC)SetWindowLong(hEdit->m_hWnd ,GWL_WNDPROC,(LONG)EditProc);LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message)
    {
    case WM_CHAR:
    AfxMessageBox("hfddf"); //这一句我改了你的,为了在我这么编译通过.
    break;
    default:
    return CallWindowProc(pOldEditProc,hWnd,message, wParam, lParam); }
    return 0;
    }
      

  7.   

    大哥,我没有用MFC呀.不过还是谢谢大家