//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

    // Register the application window for receiving multi-touch input.
    if(!RegisterTouchWindow(hWnd, 0))
    {
        MessageBox(hWnd, L"Cannot register application window for touch input", L"Error", MB_OK);
        return FALSE;
    }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}
	void WMTouchEventSource::init(void)
	{
		// setup proc
		assert(prevWndProc == NULL);
		prevWndProc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_WNDPROC);
		SetWindowLongPtr(hWnd, GWL_WNDPROC, (LONG_PTR)wmTouchProc);
		
		// register for WM_TOUCH messages
		isWMTouchDevice = RegisterTouchWindow(hWnd, TWF_FINETOUCH);

		if (isWMTouchDevice)
		{
#ifdef _DEBUG
			printf("Windows touch input not available on this window\n");
#endif
			false;
			return;
		}

		assert((bool)IsTouchWindow(hWnd, NULL));

#ifdef _DEBUG
		printf("Windows touch input available, processing WM_TOUCH messages\n");
#endif
	}
Beispiel #3
0
	BOOL Show(HINSTANCE hInstance, int nCmdShow)
	{
		hInst = hInstance; // Store instance handle in our global variable

		int zoom = g_Config.iWindowZoom;
		if (zoom < 1) zoom = 1;
		if (zoom > 4) zoom = 4;
		
		RECT rc, rcOrig;
		GetWindowRectAtZoom(zoom, rcOrig, rc);

		u32 style = WS_OVERLAPPEDWINDOW;

		hwndMain = CreateWindowEx(0,szWindowClass, "", style,
			rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);
		if (!hwndMain)
			return FALSE;

		hwndDisplay = CreateWindowEx(0, szDisplayClass, TEXT(""), WS_CHILD | WS_VISIBLE,
			rcOrig.left, rcOrig.top, rcOrig.right - rcOrig.left, rcOrig.bottom - rcOrig.top, hwndMain, 0, hInstance, 0);
		if (!hwndDisplay)
			return FALSE;

		menu = GetMenu(hwndMain);
#ifdef FINAL
		RemoveMenu(menu,2,MF_BYPOSITION);
		RemoveMenu(menu,2,MF_BYPOSITION);
#endif
		MENUINFO info;
		ZeroMemory(&info,sizeof(MENUINFO));
		info.cbSize = sizeof(MENUINFO);
		info.cyMax = 0;
		info.dwStyle = MNS_CHECKORBMP;
		info.fMask = MIM_STYLE;
		for (int i = 0; i < GetMenuItemCount(menu); i++)
		{
			SetMenuInfo(GetSubMenu(menu,i),&info);
		}
		UpdateMenus();

		//accept dragged files
		DragAcceptFiles(hwndMain, TRUE);

		hideCursor = true;
		SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0);

		Update();
		SetPlaying(0);
		
		ShowWindow(hwndMain, nCmdShow);

#if ENABLE_TOUCH
		RegisterTouchWindow(hwndDisplay, TWF_WANTPALM);
#endif

		SetFocus(hwndDisplay);

		return TRUE;
	}
Beispiel #4
0
bool WinWindow::Initialize()
{
	RETURN_FALSE_IF_FALSE(IWindow::Initialize());

	//register window class
	WNDCLASSEX wcex;

	HINSTANCE instance = GetModuleHandle(nullptr);

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC&~WS_CAPTION&~WS_SYSMENU;
	wcex.lpfnWndProc = _WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = instance;
	wcex.hIcon = nullptr;
	wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
	wcex.hbrBackground = nullptr;
	wcex.lpszMenuName = nullptr;
	wcex.lpszClassName = L"MedusaGameWindow";
	wcex.hIconSm = nullptr;

	if (!RegisterClassEx(&wcex))
	{
		/*DWORD err= GetLastError();*/
		//log error
		MEDUSA_ASSERT_FAILED("");

	}

	////get window rect
	WHeapString windowName = StringParser::ToW(mName);

	//int windowStyle=mParentWindowHandle==nullptr?WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX:WS_CHILDWINDOW|WS_VISIBLE;
	int windowStyle = mParentWindowHandle == nullptr ? WS_CAPTION | WS_OVERLAPPEDWINDOW | WS_MINIMIZEBOX : WS_CHILDWINDOW | WS_VISIBLE;

	mWindowHandle = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, L"MedusaGameWindow", windowName.c_str(), windowStyle,
		0, 0, (int)mSize.Width, (int)mSize.Height, mParentWindowHandle, nullptr, instance, nullptr);

	RegisterTouchWindow(mWindowHandle, 0);

	//ImmAssociateContext(mWindowHandle, nullptr);	//disable ime

	if (!mWindowHandle)
	{
		/*DWORD err= GetLastError();*/
		//log error
		MEDUSA_ASSERT_FAILED("");
	}

	//SetForegroundWindow(mWindowHandle);
	MakeCenter();
	Resize(mSize);
	ShowWindow(mWindowHandle, SW_SHOW);
	UpdateWindow(mWindowHandle);

	return true;
}
// Initialize Instance
BOOL InitInstance(HINSTANCE hinst, int nCmdShow)
{
    BOOL success = TRUE;

    // Store instance handler in global variable
    g_hInst = hinst; 

    g_hWnd = CreateWindowEx(0, g_tszWindowClass, g_tszMainTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 
        CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, g_hInst, 0);
    

    if(!g_hWnd)
    {
        success = FALSE;
    }

    // Create and initialize touch and mouse handler

    if(success)
    {
        g_ctDriver = new (std::nothrow) CComTouchDriver(g_hWnd);

        if(g_ctDriver == NULL)
        {
            success = FALSE;
        }

        if(success)
        {
            success = g_ctDriver->Initialize();
        }
    }

    if(success)
    {
        // Disable UI feedback for penflicks 
        SetTabletInputServiceProperties();
        
        // Ready for handling WM_TOUCH messages
        RegisterTouchWindow(g_hWnd, 0);
        
        ShowWindow(g_hWnd, nCmdShow);
        UpdateWindow(g_hWnd);
    }
    else
    {
        if(g_ctDriver)
        {
            delete g_ctDriver;
            g_ctDriver = NULL;
        }
    }
    return success;
}
Beispiel #6
0
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  Add your specialized creation code here
    
    if (!RegisterTouchWindow())
    {
        ASSERT(FALSE);
    }

    return 0;
}
static void FixWindowForTouch(HWND hwnd)
{
    RegisterTouchWindow(hwnd, TOUCH_FLAGS);

    // disable right-click on touch and hold
    // using the method documented here: http://msdn.microsoft.com/en-us/library/ms812373.aspx

    // The atom identifier and Tablet PC atom
    ATOM atomID = 0;
    LPCWSTR tabletAtom = L"MicrosoftTabletPenServiceProperty";

    // Get the Tablet PC atom ID
    atomID = GlobalAddAtom(tabletAtom);

    if (atomID != 0)
    {
        // Try to disable press and hold gesture by
        // setting the window property
        SetProp(hwnd, tabletAtom, (HANDLE)1);
    }
}
Beispiel #8
0
VOID WindowInit(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	//  Load Hero Bitmap
	resource.hero[0] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO1));
	resource.hero[1] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO2));
	resource.hero[2] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO3));
	resource.hero[3] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO4));
	resource.hero[4] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO5));
	resource.hero[5] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO6));
	resource.hero[6] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO7));
	resource.hero[7] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO8));
	resource.hero[8] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_HERO9));

	resource.wHero[0] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO1));
	resource.wHero[1] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO2));
	resource.wHero[2] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO3));
	resource.wHero[3] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO4));
	resource.wHero[4] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO5));
	resource.wHero[5] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO6));
	resource.wHero[6] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO7));
	resource.wHero[7] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO8));
	resource.wHero[8] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WHITEHERO9));

	//  Load Note Resource
	resource.note[0] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_NOTEB));
	resource.note[1] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_NOTEW));

	//  Load Noise Resource
	resource.noise[0] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_NOISEB));
	resource.noise[1] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_NOISEW));

	//  Load Other Bitmaps
	resource.cloud = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_CLOUD));
	resource.machine = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_MACHINE));
	resource.machineok = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_MACHINEOK));
	resource.pauseButton = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_PAUSEBUTTON));
	resource.welcomeBackground = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
		MAKEINTRESOURCE(IDB_WELCOMEBACKGROUND));
	
	//  Register Touch Window To Enable Touch Event
	RegisterTouchWindow(hWnd, 0);

	//  Start Timer
	SetTimer(hWnd, TIMER, 20, NULL);
}
Beispiel #9
0
// main entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR paCmdLine, int nCmdShow) {
    WNDCLASSEXW WndClass;
    MSG Msg;
    unsigned long result;

    zhInstance = hInstance;

    //PWSTR pCmdLine = GetCommandLineW();

    WndClass.cbSize = sizeof(WNDCLASSEXW);
    WndClass.style = 0; // disable CS_DBLCLKS
    WndClass.lpfnWndProc = WndProc;
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    WndClass.hInstance = zhInstance;
    WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClass.hbrBackground = NULL;
    //WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    WndClass.lpszMenuName = NULL;
    WndClass.lpszClassName = L"MyClass";

    if (!RegisterClassExW(&WndClass)) {
        MessageBoxW(0, L"Error Registering Class!", L"Error!", MB_ICONSTOP | MB_OK);
        return 0;
    }

    hwndMain = CreateWindowExW(
        0,
        L"MyClass",
        L"MIDI controller test harness",
        WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        (int)(inWidth * dpi) + 6,
        (int)(inHeight * dpi) + 28,
        NULL,
        NULL,
        zhInstance,
        NULL
        );

    if (hwndMain == NULL) {
        MessageBoxW(0, L"Error Creating Window!", L"Error!", MB_ICONSTOP | MB_OK);
        return 0;
    }

    // register the window for touch instead of gestures
    RegisterTouchWindow(hwndMain, TWF_WANTPALM);

#define TARGET_RESOLUTION 1         // 1-millisecond target resolution

#ifdef FEAT_MIDI
    TIMECAPS tc;
    UINT     wTimerRes;

    if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR)
    {
        return -1;
    }

    wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
    timeBeginPeriod(wTimerRes);
#endif

    // TODO: really should FreeConsole() and fclose(stdout) later but it'll be open til process end anyway.
    AllocConsole();
    freopen("CONOUT$", "wb", stdout);

    // display the possible MIDI output devices:
    show_midi_output_devices();

#ifdef FEAT_MIDI
    // Open the MIDI Mapper
    UINT midiDeviceID = (UINT)1;
    if (strlen(paCmdLine) > 0) {
        if (sscanf(paCmdLine, "\"%d\"", &midiDeviceID) == 0) {
            midiDeviceID = (UINT) 1;
        }
    }
    printf("Opening MIDI device ID #%d...\r\n", midiDeviceID);
    result = midiOutOpen(&outHandle, midiDeviceID, 0, 0, CALLBACK_WINDOW);
    if (result)
        printf("There was an error opening MIDI device!  Disabling MIDI output...\r\n\r\n");
    else
        printf("Opened MIDI device successfully.\r\n\r\n");
#endif

#ifdef HWFEAT_LABEL_UPDATES

    for (int i = 0; i < 8; i++) {
        labels[0][i] = (WCHAR *)malloc(sizeof(WCHAR) * 21);
        labels[1][i] = (WCHAR *)malloc(sizeof(WCHAR) * 21);
        labels_ascii[0][i] = (char *)malloc(sizeof(char) * 20);
        labels_ascii[1][i] = (char *)malloc(sizeof(char) * 20);
    }

#endif

    // initialize UI bits:
    fsw_state.bot.byte = 0;
    fsw_state.top.byte = 0;
    led_state.bot.byte = 0;
    led_state.top.byte = 0;

    // initialize the logic controller
    controller_init();

    // Show main window:
    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);

    SetTimer(hwndMain, IDT_TIMER10MS, 10, (TIMERPROC) NULL);

    PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE);

    // default Win32 message pump
    //DWORD timeLast = timeGetTime();
    while (Msg.message != WM_QUIT) {
        if (!GetMessage(&Msg, NULL, 0, 0)) {
            break;
        }
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return 0;
}
Beispiel #10
0
void makeWindow( )
{

	WNDCLASSEX	wndClass;

	wndClass.cbSize        = sizeof(wndClass);
	wndClass.style         = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc   = CGameGirlProc;
	wndClass.cbClsExtra    = 0;
	wndClass.cbWndExtra    = 0;
	wndClass.hInstance     = g_pWindows->m_hInstance;
	wndClass.hIcon         = LoadIcon( g_pWindows->m_hInstance , MAKEINTRESOURCE(IDI_APP));
	wndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
	wndClass.lpszMenuName  = NULL;//MAKEINTRESOURCE(CGameGirl::GetInstance()->MENU_BAR);
	wndClass.lpszClassName = TEXT( NAME_APRICLASS );
	wndClass.hIconSm       = LoadIcon (NULL, _T( "MAIN" ));

	RegisterClassEx(&wndClass);

	//画面の中央にセット
	RECT		desktop;
	GetWindowRect(GetDesktopWindow(), (LPRECT)&desktop);

	/*-- フレームなどのクライアント領域以外のサイズを考慮 --*/
	Sint32 w,h;
	RECT rect = { 0, 0, SWINDOW_W, SWINDOW_H };
	AdjustWindowRect( &rect, WS_OVERLAPPEDWINDOW|WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, FALSE );

	w = rect.right - rect.left;
	h = rect.bottom - rect.top;

	Sint32 ax,ay;

	ax = (desktop.right  - desktop.left)/2 - w/2;
	ay = (desktop.bottom - desktop.top)/2  - h/2;

	if( ax < 0) ax = 0;
	if( ay < 0) ay = 0;

	g_pWindows->m_hWindow = CreateWindow(
				TEXT( NAME_APRICLASS ),
				TEXT( NAME_APRICATION ),
	            WS_OVERLAPPEDWINDOW|WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,
				ax,
				ay,
				w,
				h,
				NULL,
				NULL,
				g_pWindows->m_hInstance,
			    NULL);

	g_pWindows->m_WinDC = GetDC( g_pWindows->m_hWindow );

	g_pWindows->m_AppStyle = GetWindowLong( g_pWindows->m_hWindow , GWL_STYLE);
	GetWindowRect( g_pWindows->m_hWindow , &g_pWindows->m_WinRect );

	/*-- 念のためウインドウサイズ補正 --*/
	RECT client;
	GetClientRect( g_pWindows->m_hWindow, &client );
	int diffx = (client.right - client.left) - SWINDOW_W;
	int diffy = (client.bottom - client.top) - SWINDOW_H;
	if ( diffx != 0 || diffy != 0 ) {
		rect.right -= diffx;
		rect.bottom -= diffy;

		MoveWindow( g_pWindows->m_hWindow, g_pWindows->m_WinRect.left, g_pWindows->m_WinRect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE );
	}

	// ハードがマルチタッチをサポートしているかどうか
	int  value= ~GetSystemMetrics( SM_DIGITIZER );

	if( !(value & 0xc0) )
	{
		RegisterTouchWindow( g_pWindows->m_hWindow, 0 );
	}

	QueryPerformanceFrequency((LARGE_INTEGER*)&g_pWindows->Vsyncrate);		//秒間のカウント

}
Beispiel #11
0
	BOOL Show(HINSTANCE hInstance, int nCmdShow) {
		hInst = hInstance; // Store instance handle in our global variable.

		int zoom = g_Config.iWindowZoom;
		if (zoom < 1) zoom = 1;
		if (zoom > 4) zoom = 4;
		
		RECT rc, rcOrig;
		GetWindowRectAtZoom(zoom, rcOrig, rc);

		u32 style = WS_OVERLAPPEDWINDOW;

		hwndMain = CreateWindowEx(0,szWindowClass, "", style,
			rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);
		if (!hwndMain)
			return FALSE;

		hwndDisplay = CreateWindowEx(0, szDisplayClass, TEXT(""), WS_CHILD | WS_VISIBLE,
			rcOrig.left, rcOrig.top, rcOrig.right - rcOrig.left, rcOrig.bottom - rcOrig.top, hwndMain, 0, hInstance, 0);
		if (!hwndDisplay)
			return FALSE;

		menu = GetMenu(hwndMain);
#ifdef FINAL
		RemoveMenu(menu,2,MF_BYPOSITION);
		RemoveMenu(menu,2,MF_BYPOSITION);
#endif
		MENUINFO info;
		ZeroMemory(&info,sizeof(MENUINFO));
		info.cbSize = sizeof(MENUINFO);
		info.cyMax = 0;
		info.dwStyle = MNS_CHECKORBMP;
		info.fMask = MIM_STYLE;
		for (int i = 0; i < GetMenuItemCount(menu); i++) {
			SetMenuInfo(GetSubMenu(menu,i),&info);
		}
		UpdateMenus();

		// Accept dragged files.
		DragAcceptFiles(hwndMain, TRUE);

		hideCursor = true;
		SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0);

		Update();
		SetPlaying(0);

		if(g_Config.bFullScreenOnLaunch)
			_ViewFullScreen(hwndMain);
		
		ShowWindow(hwndMain, nCmdShow);

		W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);

#if ENABLE_TOUCH
		RegisterTouchWindow(hwndDisplay, TWF_WANTPALM);
#endif

		RAWINPUTDEVICE dev[2];
		memset(dev, 0, sizeof(dev));

		dev[0].usUsagePage = 1;
		dev[0].usUsage = 6;
		dev[0].dwFlags = 0;

		dev[1].usUsagePage = HID_USAGE_PAGE_GENERIC;
		dev[1].usUsage = HID_USAGE_GENERIC_MOUSE;
		dev[1].dwFlags = 0;
		RegisterRawInputDevices(dev, 2, sizeof(RAWINPUTDEVICE));

		SetFocus(hwndDisplay);

		return TRUE;
	}
static LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam)
{
    if (code >= 0)
    {
        switch(code)
        {
        case HC_ACTION:
        {
            LPMSG msg = (LPMSG)lParam;

            //for (HandleList::iterator it = s_windows->begin(); it != s_windows->end(); ++it)
            //{
            //	RegisterTouchWindow(*it, TOUCH_FLAGS);
            //}

            /*
            if(keyboardHandle != NULL)
            {
            	FixWindowForTouch(keyboardHandle);
            }
            */

            // to register all windows as touch-capable
            /*
            if (msg->hwnd != 0)
            {
            	bool found = false;
            	for (int i = 0; i < registeredWindows.size(); ++i)
            		if (registeredWindows[i] == msg->hwnd)
            		{
            			found = true;
            			break;
            		}
            	if (!found)
            	{
            		RegisterTouchWindow(msg->hwnd, TOUCH_FLAGS);
            		char buf[10240];
            		sprintf(buf, "registering %d; adr = %x\n", msg->hwnd, windowsToRegister);
            		trace(buf);
            		registeredWindows.push_back(msg->hwnd);
            	}
            }
            */

            /*
            while (windowsToRegister.size() > 0)
            {
            	RegisterTouchWindow(windowsToRegister.back(), TOUCH_FLAGS);

            	// register also all child windows to receive touch
            	long userData = 0;
            	EnumChildWindows(windowsToRegister.back(), enumChildWindowsCallback, userData);

            	windowsToRegister.pop_back();
            }
            */

            /*
            		char buf[10240];
            		sprintf(buf, "searching %d, size = %d adr = %x\n", msg->hwnd, wtrCount, windowsToRegister);
            		trace(buf);
            */

#if 0
            int pos = -1;
            for (int i = 0; i < /*windowsToRegister.size()*/wtrCount; ++i)
            {
                /*
                	char buf[10240];
                	sprintf(buf, "vector[%d] = %d\n", i, windowsToRegister[i]);
                	trace(buf);
                	*/
                if (windowsToRegister[i] == msg->hwnd)
                {
                    /*
                    char buf[10240];
                    sprintf(buf, "is found in vector at pos: %d\n", i);
                    trace(buf);
                    */
                    pos = i;
                }
            }
            //std::vector<HWND>::iterator pos = std::find(windowsToRegister.begin(), windowsToRegister.end(), msg->hwnd);
            //if (pos != windowsToRegister.end())
            if (pos >= 0)
            {
                RegisterTouchWindow(msg->hwnd, TOUCH_FLAGS);
                //windowsToRegister.erase(pos);
                for (int i = pos + 1; i < wtrCount; ++i)
                    windowsToRegister[i - 1] = windowsToRegister[i];
                --wtrCount;
                /*
                	char buf[10240];
                	sprintf(buf, "registering known window %d\n", msg->hwnd);
                	trace(buf);
                */
                FILE* trace = fopen("c:\\patrice\\patrice.txt", "a");
                if (trace != 0)
                {
                    TCHAR windowTitle[1024];
                    GetWindowText(msg->hwnd, windowTitle, 1024);
                    TCHAR className[1024];
                    GetClassName(msg->hwnd, className, 1024);
                    fwprintf(trace, L"%s - %s\n", windowTitle, className);
                    fclose(trace);
                }
            }
#endif

            //if (!IsTouchWindow(msg->hwnd, NULL))
            //{
            //	if (RegisterTouchWindow(msg->hwnd, TOUCH_FLAGS))
            //	{
            //		touchRegistered = true;
            //	}
            //}

            //TMP
            //FixWindowForTouch(msg->hwnd);
            //END TMP

            // a window is candidate for registering for touch (or back to gesture)
            // if its class is TmioEngineWin or Internet Explorer_Server
            // and the window or one of its ancertors has been declared with TouchEnable or GestureEnable

            HWND hwnd = msg->hwnd;
            TCHAR className[1024];

            if (hwnd != 0 && GetClassName(hwnd, className, 1024))
            {
                if (wcsncmp(className, L"TmioEngineWin", 1024) == 0
                        || wcsncmp(className, L"Internet Explorer_Server", 1024) == 0)
                {
                    while (hwnd != 0)	// loop thru ancestors
                    {
                        int i = findWindowHandle(hwnd);
                        if (i != -1)
                        {
                            if (isTouch[i])
                                FixWindowForTouch(msg->hwnd);
                            else
                                FixWindowForGesture(msg->hwnd);
                            break;
                        }
                        hwnd = GetParent(hwnd);
                    }
                }
            }

            switch(msg->message)
            {
            case WM_TOUCH:
            {
                // WM_TOUCH message can contain several messages from different contacts
                // packed together.
                // Message parameters need to be decoded:
                unsigned int numInputs = (unsigned int) msg->wParam; // Number of actual per-contact messages
                TOUCHINPUT* ti = new TOUCHINPUT[numInputs]; // Allocate the storage for the parameters of the per-contact messages
                if (ti == NULL)
                {
                    break;
                }

                //int maxTouchInputs = GetSystemMetrics(SM_MAXIMUMTOUCHES);

                // Unpack message parameters into the array of TOUCHINPUT structures, each
                // representing a message for one single contact.
                if (GetTouchInputInfo((HTOUCHINPUT)msg->lParam, numInputs, ti, sizeof(TOUCHINPUT)))
                {
                    // For each contact, dispatch the message to the appropriate message
                    // handler.

                    for (unsigned int i = 0; i < numInputs; ++i)
                    {
                        if (ti[i].dwFlags & TOUCHEVENTF_DOWN)
                        {
                            OnTouchDownHandler(msg->hwnd, ti[i]);
                        }
                        else if (ti[i].dwFlags & TOUCHEVENTF_MOVE)
                        {
                            OnTouchMoveHandler(msg->hwnd, ti[i]);
                        }
                        else if (ti[i].dwFlags & TOUCHEVENTF_UP)
                        {
                            OnTouchUpHandler(msg->hwnd, ti[i]);
                        }
                    }
                }

                CloseTouchInputHandle((HTOUCHINPUT)lParam);
                delete [] ti;
            }
            break;

            /*
            				case WM_GESTURE:
            					{
            						trace("WM_GESTURE\n");
            					}
            					break;
            */

            case WM_QUIT:
                UninitializeTouch();
                break;

            case WM_APP + 5:
                int arg0 = LOWORD(msg->wParam);
                int arg1 = HIWORD(msg->wParam);
                int arg2 = LOWORD(msg->lParam);
                int arg3 = HIWORD(msg->lParam);

                if(arg0 == EX_DESTROYWINDOW)
                {
                    DestroyWindow((HWND)msg->lParam);
                }
                break;
            }
            break;
        }
        }
    }

    return CallNextHookEx(0, code, wParam, lParam);
}
Beispiel #13
0
LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	//sprintf_s(s_buf, "GetMsgProc\n");
	//WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);
	if (!s_initialized)
	{
		if (!AttachConsole(g_consoleId))
		{
			FreeConsole();
			AttachConsole(g_consoleId);
		}
		s_out = GetStdHandle(STD_OUTPUT_HANDLE); // TODO: we don't really close it
		sprintf_s(s_buf, "Attached console\n");
		WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);

		if (!g_mouseHook)
		{
			g_mouseHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, g_this, 0); // mouse_ll global only (requires process with message loop)
			if (g_mouseHook)
			{
				sprintf_s(s_buf, "Installed mouse hook\n");
				WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);
			}
			else
			{
				sprintf_s(s_buf, "Could not install mouse hook\n");
				WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);
			}
		}

		if (g_detect_screen_size)
		{
			HWND win = GetDesktopWindow();
			RECT rec;
			GetWindowRect(win, &rec);
			g_screen_height = rec.bottom;
			g_screen_width = rec.right;
		}

		sprintf_s(s_buf, "X-Offset: %i Y-Offset: %i Width: %i Height: %i\n", g_screen_offsetX, g_screen_offsetY, g_screen_width, g_screen_height);
		WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);

		s_cursors.reset(new CursorMap);
		s_cursorBuf.reset(new CursorMap);

		s_server.reset(new TUIO::TuioServer(g_host, g_serverPort));
		sprintf_s(s_buf, "Created server (%s:%i)\n", g_host, g_serverPort);
		WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);

		s_timer = SetTimer(g_targetWnd, TIMER_IDENTIFIER, TIMER_CALL_TIME, 0);

		s_initialized = true;
	}

	if (nCode < 0) // do not process message 
	{
		return CallNextHookEx(0, nCode, wParam, lParam);
	}

	switch (nCode) 
	{ 
	case HC_ACTION: 
		{
			LPMSG msg = (LPMSG)lParam;

			// register everything for touch
			// Note: pretty ugly but seems to be the only possibility to register every window
			RegisterTouchWindow(msg->hwnd, TOUCH_FLAGS);

			switch (msg->message)
			{
			case WM_TOUCH:
				{
					//sprintf_s(s_buf, "Touches received:\n");
					//WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);

					UINT cInputs = LOWORD(msg->wParam);
					PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs];
					if (NULL != pInputs)
					{
						if (GetTouchInputInfo((HTOUCHINPUT)msg->lParam,
							cInputs,
							pInputs,
							sizeof(TOUCHINPUT)))
						{
							s_server->initFrame(TUIO::TuioTime::getSessionTime());

							// process pInputs
							for (UINT i=0; i<cInputs; ++i)
							{
								//sprintf_s(s_buf, "ID: %i, X: %i, Y: %i\n", pInputs[i].dwID, pInputs[i].x, pInputs[i].y);
								//WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);

								std::map<DWORD, TUIO::TuioCursor*>::iterator cursorIt = s_cursors->find(pInputs[i].dwID);
								if (cursorIt != s_cursors->end())
								{
									// found
									s_server->updateTuioCursor(cursorIt->second,
															   ((pInputs[i].x*0.01f)+g_screen_offsetX)/(float)(g_screen_width+g_screen_offsetX),
															   ((pInputs[i].y*0.01f)+g_screen_offsetY)/(float)(g_screen_height+g_screen_offsetY));
									(*s_cursorBuf)[pInputs[i].dwID] = cursorIt->second;
									s_cursors->erase(cursorIt);
								}
								else
								{
									// not found
									(*s_cursorBuf)[pInputs[i].dwID] = s_server->addTuioCursor(
															((pInputs[i].x*0.01f)+g_screen_offsetX)/(float)(g_screen_width+g_screen_offsetX),
															((pInputs[i].y*0.01f)+g_screen_offsetY)/(float)(g_screen_height+g_screen_offsetY));
								}
							}
							
							for (std::map<DWORD, TUIO::TuioCursor*>::iterator it = s_cursors->begin(); it != s_cursors->end(); ++it)
							{
								s_server->removeTuioCursor(it->second);
							}
							
							s_cursors->clear();
							std::auto_ptr<CursorMap> tmp(s_cursorBuf);
							s_cursorBuf = s_cursors;
							s_cursors = tmp;	
							s_server->commitFrame();
						}
					}
					delete[] pInputs;
				}
				break;
			case WM_TIMER:
				{
					//if (msg->wParam == TIMER_IDENTIFIER)
					//{
						BOOL frameOpen(false);
						for (std::map<DWORD, TUIO::TuioCursor*>::iterator it = s_cursors->begin(); it != s_cursors->end();)
						{
							long delta = TUIO::TuioTime::getSessionTime().getTotalMilliseconds() - it->second->getTuioTime().getTotalMilliseconds();
							if (delta > MAX_CURSOR_IDLE_TIME)
							{
								if (!frameOpen)
								{
									s_server->initFrame(TUIO::TuioTime::getSessionTime());
									frameOpen = true;
								}
								s_server->removeTuioCursor(it->second);
								std::map<DWORD, TUIO::TuioCursor*>::iterator tmp = it++;
								s_cursors->erase(tmp);
								//sprintf_s(s_buf, "Removed cursor due to time limit\n");
								//WriteConsole(s_out, s_buf, strlen(s_buf), &s_ccount, 0);
							}
							else
							{
								++it;
							}
						}
						if (frameOpen)
						{
							s_server->commitFrame();
						}
					//}
				}
				break;
			}
		}
		break; 
	}

	return CallNextHookEx(0, nCode, wParam, lParam); 
}