?? tramousestub.cpp
字號:
_iStat1Buf[_iStat1Current][1] = (short)X;
_iStat1Buf[_iStat1Current][2] = (short)Y;
_iStat1Current++;
if(_iStat1Current==MAX_STATS)
{
HANDLE hFile = INVALID_HANDLE_VALUE;
int i;
_iStat1Current = 0;
hFile = CreateFile(L"\\tchlogInner.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)_iStat1Buf[i][1], (int)(3000 - _iStat1Buf[i][2]), (int)_iStat1Buf[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);
}
}
}
#endif
// if we don't have a callig client window or bad sample or we are ignoring samples,
// pass back to the system (so the app "underneath" transcriber will get them)
if(_hClientWnd==NULL ||
(Flags&TouchSampleValidFlag)==0 ||
(Flags&TouchSampleIgnore)!=0)
{
// danger, hardcoded conversion
// pass the event back to the mouse code, unless it was a wheel event
// in which case, evfMouse will be 0, because the wheel flags got masked off
if (0 != evfMouse)
mouse_event(evfMouse, dxMouse, dyMouse, 0, NULL);
return;
}
// Intercept points here
// 1. test window at stroke begining
// 0x07 means pen down, valid, callib, but pen wasn't down for the previous pt
if(Flags==0x07)
{
if(!IsWindow(_hClientWnd))
{
_hClientWnd = NULL;
// danger, hardcoded conversion
// pass the event back to the mouse code, unless it was a wheel event
// in which case, evfMouse will be 0, because the wheel flags got masked off
if (0 != evfMouse)
mouse_event(evfMouse, dxMouse, dyMouse, 0, NULL);
return;
}
// set flags
_iClientFlags = (int)GetWindowLong(_hClientWnd, 0);
//just adjust
if((_iClientFlags&TABLET_TEST_FIRST_POINT)!=0 &&
!SendMessage(_hClientWnd, WM_PEGREC_FIRSTPOINT, 0, MAKELPARAM(X, Y)))
{
_iClientFlags = TABLET_ALL_TO_SYSTEM;
}
if((_iClientFlags&TABLET_SMART_TO_SYSTEM)!=0)
_iClientFlags = _iClientFlags&(~TABLET_ALL_TO_SYSTEM);
if((_iClientFlags&TABLET_SAVE_FOCUS_WND)!=0)
{
//@todo - do we need FindForegroundFocusWindow( ) instead of GetForegroundWindow( )?
_hLastTouchFocusWnd = GetForegroundWindow();
}
begTick = dwLastDelayTick = dwTick;
_begX = iLastDelayX = X;
_begY = iLastDelayY = Y;
bClick = FALSE;
bDelay = FALSE;
bNear = TRUE;
} // if(flgs==07)
if((_iClientFlags&TABLET_SMART_TO_SYSTEM)!=0)
{
// 2. Is still near?
if( bNear &&
Flags==0x0f /*inter point*/ &&
(Flags&TouchSampleDownFlag)!=0 &&
(_begX-X>=iMaxClickDist || _begX-X<=-iMaxClickDist ||
_begY-Y>=iMaxClickDist || _begY-Y<=-iMaxClickDist))
{ // decision = no click and no initial delay => stop NEAR
bNear = FALSE;
if((_iClientFlags&TABLET_SEND_RELEASE_MSG)!=0)
SendPtToWnd((TouchSamplePreviousDownFlag|TouchSampleDownFlag|TouchSampleIgnore), X, Y);
iLastDelayX = X;
iLastDelayY = Y;
dwLastDelayTick = dwTick;
{
HANDLE hThread=GetCurrentThread();
SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST);
}
}
// IS CLICK?
if( bNear &&
Flags==0x0d /*LAST PT*/ &&
(_iClientFlags&TABLET_CLICK_TO_SYSTEM)!=0 &&
dwTick-begTick < dwMaxClickTime &&
begTick-_dwLastSendedTick > dwMinPauseBeforeClick)
{ //yes - it's click
HWND hWndFgr = GetForegroundWindow();
BOOL bPermition = TRUE;
bClick = TRUE;
_dwLastSendedTick = 0;
if((_iClientFlags&(TABLET_SEND|TABLET_NEED_PERMITION))!=0)
bPermition = (BOOL)SendMessage(_hClientWnd, WM_PEGREC_MOUSECLICK, (WPARAM)hWndFgr, MAKELPARAM(_begX, _begY));
else
PostMessage(_hClientWnd, WM_PEGREC_MOUSECLICK, (WPARAM)hWndFgr, MAKELPARAM(_begX, _begY));
// simulate a click to the app "below" Transcriber (since we already ate the points)
if((_iClientFlags&TABLET_NEED_PERMITION)==0 || bPermition)
{
// danger, hardcoded conversion
// pass the event back to the mouse code, unless it was a wheel event
// in which case, evfMouse will be 0, because the wheel flags got masked off
if (0 != evfMouse)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, dxMouse, dyMouse, 0, NULL);
mouse_event(MOUSEEVENTF_MOVE, 0, 0, 0, NULL);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, NULL);
}
}
else
{
return;
}
}
// we delay points to see if we should either treat this as a selection or see if
// we should send the point to the application "underneath" Transcriber,
// or tap and hold.
// IS INITIAL DELAY?
if( bNear &&
Flags==0x0f /*intermediate point*/ &&
(_iClientFlags&TABLET_STARTDELAY_TO_SYSTEM)!=0 &&
(dwTick-begTick>1200 ||
(dwTick-begTick>dwMinStartDelayTime &&
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)
{
// danger, hardcoded conversion
// pass the event back to the mouse code, unless it was a wheel event
// in which case, evfMouse will be 0, because the wheel flags got masked off
if (0 != evfMouse)
mouse_event(evfMouse, dxMouse, dyMouse, 0, NULL);
}
// 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;
_dwLastPostedToClient = dwTick;
SendPtToWnd(FlagsToWnd, X, Y);
}
return;
}
void CgrMouseStubInitialize(HANDLE hinstDll) {
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;
g_hTabletEvent = CreateEvent(NULL, TRUE, TRUE, L"CgrTabletEvent");
g_hInnerEvent = CreateEvent(NULL, TRUE, TRUE, L"CgrTabletInnerEvent");
DEBUGCHK(g_hTabletEvent != NULL && g_hInnerEvent != NULL);
// initialize the thread safety objects
InitializeCriticalSection(&Q2CritSect);
hQ1Mutex = CreateMutex(NULL, FALSE, TRANSCRIBER_Q1MUTEX);
// 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;
// Touch driver is loaded by gwes process and transcriber process.
// Create the 2 worker threads in gwes process only.
// We can't call FindWindow here the way the touch driver stub does,
// because the API is not loaded at kbd/mouse driver init time. Just assume
// that our window is not already there (since this code runs at system startup time)
{
DWORD dwIDThread;
if(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MouseWindowThread, (LPVOID)hinstDll, 0, &dwIDThread)==NULL )
{
MYERRORMSG(1,
(__TEXT("Couldn't create touchstub window thread.\r\n")));
}
if(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MouseInnerThread, (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 HANDLE hThread;
#ifdef __cplusplus
}
#endif //ifdef __cplusplus
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -