⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tramousestub.cpp

📁 YLP270的Windows CE5.0 bsp源码。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* *********************************************************************************************** */
// This posts the point on the internal touch driver queue (Q2)
void SendPtToSelf(int iFlags, int iX, int iY)
{
 int iGet = 0;
 int iPut = 0;
 int i;

   if(_bIgnoreStroke2 &&
      (iFlags&TouchSamplePreviousDownFlag)!=0)
      {
        return; 
      }

   EnterCriticalSection(&Q2CritSect);

   iGet = tq2.iGet;
   iPut = tq2.iPut;
   
   if((iFlags&TouchSampleDownFlag)!=0)
      i = iGet - 3;
   else
      i = iGet - 2;

   // For the mouse driver, iX and iY are the mouse DELTA, not the current cursor location.
   //  So, before we pass the information to transcriber, we need the current cursor loc
   //  iX and iY have already been applied to the current cursor location by CgrCallback.
   POINT	pt;
   GetCursorPos(&pt);

   // danger - Hardcoded conversion!  Transcriber expects touch coordinates, which are 4 times the vertical
   //  and horizontal resolution of mouse coordinates.  We can't do anything about the resolution, but we 
   //  can scale the coordinates as transcriber expects.
   pt.x *= 4;
   pt.y *= 4;

   // now, in case we have to feed the points back to mouse_event, we need to save iX and iY, which
   //  are deltas.  We're going to pack them into the flags, along with the mouse flags, so we can
   //  recreate the mouse event.
   // FLAGS - hi byte - evfMouse flags 
   //         lo byte of hi word iX, 
   //         hi byte of lo word iY, 
   //         lo byte touch flags
   //  evfMouse flags are already encoded into the high byte of flags.  The byte of flags has the touch flags,
   //  which never use more than 5 bits (in our case 4, since we never set touch sample ignore.
   //  So, the middle two bytes are available.  We risk losing some bits if the mouse moved a long way,
   //  but that is super rare, and this is intended to be a working solution for testing instead of a shipping solution.
   //  DANGER - hardcoded conversion
  signed char byte;
   byte = static_cast<BYTE>(iX);
   iFlags |= (0x00FF0000 & (byte << 16));
   byte = static_cast<BYTE>(iY);
   iFlags |= (0x0000FF00 & (byte << 8));   

   // if there are at least 2 or 3 elements left for writing in the circular buffer (depn on iFlags)
   //  but why 2 or 3???  Does iGet not represent the real read pointer for the queue?
   //  perhaps we keep 2 or 3 old points available at all times in case we need them
   //  or maybe the code used to use them, but doesn't anymore
   if(iPut<i ||
      (iPut>=iGet && iPut<i+MAX_TOUCHQUEUE))
      {
         _bIgnoreStroke2 = FALSE;

         tq2.elems[iPut][0]=iFlags;
         tq2.elems[iPut][1]=((pt.x<<16)|pt.y);

         iPut++;
         if(iPut>=MAX_TOUCHQUEUE)
           iPut = 0;
         tq2.iPut = iPut;

		 // if both this point and the last point were pen down
         if((iFlags&(TouchSampleDownFlag|TouchSamplePreviousDownFlag))==
             (TouchSampleDownFlag|TouchSamplePreviousDownFlag))
            {
             int iiX = (pt.x>>3);
             int iiY = (pt.y>>3);
               if(iiX != _iLastSelfX || 
                  iiY != _iLastSelfY || 
                  _iInRow >10)
                  {
                     SetEvent(g_hInnerEvent);
                     _iInRow = 0;
                  }
               else
                  _iInRow++;
            }
         else
            {
               SetEvent(g_hInnerEvent);
               _iInRow = 0;
            }
      }
   else
   {
      _bIgnoreStroke2 = TRUE;
#ifdef DEBUG
      OutputDebugString(TEXT("Inner Queue Overrun!\n")); 
#endif
   }

   LeaveCriticalSection(&Q2CritSect);

}


/* *********************************************************************************************** */

LPVOID TouchGetQueuePtr()
{
   return ptq; //_pTouchQueue; //&tq;
}

BOOL IsStubWndExist()
{
   if(*_phStubWnd!=NULL || (*_phStubWnd=FindWindow(TOUCHSTUB_WNDCLASSNAME, NULL))!=NULL)
      return TRUE;
   else
      return FALSE;
}

HWND TouchGetFocusWnd()
{
   if(IsStubWndExist())
      return (HWND)SendMessage(*_phStubWnd, WM_STUB_GETFOCUSWND, 0, 0);
   return NULL;
}

HWND TouchGetLastTouchFocusWnd()
{
   if(IsStubWndExist())
      return (HWND)SendMessage(*_phStubWnd, WM_STUB_GETLASTTOUCHFOCUSWND, 0, 0);
   return NULL;
}

void TouchReset(BOOL bSetAllValuesToDefault)
{
   if(IsStubWndExist())
      SendMessage(*_phStubWnd, WM_STUB_RESET, bSetAllValuesToDefault, 0);
}

void TouchCreateEvent(int iX, int iY)
{
   if(IsStubWndExist())
      SendMessage(*_phStubWnd, WM_STUB_EVENT, iX, iY);
}

// transcriber uses this entry point to "give back" a click
void TouchCreateEventInternal(int begX, int begY)
{
	// danger, hardcoded conversion
	// pass the event back to the mouse code
	SetCursorPos(begX/4, begY/4);
	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, NULL);
	mouse_event(MOUSEEVENTF_MOVE, 0, 0, 0, NULL);
	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, NULL);
}

HWND TouchGetRegisteredWindow()
{
   return _hClientWnd;
}

BOOL TouchRegisterWindow(HWND hClientWnd)
{
	// set up permissions so we can access the buffer in the driver
	//  (which might be in slot 4, for example, while Tscriber is in slot 8)

	if (NULL == ptq)
		CgrMouseStubInitialize(NULL);

	if (NULL == ptq)
		return FALSE;

	ptq->iPut = ptq->iGet =0;
	tq2.iPut = tq2.iGet =0;

	// zero out the shared memory queue
	memset((void*) ptq, 0, sizeof(TOUCH_QUEUE));

	if(IsStubWndExist() && SendMessage(*_phStubWnd, WM_STUB_REGISTWND, (WPARAM)hClientWnd, 0))
		return TRUE;
	else
		return FALSE;
}

void TouchUnregisterWindow(HWND hClientWnd)
{
	if(IsStubWndExist())
        SendMessage(*_phStubWnd, WM_STUB_UNREGISTWND, (WPARAM)hClientWnd, 0);
}

void TouchSetValue(DWORD dwName, DWORD dwValue)
{
   if(IsStubWndExist())
      SendMessage(*_phStubWnd, WM_STUB_SETVALUE, dwName, dwValue);
}

LRESULT TouchGetValue(DWORD dwName, DWORD dwValue)
{
   if(IsStubWndExist())
      return SendMessage(*_phStubWnd, WM_STUB_GETVALUE, dwName, dwValue);
   return 0;
}


/* ************************************************************************** */
// this is where we get points from the mouse driver.  We return FALSE if we don't want them,
//  or, if we discover too late that we don't want them, we call mouse_event
BOOL
CgrCallback(
	TOUCH_PANEL_SAMPLE_FLAGS	Flags,
	INT	X,
	INT	Y,
	UINT evfMouse
    )
{
 DWORD dwTick;
 TOUCH_PANEL_SAMPLE_FLAGS FlagsToDll = Flags, FlagsToWnd = Flags;
#ifdef DEBUG1
 TCHAR str[100];
#endif

#if WRITE_STATISTICSLOG // define to log all points we get from hardware into a txt file
{
  static int _iStatWrites = 0;
  static int _iStatCurrent = 0;
  static short _iStatBuf[MAX_STATS][3] = {0};

if(_iStatWrites<=MAX_WRITES)
   {
    static int count = 0;

      _iStatBuf[_iStatCurrent][0] = (short)Flags;
      _iStatBuf[_iStatCurrent][1] = (short)X;
      _iStatBuf[_iStatCurrent][2] = (short)Y;
      _iStatCurrent++;
      
	  if(_iStatCurrent==MAX_STATS)
         {
          HANDLE hFile = INVALID_HANDLE_VALUE;
          int i;

 
		  
		  _iStatCurrent = 0;

             hFile = CreateFile(L"\\tchlog.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
             if(hFile!=INVALID_HANDLE_VALUE)
                {
                 DWORD dw = 0;
				 int   len;
				 int   j;
      
				 SetFilePointer(hFile, 0, NULL, FILE_END);

				   for (i = 0; i < MAX_STATS; i++)
				   {
				    TCHAR str[64];
					unsigned char str2[64];

                                wsprintf(str, L"%d %d %d %d %c%c", count++, (int)_iStatBuf[i][1], (int)(3000 - _iStatBuf[i][2]), (int)_iStatBuf[i][0], (TCHAR)13, (TCHAR)10); 
  		            
					len = _tcslen(str); 
					if(len > 62) 
						len = 62;

					for (j = 0; j < len; j ++) 
						str2[j] = (unsigned char)str[j]; 
					str2[len] = 0;
					
					WriteFile(hFile, str2, len, &dw, NULL);

				   }

                   CloseHandle(hFile);
                }

             _iStatWrites++;
         }
   }
}
#endif

   if (NULL == *_phStubWnd)
	IsStubWndExist();

   dwTick = GetTickCount();
   // Check if we need to send this point to system or transcriber.
   if( _hClientWnd==NULL || 
      *_phStubWnd==NULL ||
      (Flags&TouchSampleValidFlag)==0 ||
      (Flags&TouchSampleIgnore)!=0)
     {
         // if we already know that we don't want the point, give it back to the mouse driver by returning false
         return FALSE;           
     }

     // we need to package up and send along the w coordinate and the mouse flags, in case 
     //  the point needs to go back to the system (we don't know the answer to that question yet).
     //  So, we'll do this by ignoring the mouse wheel entirely - we'll always send "0" for the W (wheel) coordinate,
     //  and we'll save off the low byte of the mouse flags in our "Flags" variable, which has some extra room in the
     //  the high byte. (the high bytes of the mouse flags are mouse wheel stuff anyway, which we will mask off).
     //  This should be safe, because CgrCallback is only called when the left button is down (or just went up),
     //  and should not get a call for the mouse wheel.  However, just to be sure, we'll always check to make sure
     //  it isn't a wheel event before sending it back to mouse_event. (if a wheel event does come through while the
     //  left mouse button is down, it could concievably get lost...)
     Flags = Flags | (LOBYTE(LOWORD(evfMouse)) << 24);

     // If we do not call mouse event, it is up to us to update the cursor position 
     //  (call SetCursor).  We need to do this before the call to SendPtToSelf
     POINT pt;
     BOOL bRC;
     bRC = GetCursorPos(&pt);
     if (bRC)
     {
        pt.x += X;
        pt.y += Y;
        bRC = SetCursorPos(pt.x, pt.y);
        ASSERT(bRC);
	 }
     
     SendPtToSelf(Flags, X, Y);
     return TRUE;
}


/* *********************************************************************************** */
// This takes points off the internal Touch Driver queue (Q2) and decides where to send them 
//  - either to Transcriber, or back to the system
void StubCallback2(
   DWORD dwTick0,
	TOUCH_PANEL_SAMPLE_FLAGS	Flags,
	INT	X,
	INT	Y
    )
{
 DWORD dwTick = dwTick0;

 // take the high byte of flags and assign it to the mouse flags, evfMouse
 //  static cast is for sign extension
 UINT evfMouse = 0x000000FF & HIBYTE(HIWORD(Flags));
 signed char byte;
 byte = LOBYTE(HIWORD(Flags));
 int	  dxMouse = static_cast<int>(byte);
 byte = HIBYTE(LOWORD(Flags));
 int    dyMouse = static_cast<int>(byte);
 // mask off the mouse flags and deltas so that they don't get into our way
 //  this is safe because the touch flags use only the lowest 5 bits of "Flags"
 Flags = Flags & 0xFF;
 
 TOUCH_PANEL_SAMPLE_FLAGS FlagsToDll = Flags;
 TOUCH_PANEL_SAMPLE_FLAGS FlagsToWnd = Flags;

#if WRITE_STATISTICSINNER	// turn on to see points we place into the queue for the app
   {
    static int   _iStat1Writes = 0;
    static int   _iStat1Current = 0;
    static short _iStat1Buf[MAX_STATS][3] = {0};
    static int   count = 0;


      _iStat1Buf[_iStat1Current][0] = (short)Flags;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -