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

📄 tchstub.cpp

📁 Windows CE下的触控屏驱动程序源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                begTick-_dwLastSendedTick>dwMinPauseBeforeClick)) ) 
            {  //Yes, it's initial delay
             BOOL bPermition = TRUE;
               if((_iClientFlags&(TABLET_SEND|TABLET_NEED_PERMITION))!=0)
                  bPermition = (BOOL)SendMessage(_hClientWnd, WM_PEGREC_STARTDELAY, (WPARAM)GetForegroundWindow(), MAKELPARAM(_begX, _begY));
               else
                  PostMessage(_hClientWnd, WM_PEGREC_STARTDELAY, (WPARAM)GetForegroundWindow(), MAKELPARAM(_begX, _begY));
               if((_iClientFlags&TABLET_NEED_PERMITION)==0 || bPermition)
                  {
                     _iClientFlags |= TABLET_ALL_TO_SYSTEM;
                     _iClientFlags  &= (~TABLET_SMART_TO_SYSTEM);
                     FlagsToDll = 0x07;
                     bDelay = TRUE;
                  }
               else
                  {
//                   _iClientFlags = 0; //skip this stroke
                     _iClientFlags &= (~TABLET_STARTDELAY_TO_SYSTEM);
                  }

               _dwLastSendedTick = 0;
            }


         // IS SECONDARY DELAY?  (end of a stroke)
         if( !bNear                                      &&
             Flags==0x0f   /*intermediate point*/       &&
             (_iClientFlags&TABLET_INTERDELAY_TO_SYSTEM)!=0)
            if(iLastDelayX-X<iMaxDelayDist && X-iLastDelayX<iMaxDelayDist &&
               iLastDelayY-Y<iMaxDelayDist && Y-iLastDelayY<iMaxDelayDist)
               { //Yes, it is
                  if(dwTick - dwLastDelayTick > dwMinInterDelayTime)
                     {
                      BOOL bPermition = TRUE;
                        if((_iClientFlags&(TABLET_SEND|TABLET_NEED_PERMITION))!=0)
                           bPermition = (BOOL)SendMessage(_hClientWnd, WM_PEGREC_ENDDELAY, (WPARAM)GetForegroundWindow(), MAKELPARAM(_begX, _begY));
                        else
                           PostMessage(_hClientWnd, WM_PEGREC_ENDDELAY, (WPARAM)GetForegroundWindow(), MAKELPARAM(_begX, _begY));

                        if((_iClientFlags&TABLET_NEED_PERMITION)==0 || bPermition)
                           {
                              _iClientFlags |= TABLET_ALL_TO_SYSTEM;
                              _iClientFlags  &= (~TABLET_SMART_TO_SYSTEM);
//                              _iClientFlags  &= (~TABLET_ALL_TO_CLIENT);
                              FlagsToDll = 0x07;
                              X=_begX;
                              Y=_begY;
                              _dwLastSendedTick = 0;
                              bDelay = TRUE;

//                              DeferedDelay = TRUE;
                           }
                        else
                           {
//                           _iClientFlags = 0; //skip this stroke
                              _iClientFlags &= (~TABLET_INTERDELAY_TO_SYSTEM);
                           }

//                        SendMessage(_hClientWnd, WM_PEGREC_CLEARTRACE, 0, 1);
                     }
               }
            else
               { // new delay point
                  iLastDelayX = X;
                  iLastDelayY = Y;
                  dwLastDelayTick = dwTick;
               }

      } // endif "smart"

   // TO ORIGINAL DLL CALLBACK 
   if((_iClientFlags&TABLET_ALL_TO_SYSTEM)!=0)
      {
         (*v_pfnCgrPointCallback)(FlagsToDll, X, Y);
      }

   // TO The Transcriber App window
   if((_iClientFlags&TABLET_ALL_TO_CLIENT)!=0)
      {

         // it should be here because of possible _dwLastSendedTick changing
         if(Flags == 0x0d && !bClick && !bDelay)
            _dwLastSendedTick = dwTick;

#if DISCARD_SIMILAR_POINTS    
		 // Alex says safe to leave out - originally placed here to avoid overloading
		 //  slower processors.
		 // throw away redundant points (pen didn't move far enough within small time)
         if((FlagsToWnd&TouchSampleDownFlag)!=0)
            {
             int X0 = _iLastProceedX, Y0 = _iLastProceedY;
             
			 _iLastProceedX = X;
             _iLastProceedY = Y;
             _iLastProceedFlags = FlagsToWnd;
             
			 if((FlagsToWnd&TouchSamplePreviousDownFlag)!=0)
                  { //only for internal points
                   int iSum;

				   X = X0;
				   Y = Y0;               

				   if(dwTick-_dwLastPostedToClient<1000)
                         {
                            iSum = abs(X - _iLastPostedX)+abs(Y - _iLastPostedY);
                            if(iSum<_iMinDist)
                               goto bypass_sendpoint;
                         }
//                      if(iSum>_iMaxDist)
//                         goto bypass_sendpoint;
                  }
             
			   _iLastPostedX = X;
               _iLastPostedY = Y;
            }
         else
            {
               if((FlagsToWnd&TouchSamplePreviousDownFlag)!=0 &&
                  (_iLastPostedX != _iLastProceedX || _iLastPostedY != _iLastProceedY))
                  {
                     if(abs(X - _iLastPostedX)+abs(Y - _iLastPostedY) < _iMaxDist)
                        {
                           _iLastPostedX = _iLastProceedX;
                           _iLastPostedY = _iLastProceedY;
                           SendPtToWnd(_iLastProceedFlags, _iLastProceedX, _iLastProceedY);
                        }
                  }
            }

#endif // DISCARD_SIMILAR_POINTS

         _dwLastPostedToClient  = dwTick;

         SendPtToWnd(FlagsToWnd, X, Y);

//bypass_sendpoint:
        ;

//       if(Flags == 0x0d && !bClick && !bDelay)
//          _dwLastSendedTick = dwTick;
      }
#ifdef DEBUG2
      else
	  {
         OutputDebugString(L"CgrTouch Point 4\n");
      }
#endif

 	return;
}

void CgrTouchStubInitialize(HANDLE hinstDll) {

	TCHAR		*pOldDriverName = DEFAULT_TOUCH_DRIVER_NAME;
	SECURITY_ATTRIBUTES     SecAttr;
	ULONG		iSize = 0;
	DWORD       dwResult;

   // This code was all written originally with the (bad) assumption that
   //  if two processes load the same DLL, the dll shares global variables.
   //  In Win32, that assumption is not true. So, for the global variables
   //  that must be shared, we enforce the shared memory by using a MemoryMappedFile
   //  Both processes will attempt to create a MMF - whoever gets there first creates,
   //  whoever gets there second will open the existing MMF.
   //  so far, we need to put *_phStubWnd and the outer touch queue into the MMF area.
   //  This is really a bit of a misnomer since we never have a real file, just a memory object.
   //  might have to set SEC_NOCACHE for the ARM if there are cache coherency problems
   iSize = sizeof(HANDLE) + sizeof(HWND) + sizeof(TOUCH_QUEUE);
   _hFileMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, iSize, 
	                                 TEXT("TranscriberSharedGlobals"));
   dwResult = GetLastError();
   if (NULL == _hFileMapping)
   {
	  MYERRORMSG(1, (__TEXT("Transcriber driver couldn't create shared global memory area.\r\n")));
	  return;
   }

   _pView = MapViewOfFile(_hFileMapping, FILE_MAP_WRITE, 0, 0, 0);
   if (NULL == _pView)
   {
	  MYERRORMSG(1, (__TEXT("Transcriber driver couldn't access shared global memory area.\r\n")));
	  return;
   }

   // once we make it to here, _pView can be used as a base pointer to the global area.


   _hClientWnd=NULL;
   _iClientFlags=TABLET_ALL_TO_SYSTEM;

   SecAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
   SecAttr.lpSecurityDescriptor = NULL;
   SecAttr.bInheritHandle = TRUE;
   g_hTabletEvent = CreateEvent(&SecAttr, TRUE, TRUE, L"CgrTabletEvent");
   g_hInnerEvent  = CreateEvent(&SecAttr, TRUE, TRUE, L"CgrTabletInnerEvent");

   // initialize the thread safety objects
   InitializeCriticalSection(&Q2CritSect);
   hQ1Mutex = CreateMutex(NULL, FALSE, TRANSCRIBER_Q1MUTEX);
#ifdef DEBUGTOUCH
   InitializeCriticalSection(&csErrMsg);
#endif // DEBUGTOUCH

   // get a pointer that we can share out for the shared queue
   //@future - I should have a more elegant way for doing this than byte offset
   //  when I add more elements, go to a struct
   // LAYOUT - the hwnd occupies the low 4 bytes of shared memory.
   //  The touch queue starts after that.
   ptq = (TOUCH_QUEUE*)((BYTE*)_pView + sizeof(HWND) + sizeof(HANDLE));
   _phinstDll = (HANDLE *)((BYTE*)_pView + sizeof(HWND));
   _phStubWnd = (HWND*) _pView;
   if (dwResult != ERROR_ALREADY_EXISTS) {
       ptq->iPut = ptq->iGet = 0;  
       tq2.iPut = tq2.iGet = 0;  
       *_phinstDll = NULL;
   }
   if (*_phinstDll == NULL) *_phinstDll = hinstDll;
     //  if(!FindWindow(TOUCHSTUB_WNDCLASSNAME, NULL))
     {
      DWORD dwIDThread;
        if(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)TchWindowThread, (LPVOID)hinstDll, 0, &dwIDThread)==NULL )
			 {
            MYERRORMSG(1,
				   (__TEXT("Couldn't create touchstub window thread.\r\n")));
          }
        if(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)TchInnerThread, (LPVOID)hinstDll, 0, &dwIDThread)==NULL )
			 {
            MYERRORMSG(1,
				   (__TEXT("Couldn't create touchstub inner thread.\r\n")));
          }
     }


}

extern ULONG   culReferenceCount;              //@globalvar ULONG | culReferenceCount | Count of attached threads
extern PFN_TOUCH_PANEL_CALLBACK v_pfnPointCallback;
PFN_TOUCH_PANEL_CALLBACK v_pfnCgrCallback = CgrCallback;

/*++
Autodoc Information:

    @func BOOL | TouchPanelDllEntry |
    Dll entry point.

    @rdesc
    TRUE if the function succeeds. Otherwise, FALSE.

--*/
BOOL
TouchPanelDllEntry(
    HANDLE  hinstDll,    //@parm Process handle.
    DWORD   fdwReason,   //@parm Reason for calling the function.
    LPVOID  lpvReserved  //@parm Reserved, not used.
    )
{

    BOOL ReturnCode = TRUE;

    switch ( fdwReason )
    {
        case DLL_PROCESS_ATTACH:
            DEBUGREGISTER(reinterpret_cast<HINSTANCE>(hinstDll));
            DEBUGMSG( ZONE_FUNCTION, (TEXT("Dll Process Attach\r\n")) );

             //
             // Process is attaching.  We allow only 1 process to be attached.
             // If our global counter (maintained by the PDD) is greater than 0,
             //   error.
             //

            CgrTouchStubInitialize(hinstDll); // init calligrapher's part

            if (_phinstDll != NULL && *_phinstDll != hinstDll) break;
            if ( DdsiTouchPanelAttach() > 1 )
            {
                DEBUGMSG( ZONE_FUNCTION, (TEXT("DdsiTouchPanelAttach > 1\r\n") ) );
                DdsiTouchPanelDetach(); // if a process attach fails, the  detach is
                 // never called. So adjust the count here.
                ReturnCode = FALSE;
            }

            break;

        case DLL_THREAD_ATTACH:
            DEBUGMSG( ZONE_FUNCTION, (TEXT("Dll Thread Attach\r\n")) );

             //
             // Thread is attaching.  We allow only 1 thread to be attached.
             //
            if (_phinstDll != NULL && *_phinstDll != hinstDll) break;
            if ( ++culReferenceCount > 1 )
                ReturnCode = FALSE;
            break;

        case DLL_THREAD_DETACH:
            DEBUGMSG( ZONE_FUNCTION, (TEXT("Dll Thread Detach\r\n")) );

             //
             // Thread is detaching. If the detaching thread is the thread that
             // was allowed to attach, we now have no one to process touch panel
             // points. In this case we clear the callback functions, disable the
             // touch panel hardware, and disconnect from the logical interrupt.
             //

            if (_phinstDll != NULL && *_phinstDll != hinstDll) break;
            if ( --culReferenceCount == 0 )
            {
                v_pfnPointCallback = NULL;
                DdsiTouchPanelDisable();
                InterruptDisable( gIntrTouch );
//				if( SYSINTR_NOP != gIntrTouchChanged )
//               		InterruptDisable( gIntrTouchChanged );
            }
            break;

        case DLL_PROCESS_DETACH:
            DEBUGMSG( ZONE_FUNCTION,
                      (TEXT("Dll Process Detach\r\n")) );

            if (_phinstDll != NULL && *_phinstDll != hinstDll) break;

             //
             // Process is detaching.
             // If the detaching process is the process that was allowed
             // to attach, we reset the callback functions,
             // reference count, disable the touch panel, and disconnect from the
             // logical interrupt.
             //
             //
            DdsiTouchPanelDetach();
            break;
    }
    return ( ReturnCode );
}


#ifdef __cplusplus
   }
#endif //ifdef __cplusplus

⌨️ 快捷键说明

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