JS拖动技术--- 关于setCapture

<script type="text/javascript">
<!--
window.οnlοad=function(){
  objDiv = document.getElementById('drag');
  drag(objDiv);
};

function drag(dv){
  dv.οnmοusedοwn=function(e){
      var d=document;
      e = e || window.event;
     
      var x= e.layerX || e.offsetX;
      var y= e.layerY || e.offsetY;
     
      //设置捕获范围
      if(dv.setCapture){
          dv.setCapture();
      }else if(window.captureEvents){
          window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
      }
     

      d.οnmοusemοve=function(e){
           e= e || window.event;
           if(!e.pageX)e.pageX=e.clientX;
           if(!e.pageY)e.pageY=e.clientY;
           var tx=e.pageX-x;
           var ty=e.pageY-y;
          
           dv.style.left=tx;
           dv.style.top=ty;
      };

      d.οnmοuseup=function(){
           //取消捕获范围
           if(dv.releaseCapture){
              dv.releaseCapture();
           }else if(window.captureEvents){
              window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
           }
          
          //清除事件
          d.οnmοusemοve=null;
          d.οnmοuseup=null;
      };
   };
}
//-->
</script>

<div id="drag" style="position:absolute;left:12px;top:24px;width:100;height:150;border:1px solid #000000;z-index:1;background:#eeeeee">drag me</div>

转载出处:http://blog.csdn.net/fox123871/article/details/6630145

展开阅读全文

关于 CWnd::SetCapture 的问题

01-17

书上说,调用这个函数后,不管鼠标在什么地方都可以收到鼠标消息。rnrn但是,MSDN 在 CWnd::SetCapture 部分有这么句话:While mouse input is captured, no WM_NCHITTEST or WM_SETCURSOR messages are sent to the active window.rn这里又说收不到 WM_NCHITTEST 或 WM_SETCRUSORrnrn运行我下面的程序,程序一启动,鼠标光标居然成了沙漏型。鼠标移动的时候也有输出,这应该说明收到了 WN_NCHITTEST。程序只有在释放鼠标以后才能最大化、最小化。换句话说,如果不执行 ReleaseCapture 就不让鼠标有单击功能,但是却可以由鼠标移动功能rnrn[code=C/C++]rn#includernrnclass CMainWindow : public CFrameWndrnrnpublic:rn CMainWindow();rnprotected:rn afx_msg void OnMouseMove(UINT nFlags,CPoint point );rn afx_msg void OnLButtonDown( UINT nFlags, CPoint point );rn afx_msg LRESULT OnNcHitTest( CPoint point );rn afx_msg BOOL OnSetCursor( CWnd* pWnd, UINT nHitTest, UINT message );rnrn DECLARE_MESSAGE_MAP()rn;rnrnrn#include "CMainWindow.h"rnrnBEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)rn ON_WM_MOUSEMOVE()rn ON_WM_LBUTTONDOWN()rn ON_WM_NCHITTEST()rn ON_WM_SETCURSOR()rnEND_MESSAGE_MAP()rnCMainWindow::CMainWindow()rnrn Create(NULL,L"");rn SetCapture();rnrnvoid CMainWindow::OnMouseMove(UINT nFlags,CPoint point)rnrn TRACE(L"x=%d\ty=%d\n",point.x,point.y);rn CFrameWnd::OnMouseMove(nFlags,point);rnrnrnvoid CMainWindow::OnLButtonDown( UINT nFlags, CPoint point )rnrn ::ReleaseCapture();rnrnrnBOOL CMainWindow::OnSetCursor( CWnd* pWnd, UINT nHitTest, UINT message )rnrn TRACE(L"OnSetCursor\n");rn return CFrameWnd::OnSetCursor(pWnd, nHitTest, message);rnrnrnLRESULT CMainWindow::OnNcHitTest( CPoint point )rnrn TRACE(L"OnNcHitTest\n");rn return CFrameWnd::OnNcHitTest(point);rnrnrn[/code] 论坛

没有更多推荐了,返回首页