123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include "pch.h"
- #include <windows.h>
- #include <assert.h>
- #define ASSERT assert
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- #include "ManipulationEventSink.h"
- #include "ManipulationHelper.h"
- namespace ManipulationHelper
- {
- ManipulationHelper::ManipulationHelper(HWND wndHandle)
- {
- //开启控制台
- //AllocConsole();
- //FILE* stream;
- //freopen_s(&stream, "CONOUT$", "w", stdout);
- m_wndHandle = wndHandle;
- //初始化当前线程的COM库
- HRESULT hr = CoInitialize(0);
- if (FAILED(hr))
- {
- ASSERT(SUCCEEDED(hr) && L"Failed to execute CoInitialize");
- return;
- }
- // Perform application initialization
- if (!InitInstance())
- {
- CoUninitialize();
- return;
- }
- //printf("Init OK \n");
- InitOkFlag = TRUE;
- }
- ManipulationHelper::~ManipulationHelper()
- {
- //关闭控制台
- //FreeConsole();
- if (InitOkFlag)
- {
- CoUninitialize();
- }
- }
- int ManipulationHelper::ProcessDown(MANIPULATOR_ID manipulatorId, FLOAT x, FLOAT y)
- {
- return m_pIManipProc->ProcessDown(manipulatorId, x, y);
- }
- int ManipulationHelper::ProcessMove(MANIPULATOR_ID manipulatorId, FLOAT x, FLOAT y)
- {
- return m_pIManipProc->ProcessMove(manipulatorId, x, y);
- }
- int ManipulationHelper::ProcessUp(MANIPULATOR_ID manipulatorId, FLOAT x, FLOAT y)
- {
- return m_pIManipProc->ProcessUp(manipulatorId, x, y);
- }
- void ManipulationHelper::SetManipulationStartedCallBack(ManipulationStartedCallBack msCallback)
- {
- m_pManipulationEventSink->SetManipulationStartedCallBack(msCallback);
- }
- void ManipulationHelper::SetManipulationDeltaCallBack(ManipulationDeltaCallBack mdCallback)
- {
- m_pManipulationEventSink->SetManipulationDeltaCallBack(mdCallback);
- }
- void ManipulationHelper::SetManipulationCompletedCallBack(ManipulationCompletedCallBack mcCallback)
- {
- m_pManipulationEventSink->SetManipulationCompletedCallBack(mcCallback);
- }
- BOOL ManipulationHelper::InitInstance()
- {
- // Register application window for receiving multi-touch input. Use default settings.
- if (!RegisterTouchWindow(m_wndHandle, 0))
- {
- MessageBox(m_wndHandle, L"Cannot register application window for multi-touch input", L"Error", MB_OK);
- return FALSE;
- }
- ASSERT(IsTouchWindow(m_wndHandle, NULL));
- // Instantiate the ManipulationProcessor object
- HRESULT hr = CoCreateInstance(__uuidof(ManipulationProcessor), NULL, CLSCTX_ALL, IID_PPV_ARGS(&m_pIManipProc));
- if (FAILED(hr))
- {
- ASSERT(SUCCEEDED(hr) && L"InitInstance: failed to instantiate the ManipulationProcessor object");
- return FALSE;
- }
- // Instantiate the event sink with the manipulation processor and pointer to the rectangle object
- m_pManipulationEventSink = new ManipulationEventSink();
- if (m_pManipulationEventSink == NULL)
- {
- ASSERT(m_pManipulationEventSink && L"InitInstance: failed to instantiate the CManipulationEventSink class");
- m_pIManipProc->Release();
- m_pIManipProc = NULL;
- return FALSE;
- }
- // Establish the link between ManipulationEventSink and ManipulationProcessor
- if (!m_pManipulationEventSink->Connect(m_pIManipProc))
- {
- ASSERT(FALSE && L"InitInstance: failed to connect ManipulationEventSink and ManipulationProcessor");
- m_pIManipProc->Release();
- m_pIManipProc = NULL;
- m_pManipulationEventSink->Release();
- m_pManipulationEventSink = NULL;
- return FALSE;
- }
- return TRUE;
- }
- }
|