SendMessage(WM_VSCROLL,MAKEWPARAM(bUp?SB_LINEUP:SB_LINEDOWN,0),0);
我刚学MFC没多久,对这段代码有些不解:1.MAKEWPARAM宏怎么用?在本段代码里起什么作用?
                                     2.貌似SendMessage将激活消息映射WM_VSCROLL的响应函数,若是,那么SendMessage将什么信息传递给那个响应函数?
在MSDN里也查过,但是仍然不太理解,请高手赐教,非常感谢!

解决方案 »

  1.   

    SendMessage是一个win32的API,这里是一个MFC封装函数,是给某某HWND窗口发送消息的。
    你应该看看Windows编程等书籍。
      

  2.   

    制作wParam参数
    SB_LINEUP, SB_LINEDOWN 将滚动框调整一个单位的位置
      

  3.   

    报告楼上兄台,现在正在看MFC windows 程序设计,这句代码也是这本书上的,但是此书对这句代码没有解释,所以在到坛子里发问。
      

  4.   

    主要是对MAKEWPARAM宏的用法,还有SendMessage与WM_VSCROLL响应函数的通信方式不理解
      

  5.   

    CWnd::SendMessage
    LRESULT SendMessage( UINT message, WPARAM wParam = 0, LPARAM lParam = 0 );Return ValueThe result of the message processing; its value depends on the message sent.ParametersmessageSpecifies the message to be sent.wParamSpecifies additional message-dependent information.lParamSpecifies additional message-dependent information.ResSends the specified message to this window. The SendMessage member function calls the window procedure directly and does not return until that window procedure has processed the message. This is in contrast to the PostMessage member function, which places the message into the window’s message queue and returns immediately. 
    MAKEWPARAM宏的说明:
    The MAKEWPARAM macro creates a value for use as a wParam parameter in a message. The macro concatenates the specified values. WPARAM MAKEWPARAM(
      WORD wLow, 
      WORD wHigh 
    );
    Parameters
    wLow 
    Specifies the low-order word of the new value. 
    wHigh 
    Specifies the high-order word of the new value. 
    Return Values
    The return value is a WPARAM value. 
    建议好好利用MSDN,学会利用MSDN,强化英语
      

  6.   

    对于MAKEWPARAM宏就不多说了SendMessage与WM_VSCROLL响应函数的通信方式不理解
    就是发消息之后直接响应WM_VSCROLL,简单的说就是调用OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
      

  7.   

    多谢楼上兄台,现在还有个疑问就是MAKEWPARAM(bUp?SB_LINEUP:SB_LINEDOWN,0)对OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 产生了怎样的影响?与OnVScroll函数中的那个参数对应?
      

  8.   

    MSDN里说MAKEWPARAM(bUp?SB_LINEUP:SB_LINEDOWN,0)将返回一个WPARAM value,在这个返回的WPARAM value是什么?与OnVScroll函数中的那个参数对应?
      

  9.   

    afx_msg void CWnd::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar );nSBCode:SB_BOTTOM   Scroll to bottom.SB_ENDSCROLL   End scroll.SB_LINEDOWN   Scroll one line down.SB_LINEUP   Scroll one line up.SB_PAGEDOWN   Scroll one page down.SB_PAGEUP   Scroll one page up.SB_THUMBPOSITION   Scroll to the absolute position. The current position is provided in nPos.SB_THUMBTRACK   Drag scroll box to specified position. The current position is provided in nPos.SB_TOP   Scroll to top
      

  10.   

    多谢楼上兄台。MSDN里说MAKEWPARAM(bUp?SB_LINEUP:SB_LINEDOWN,0)将返回一个WPARAM value,这里返回的WPARAM value应该是SB_LINEUP或SB_LINEDOWN吧?我对MAKEWPARAM的用法不理解。
      

  11.   

    MAKEWPARAM宏里的高字和低字两者有什么区别呢?
      

  12.   

    MAKEWPARAM(bUp?SB_LINEUP:SB_LINEDOWN,0),这里为什么只设置低字不使用高字呢?
      

  13.   

    #define MAKELONG(a, b)      ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
    #define MAKEWPARAM(l, h)      (WPARAM)MAKELONG(l, h)//每条消息的高字和低字都有不同的定义,使用之前应查看MSDN。------------------------------------------------------------------------WM_VSCROLL 
    nScrollCode = (int) LOWORD(wParam); // scroll bar value 
    nPos = (short int) HIWORD(wParam);  // scroll box position 
    hwndScrollBar = (HWND) lParam;      // handle to scroll bar nPos 
    Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used. //高字(即:nPos),只有在 SB_THUMBPOSITION 或 SB_THUMBTRACK 才需要使用,所以如果是SB_LINEUP 或 SB_LINEDOWN 就不用设置了。
      

  14.   

    非常非常感谢,今后我会好好利用MSDN。