0
我是編寫Windows程序的新手。道歉,如果我的問題是一個非常簡單或基本的問題。整個屏幕的觸摸手勢
我想寫一個代碼,它使用微軟提供的觸摸手勢API用於使用C++的Windows 10。我也在使用觸摸屏。
我能夠創建一個窗口和一個句柄使用觸摸手勢,如以下代碼中提到:
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DecodeGesture(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
// Run the message loop.
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
}
return 0;
case WM_GESTURE:
// Insert handler code here to interpret the gesture.
return DecodeGesture(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
LRESULT DecodeGesture(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
// Create a structure to populate and retrieve the extra message info.
GESTUREINFO gi;
ZeroMemory(&gi, sizeof(GESTUREINFO));
gi.cbSize = sizeof(GESTUREINFO);
BOOL bResult = GetGestureInfo((HGESTUREINFO)lParam, &gi);
BOOL bHandled = FALSE;
if (bResult) {
// now interpret the gesture
switch (gi.dwID) {
case GID_ZOOM:
// Code for zooming goes here
bHandled = TRUE;
break;
case GID_PAN:
// Code for panning goes here
bHandled = TRUE;
break;
case GID_ROTATE:
// Code for rotation goes here
bHandled = TRUE;
break;
case GID_TWOFINGERTAP:
{
// Code for two-finger tap goes here
// Get all instances of the onscreen keyboard running on the local computer.
// This will return an empty array if onscreen keyboard isn't running.
array<Process^>^localByName = Process::GetProcessesByName("osk");
if (localByName->Length < 1)
{
system("start powershell.exe Set-ExecutionPolicy RemoteSigned \n");
system("start powershell.exe osk");
//system("pause");
}
bHandled = TRUE;
break;
}
case GID_PRESSANDTAP:
// Code for roll over goes here
bHandled = TRUE;
break;
default:
// A gesture was not recognized
break;
}
}
else {
DWORD dwErr = GetLastError();
if (dwErr > 0) {
//MessageBoxW(hWnd, L"Error!", L"Could not retrieve a GESTUREINFO structure.", MB_OK);
}
}
if (bHandled) {
return 0;
}
else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
//----------------------------------------------------------------------//
顯然,上面提到的代碼點到手柄,這是一個窗口而不是整個屏幕。
如何修改此代碼以創建一個指向整個屏幕而不僅僅是該窗口內部區域的句柄?
_「的句柄將指向整個操作系統」 _咦,什麼嗎? – user0042
在整個操作系統中,我的意思是整個用戶界面,而不是由創建的窗口占用的區域。 – Roger1990
_桌面_換句話說? – user0042