?? tchwnd.cpp
字號:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
TCHWND
--*/
#include <windows.h>
#include <tchar.h>
#include <types.h>
//#include "debug.h"
#include "pegc_def.h"
#include "tchddi.h"
#ifdef __cplusplus
extern "C"{
#endif
#include "tchstub.h"
// Local and external functions
HWND FindForegroundFocusWindow(HWND hForegroundWnd);
LRESULT CALLBACK TchStubWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void TouchCreateEventInternal(int begX, int begY);
void
StubCallback2(
DWORD dwtick0,
TOUCH_PANEL_SAMPLE_FLAGS Flags,
INT X,
INT Y
);
DWORD WINAPI TchWindowThread(DWORD dwParameter)
{
WNDCLASSW wc;
HWND hWnd;
MSG msg;
HANDLE hInst = reinterpret_cast<HANDLE>(dwParameter);
wc.style = 0; //CS_HREDRAW | CS_VREDRAW; //| CS_DBLCLKS;
wc.lpfnWndProc = (WNDPROC) TchStubWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = reinterpret_cast<HINSTANCE>(hInst);
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = TOUCHSTUB_WNDCLASSNAME;
Sleep(4000);
if (RegisterClass(&wc) == FALSE )
{
MYERRORMSG(1,
(TEXT("Could not register window class for TouchStub Window.\r\n")));
return 0;
}
if((hWnd=CreateWindowEx(0, TOUCHSTUB_WNDCLASSNAME, L"", 0,
0, 0, 1 , 1, NULL, NULL, reinterpret_cast<HINSTANCE>(hInst), NULL))==0)
{
MYERRORMSG(1,
(TEXT("Could not create TouchStub Window.\r\n")));
return 0;
}
ShowWindow(hWnd, SW_HIDE);
while(1)
{
if(GetMessage(&msg, NULL, 0, 0) == FALSE)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
// The point of this routine is to get the focus window in the client proc (ie, pWord, etc).
//
// Since the Focus window of the foreground proc is not the same as the foreground window, we do this by
// creating a window parented to the foreground window, then calling GetFocus() on that window, then
// destroying the temp window we created.
// If creating the window fails, we return hForegroundWnd - not perfect, but the best we can do.
// The GWE lead developer warns that this could break with future versions of the OS. The alternative is to // sublcass the foreground wnd, then on that subclassed thread check to see who has focus, then
// undo the sublcass, returning the result (the code used to do that).
HWND FindForegroundFocusWindow(HWND hForegroundWnd)
{
HWND hWndFocus;
HWND hTempWindow;
// create a window, any window, parented to hForegroundWnd
hTempWindow = CreateWindowEx(0, TOUCHSTUB_WNDCLASSNAME, L"", 0,
0, 0, 1 , 1, hForegroundWnd, NULL,
reinterpret_cast<HINSTANCE>(*_phinstDll), NULL);
if (NULL == hTempWindow)
return hForegroundWnd;
// this works because creating a window parented to hForegroundWindow joins the
// input contexts of the message queues temporarily, so we can find which
// child of the foreground wnd actually has the focus using the standard API call.
hWndFocus = GetFocus();
// destroying the window disconnects my thread input context from the foreground thread
DestroyWindow(hTempWindow);
return hWndFocus;
}
LRESULT CALLBACK TchStubWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
return 0;
case WM_STUB_TABLET:
StubCallback2(wParam, (TOUCH_PANEL_SAMPLE_FLAGS)(lParam>>26), ((lParam>>13)&0x01FFF), (lParam&0x01FFF));
break;
case WM_STUB_GETVERSION:
return (CGRTOUCH_MAJOR_VERSION*10000+CGRTOUCH_MINOR_VERSION*100+CGRTOUCH_RELEASE);
//_iTouchStubVersion;
case WM_STUB_GETLASTTOUCHFOCUSWND:
return (LRESULT)_hLastTouchFocusWnd;
// go to the client process (pWord, etc) and see who has focus there (set _hLastTouchFocusWnd to answer)
case WM_STUB_GETFOCUSWND:
{
HWND hFgrWnd = GetForegroundWindow();
// if there is no foreground window, no need to go further
if(hFgrWnd==NULL || !IsWindow(hFgrWnd))
{
_hLastTouchFocusWnd = NULL;
return 0;
}
// default to the foreground window in case the explorer has focus
_hLastTouchFocusWnd = hFgrWnd;
// if the explorer has focus, return
TCHAR szClass[128];
GetClassName( hWnd, szClass, 127);
if(_tcscmp(szClass, L"DesktopExplorerWindow")==0)
return 0;
// Call our routine to find the focus window
_hLastTouchFocusWnd = FindForegroundFocusWindow(hFgrWnd);
return reinterpret_cast<long>(_hLastTouchFocusWnd);
}
case WM_STUB_EVENT:
TouchCreateEventInternal((int)wParam, (int)lParam);
return TRUE;
case WM_STUB_REGISTWND:
_hClientWnd = (HWND)wParam;
#ifdef DEBUGTOUCH
// Show the debug message next time touch driver performance is below.
_bNoDbgMsg = FALSE;
#endif // DEBUGTOUCH
return TRUE;
case WM_STUB_UNREGISTWND:
if(_hClientWnd == (HWND)wParam)
_hClientWnd = NULL;
#ifdef DEBUGTOUCH
// Show the debug message next time touch driver performance is below.
_bNoDbgMsg = FALSE;
#endif // DEBUGTOUCH
break;
case WM_STUB_SETVALUE:
switch(wParam)
{
case STUB_LAST_CLICKTIME:
_dwLastSendedTick = lParam;
break;
case STUB_VALUE_REGWND:
break;
case STUB_VALUE_STUBWND:
break;
case STUB_MIN_PAUSE_BEFORE_CLICK:
dwMinPauseBeforeClick = lParam;
break;
case STUB_MAX_CLICK_DIST:
iMaxClickDist = lParam;
break;
case STUB_MAX_CLICK_TIME:
dwMaxClickTime = lParam;
break;
case STUB_MAX_DELAY_DIST:
iMaxDelayDist = lParam;
break;
case STUB_MIN_START_DELAY_TIME:
dwMinStartDelayTime = lParam;
break;
case STUB_MIN_INTER_DELAY_TIME:
dwMinInterDelayTime = lParam;
break;
}
break;
case WM_STUB_GETVALUE:
switch(wParam)
{
case STUB_VALUE_REGWND:
return (LRESULT)_hClientWnd;
case STUB_VALUE_STUBWND:
return (LRESULT)*_phStubWnd;
case STUB_MIN_PAUSE_BEFORE_CLICK:
return dwMinPauseBeforeClick;
case STUB_MAX_CLICK_DIST:
return iMaxClickDist;
case STUB_MAX_CLICK_TIME:
return dwMaxClickTime;
case STUB_MAX_DELAY_DIST:
return iMaxDelayDist;
case STUB_MIN_START_DELAY_TIME:
return dwMinStartDelayTime;
case STUB_MIN_INTER_DELAY_TIME:
return dwMinInterDelayTime;
default:
return 0;
}
break;
case WM_STUB_RESET:
if(wParam)
{
dwMinPauseBeforeClick = 1500;
iMaxClickDist = 23;
iMaxDelayDist = 18;
dwMaxClickTime = 480;
dwMinStartDelayTime = 480;
dwMinInterDelayTime = 800;
}
_dwLastSendedTick = 0;
default : return DefWindowProc(hWnd, message, wParam, lParam);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
#ifdef __cplusplus
}
#endif //ifdef __cplusplus
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -