• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 通過鼠標(biāo)動(dòng)作來發(fā)出命令的代碼

    通過鼠標(biāo)動(dòng)作來發(fā)出命令的代碼

    作者: 時(shí)間:2012-06-26 來源:網(wǎng)絡(luò) 收藏

    在一些比較不錯(cuò)的瀏覽器中,出現(xiàn)了一些新的功能,(也稱手勢(shì)Mouse Gestures)來一些,比如opera,myie2.一般是這樣,先按住右鍵,不要松,然后畫直線或者其他設(shè)定的路徑,就可以完成指定的。下面我們就來實(shí)現(xiàn)這個(gè)功能,具體的核心來自共享軟件聯(lián)盟小樹沖浪瀏覽器中,整理改編了其中的一些地方。

    本文引用地址:http://www.czjhyjcfj.com/article/148846.htm

      1.建立一個(gè)對(duì)話框程序,聲明以下變量和函數(shù)

      BOOL m_bIsCapture;//一個(gè)標(biāo)志變量

      char m_MouseGestures[4], m_SeqMG[4];//用來保存鼠標(biāo)U(上) D(下)等..

      int m_iMGLen;

      int m_iMouseGS, m_iMouseGE;

      POINT m_StartPoint; //鼠標(biāo)的坐標(biāo)點(diǎn)

      BOOL MoveDirection(CPoint point, char* Direction); //判斷鼠標(biāo)的簡(jiǎn)單,四個(gè),上下左右

      void PushMouseGesture(char gesture);//把鼠標(biāo)動(dòng)作的保存起來

      2.在對(duì)話框中加一個(gè)文本框,增加它的CString變量,m_mouse,用來顯示鼠標(biāo)的動(dòng)作

      3.重載OnMouseMove的函數(shù),如下

      if( nFlags == MK_RBUTTON) //判斷時(shí)候鼠標(biāo)右鍵按下

      {

      if (m_bIsCapture) //初始的值的TRUE, 只有當(dāng)?shù)谝稽c(diǎn)的時(shí)候發(fā)生里面的動(dòng)作

      {

      m_bIsCapture=FALSE;

      SetCapture(); //捕獲鼠標(biāo)

      m_StartPoint = point; //記錄初始坐標(biāo)點(diǎn)

      }

      char dir;

      if(MoveDirection(point, dir)) //調(diào)用函數(shù)

      {

      PushMouseGesture(dir);

      m_StartPoint = point;

      }

      }

      CDialog::OnMouseMove(nFlags, point);

      }

      4.判斷鼠標(biāo)動(dòng)作的函數(shù) (核心),個(gè)人認(rèn)為是很巧妙而且簡(jiǎn)單的算法:

      BOOL Cmouse2Dlg::MoveDirection(CPoint point, char *Direction)

      {

      int x = point.x - m_StartPoint.x;

      int y = point.y - m_StartPoint.y;

      int dist = x*x+y*y;

      if(dist>64)

      {

      if(x>abs(y) x>0)

      *Direction = RBUT_RIGHT;

      else if(abs(x)>abs(y) x0)

      *Direction = RBUT_LEFT;

      else if(y>abs(x) y>0)

      *Direction = RBUT_DOWN;

      else if(abs(y)>abs(x) y0)

      *Direction = RBUT_UP;

      else

      return FALSE;

      return TRUE;

      }

      else

      return FALSE;

      }

      5.PushMouseGesture函數(shù)

      這個(gè)函數(shù)主要是將鼠標(biāo)的動(dòng)作保存到m_MouseGestures中,等以后調(diào)用

      if(m_iMouseGE!=0 || m_iMouseGS !=0) //m_iMouseGS和m_iMouseGE初始為0

      {

      int pre = (m_iMouseGE -1 + m_iMGLen)m_iMGLen;

      if(m_MouseGestures[pre] == gesture)

      return;

      }

      m_MouseGestures[m_iMouseGE] = gesture;

      m_iMouseGE = (m_iMouseGE+1)m_iMGLen;

      if(m_iMouseGS == m_iMouseGE)

      m_iMouseGS = (m_iMouseGS + 1)m_iMGLen;



    評(píng)論


    相關(guān)推薦

    技術(shù)專區(qū)

    關(guān)閉
    主站蜘蛛池模板: 乌苏市| 南皮县| 赣州市| 渑池县| 水城县| 盐山县| 南丹县| 遂平县| 石景山区| 武城县| 腾冲县| 且末县| 嵩明县| 岳阳市| 天峻县| 周至县| 长春市| 北辰区| 三穗县| 本溪| 元江| 鹤峰县| 建湖县| 洞口县| 金堂县| 平谷区| 虞城县| 江油市| 隆德县| 航空| 柞水县| 长顺县| 崇州市| 龙岩市| 阳泉市| 厦门市| 南投县| 荔浦县| 黄骅市| 马鞍山市| 叙永县|