2 u010400666 u010400666 于 2013.09.12 11:39 提问

谁能帮我讲解一下这个函数内容(Hook知识不用说了),非常感谢

//定义钩子函数,对按钮控件子类化
LRESULT CALLBACK HOOKProc( int nCode, WPARAM wParam, LPARAM lParam )
{
PCWPSTRUCT wc = (PCWPSTRUCT) lParam;
HWND hWnd = wc->hwnd;
if( hWnd )
{
char ClassName[MAX_PATH] = "";
GetClassName( hWnd, ClassName, MAX_PATH );
if( strcmp( ClassName, "Button" ) == 0 )
{
CWnd *pWnd = CWnd::FromHandle( hWnd );

        if ( pWnd->GetStyle() & BS_RADIOBUTTON )
        {
            return 1;
        }
        if ( pWnd->GetStyle() & BS_CHECKBOX )
        {
            return 1;
        }

        WNDPROC WndProc;
        WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );

        CDrawButton *pButton=(CDrawButton*)GetWindowLong(hWnd,GWL_USERDATA);

        if (pButton != NULL&& pButton->m_Flag==1 )
        {
            SetWindowLong(hWnd,GWL_USERDATA,0);
            SetWindowLong( hWnd, GWL_WNDPROC, (LONG)pButton->m_OldProc );

            pButton->m_OldProc = NULL;
            delete pButton;
        }
        else if (pButton == NULL ) 
        {
            if( WndProc !=DefWindowProc1 )
            {
                pButton = new CDrawButton;
                pButton->m_OldProc = WndProc;
                SetWindowLong(hWnd,GWL_USERDATA,(long)pButton);
                WndProc =  (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) DefWindowProc1);
            }
        }
    }
}
return CallNextHookEx( hWndHook, nCode, wParam, lParam );

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!