Example #1
0
//-----------------------------------------------------------------------------
// Name: OnCreate()
// Desc: Handles the WM_CREATE window message
//-----------------------------------------------------------------------------
BOOL OnCreate( HWND hWnd, LPCREATESTRUCT lpCreateStruct )
{
    HRESULT hr;
    HMENU   hMenu;

    // Initialize direct input
    hr = InitDirectInput( hWnd );
    if( FAILED(hr) )
    {
        MessageBox( NULL, _T("Error Initializing DirectInput"), 
                    _T("Scrawl"), MB_ICONERROR | MB_OK );
        return FALSE;
    }

    // Fix up the popup system menu with custom commands
    hMenu = GetSystemMenu( hWnd, FALSE );

    EnableMenuItem( hMenu, SC_SIZE,     MF_BYCOMMAND | MF_DISABLED | MF_GRAYED );
    EnableMenuItem( hMenu, SC_MAXIMIZE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED );
    AppendMenu( hMenu, MF_ENABLED | MF_STRING, IDC_CLEAR, _T("C&lear\tDel") );
    AppendMenu( hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, _T("&About\tF1") );

    AppendMenu( hMenu, MF_ENABLED | MF_STRING | MF_POPUP,
                (UINT_PTR)LoadMenu( (HINSTANCE)GetModuleHandle(NULL), 
                                    MAKEINTRESOURCE(IDM_SENSITIVITY) ),
                _T("Sensitivit&y") );

    return TRUE;    
}
Example #2
0
    /**
    * 初期化
    */
    IZ_BOOL CPadDInput::Init(
        SInputDeviceInitParam* initParam,
        IZ_FLOAT analogStickDeadZone)
    {
        SInputDeviceInitParam* param = reinterpret_cast<SInputDeviceInitParam*>(initParam);

        D_INPUT* input = IZ_NULL;
        VRETURN(InitDirectInput(*param, &input));

        HWND hWnd = (HWND)param->nativeWindowHandle;

        m_InputTmp = input;

        HRESULT hr;

        // 利用可能なパッドの列挙関数を実行
        hr = m_InputTmp->EnumDevices(
                DI8DEVCLASS_GAMECTRL,
                EnumGameCtrlCallback,
                this,
                DIEDFL_ATTACHEDONLY);
        VRETURN(SUCCEEDED(hr));

        m_pPadDevice = m_DevTmp;

        if (m_pPadDevice == IZ_NULL)
        {
            return IZ_FALSE;
        }
    
        // デバイスをパッドに設定
        // デフォルトの設定を使用
#if 0
        hr = m_pPadDevice->SetDataFormat(&c_dfDIJoystick2);
#else
        hr = m_pPadDevice->SetDataFormat(&c_dfDIJoystick);
#endif
        VRETURN(SUCCEEDED(hr));

        // 協調レベルの設定
        hr = m_pPadDevice->SetCooperativeLevel(
                hWnd,
                DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
        VRETURN(SUCCEEDED(hr));

        // パッドのプロパティを列挙して設定

        // アナログスティック設定
        hr = m_pPadDevice->EnumObjects(
                EnumPadAxisCallback,
                //(void*)pInitParam->hWnd,
                this,
                DIDFT_AXIS);
        VRETURN(SUCCEEDED(hr));

        // 一応・・・
        m_hWnd = hWnd;

        return IZ_TRUE;
    }
Example #3
0
HRESULT CKeyInput::InitDevice()
{
    HRESULT hr;
    if (m_pDI == NULL)
        if( FAILED( hr = InitDirectInput() ) )
            return hr;
    if( FAILED( hr = m_pDI->CreateDevice( GUID_SysKeyboard, &m_pKeyboard, NULL ) ) )
        return hr;
    DWORD dwCoopFlags = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND | DISCL_NOWINKEY;

    // Set the data format to "keyboard format" - a predefined data format 
    //
    // A data format specifies which controls on a device we
    // are interested in, and how they should be reported.
    //
    // This tells DirectInput that we will be passing an array
    // of 256 bytes to IDirectInputDevice::GetDeviceState.
    if( FAILED( hr = m_pKeyboard->SetDataFormat( &c_dfDIKeyboard ) ) )
        return hr;

    // Set the cooperativity level to let DirectInput know how
    // this device should interact with the system and with other
    // DirectInput applications.
    hr = m_pKeyboard->SetCooperativeLevel( m_wnd, dwCoopFlags );

    if( FAILED(hr) )
        return hr;



    // Acquire the newly created device
    m_pKeyboard->Acquire();
    return S_OK;
}
Example #4
0
void Input::Startup(HWND hWnd)
{
	m_pDIObject = NULL;
	m_pDIKeyboardDevice = NULL;
	m_pDIMouseDevice = NULL;
	
	//Clears the buffer before use
	ZeroMemory(&KeyBuffer, 256);

	bool result = false;
	
	result = InitDirectInput();

	if(!result)
	{
		MessageBox (NULL, "InitDirectInput Failed", "ERROR", MB_OK);
	}
	
	result = false;
	result = InitKeyboard(hWnd);
	if(!result)
	{
		MessageBox (NULL, "InitKeyboard Failed", "ERROR", MB_OK);
	}

	result = false;
	result = InitMouse(hWnd);
	if(!result)
	{
		MessageBox (NULL, "InitMouse Failed", "Error", MB_OK);
	}
}
Example #5
0
void Application::Initialize(char* win_title, RECT win_rect, bool win_fullscreen, HINSTANCE hInst, int cmdShow)
{
	//	引数をメンバー変数に保存する
	Application::win_title = win_title;
	Application::win_rect = win_rect;
	Application::win_fullscreen = win_fullscreen;

	//ウィンドウの初期化
	if (!InitWindow(hInst, cmdShow))
		DebugAlert("ウィンドウを\nしょきかできませんでした");

	//Direct3Dの初期化
	if (!InitDirect3d())
		DebugAlert("Direct3Dを\n初期化できませんでした。");

	//プレゼンテーションパラメータの初期化
	if (!InitPresentParam())
		DebugAlert("プレゼンテーションパラメータを\n初期化できませんでした。");

	//Direct3Dデバイスの初期化
	if (!InitD3dDevice())
		DebugAlert("Direct3Dデバイスを\n初期化できませんでした。");

	//DirectInputの初期化
	if (!InitDirectInput(hInst))
		DebugAlert("DirectInputを\n初期化できませんでした。");

	//DirectInputデバイスの初期化
	if (!InitDinputDevice())
		DebugAlert("DirectInputデバイスを\n初期化できませんでした。");

	DebugLog("アプリケーションを初期化しました。\n");
}
Example #6
0
void SetupDirectInput(void) {
  HRESULT hr;
  FreeDirectInput();
  hr = InitDirectInput(hInstance, stWindow);
  if(FAILED(hr)) {
    FreeDirectInput();
  }
}
Example #7
0
void FrkKeyboard::Init(){
	ZeroMemory(&m_hBuffer, sizeof(m_hBuffer));
	InitDirectInput();
	CreateDevice();
	SetCooperativeLevel();
	SetDataFormat();
	Acquire();
}
Example #8
0
//-----------------------------------------------------------------------------
// Name: MainDialogProc
// Desc: Handles dialog messages
//-----------------------------------------------------------------------------
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
    UNREFERENCED_PARAMETER( lParam );

    switch( msg )
    {
        case WM_INITDIALOG:
            if( FAILED( InitDirectInput( hDlg ) ) )
            {
                MessageBox( NULL, TEXT( "Error Initializing DirectInput" ),
                            TEXT( "DirectInput Sample" ), MB_ICONERROR | MB_OK );
                EndDialog( hDlg, 0 );
            }

            // Set a timer to go off 30 times a second. At every timer message
            // the input device will be read
            SetTimer( hDlg, 0, 1000 / 30, NULL );
            return TRUE;

        case WM_ACTIVATE:
            if( WA_INACTIVE != wParam && g_pJoystick )
            {
                // Make sure the device is acquired, if we are gaining focus.
                g_pJoystick->Acquire();
            }
            return TRUE;

        case WM_TIMER:
            // Update the input device every timer message
            if( FAILED( UpdateInputState( hDlg ) ) )
            {
                KillTimer( hDlg, 0 );
                MessageBox( NULL, TEXT( "Error Reading Input State. " ) \
                            TEXT( "The sample will now exit." ), TEXT( "DirectInput Sample" ),
                            MB_ICONERROR | MB_OK );
                EndDialog( hDlg, TRUE );
            }
            return TRUE;

        case WM_COMMAND:
            switch( LOWORD( wParam ) )
            {
                case IDCANCEL:
                    EndDialog( hDlg, 0 );
                    return TRUE;
            }

        case WM_DESTROY:
            // Cleanup everything
            KillTimer( hDlg, 0 );
            FreeDirectInput();
            return TRUE;
    }

    return FALSE; // Message not handled 
}
Example #9
0
InputHandler::InputHandler(HWND handleWindow)
{
	handle = handleWindow;
	m_pDIObject = NULL;
	m_pDIKeyboardDevice = NULL;       

	InitDirectInput();
	InitKeyboard();
	InitMouse();

} 
Example #10
0
static void DeviceInitialize(DInputDevice& device)
{
    PrintLog("[PAD%d] Starting",device.dwUserIndex+1);
    PrintLog("[PAD%d] Initializing as UserIndex %d",device.dwUserIndex+1,device.dwUserIndex);

    HRESULT hr = InitDirectInput(hMsgWnd,device);
    if(FAILED(hr)) PrintLog("[PAD%d] Fail with 0x%08X",device.dwUserIndex+1,hr);

    if(SUCCEEDED(hr)) 
    {
        PrintLog("[PAD%d] Done",device.dwUserIndex+1);
        if(g_bInitBeep) MessageBeep(MB_OK);
    }
}
Example #11
0
void SystemInit()
{
	sysInf.FontSize = mainFontSize;

	InitMaze();
	HDC		hDC;
	BITMAPINFOHEADER	bmpInfoHead;

	CreateAlphaTable();
	ZeroMemory(&bmpInfoHead,sizeof(BITMAPINFOHEADER));
	bmpInfoHead.biSize = sizeof(BITMAPINFOHEADER);
	bmpInfoHead.biWidth = WIN_SIZEX;
	bmpInfoHead.biHeight = -WIN_SIZEY;
	bmpInfoHead.biPlanes = 1;
    bmpInfoHead.biBitCount = 24;
    bmpInfoHead.biCompression = BI_RGB;
	bmpInfoHead.biSizeImage = WIN_SIZEX * WIN_SIZEY *3;
	hDC = GetDC(sysInf.hWnd);
	g_DibInf.memDC = CreateCompatibleDC(hDC);
	g_DibInf.hBmp = CreateDIBSection(hDC,(BITMAPINFO *)&bmpInfoHead,DIB_RGB_COLORS,
					(void **)&g_DibInf.colorBuf.pBuf,NULL,NULL);
	g_DibInf.oldBmp = (HBITMAP)SelectObject(g_DibInf.memDC,g_DibInf.hBmp);
	ReleaseDC(sysInf.hWnd,hDC);
	ZeroMemory(g_DibInf.colorBuf.pBuf, WIN_SIZEX*WIN_SIZEY*3);
	g_DibInf.colorBuf.width = WIN_SIZEX;
	g_DibInf.colorBuf.height = WIN_SIZEY;
	g_DibInf.colorBuf.bpp = 24;
	g_DibInf.colorBuf.wPitch = WIN_SIZEX *3;

	backColorBuf.createColorBuf(WIN_SIZEX+80,WIN_SIZEY+60,24);
	bak_backColorBuf.createColorBuf(WIN_SIZEX+80,WIN_SIZEY+60,24);
	bgInf.colorBuf.loadLGF(pack_eventcg,"s00000",Type_back);
	msgWnd.InitMessageParts();
	InitDirectInput(sysInf.hInstance);
	lpSoundDS = new ClSoundDS(sysInf.hWnd,readFile,FALSE);

	if(sysInf.bAutoRead)CheckMenuItem( sysInf.hMenu, ID_AUTOREAD,   MF_CHECKED );
#ifdef _DEBUG
	sysInf.bInfo = TRUE;
#endif
	InitReadFlag();
	lpMovie = new CMovie;
	lpMovie->OpenMovie("leaflogo.avi",1);

	SYSTEMTIME	sysTime;
	GetLocalTime(&sysTime);
	srand( sysTime.wMilliseconds );
	for(int i=0;i<sysTime.wMilliseconds;i++)rand();
} // SystemInit
Example #12
0
//-----------------------------------------------------------------------------
// Name: MainDialogProc
// Desc: Handles dialog messages
//-----------------------------------------------------------------------------
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_INITDIALOG:
            if( FAILED( InitDirectInput( hDlg ) ) )
            {
                MessageBox( NULL, TEXT( "Error Initializing DirectInput" ),
                            TEXT( "DirectInput Sample" ), MB_ICONERROR | MB_OK );
                EndDialog( hDlg, 0 );
            }

            // Set a timer to go off 30 times a second. At every timer message
            // the input device will be read
            SetTimer( hDlg, 0, 1000 / 30, NULL );
            return TRUE;

        case WM_TIMER:
            // Update the input device every timer message
            if( FAILED( UpdateInputState( hDlg ) ) )
            {
                KillTimer( hDlg, 0 );
                MessageBox( NULL, TEXT( "Error Reading Input State. " ) \
                            TEXT( "The sample will now exit." ), TEXT( "DirectInput Sample" ),
                            MB_ICONERROR | MB_OK );
                EndDialog( hDlg, TRUE );
            }
            return TRUE;

        case WM_COMMAND:
            switch( LOWORD( wParam ) )
            {
                case IDCANCEL:
                    EndDialog( hDlg, 0 );
                    return TRUE;
            }
            break;

        case WM_DESTROY:
            // Cleanup everything
            KillTimer( hDlg, 0 );
            FreeDirectInput();
            return TRUE;
    }

    return FALSE; // Message not handled 
}
Example #13
0
//-----------------------------------------------------------------------------
// Name: Open_Port()
// output: none
// Desc: Sets up and creates thread after initializing directx and enumerating 
// joysticks
//-----------------------------------------------------------------------------
HRESULT Open_Port()
{
	DWORD dwThreadId;
	HRESULT err;

	// set up exit condition semaphore
	DeathEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
	ResetEvent(DeathEvent);

	err = InitDirectInput();
	if (err) return err;

	// start polling thread
	PollingThreadHandle = CreateThread(NULL,0,&PollingThread,hInstance,0,&dwThreadId);
	if (PollingThreadHandle == NULL)
	{
		return ERR_CANNOT_CREATE_POLLINGTHREAD;
	}
	return OK;
}
Example #14
0
/******************************************************************
  Function: InitiateControllers
  Purpose:  This function initialises how each of the controllers 
            should be handled.
  input:    - A controller structure that needs to be filled for 
			  the emulator to know how to handle each controller.
  output:   none
*******************************************************************/  
EXPORT void CALL InitiateControllers (CONTROL_INFO ControlInfo)

#endif // SPECS_VERSION
{
	DebugWriteA("CALLED: InitiateControllers\n");
	if( !prepareHeap())
		return;

#if SPECS_VERSION == 0x0100
	g_strEmuInfo.hMainWindow = hMainWindow;
//	g_strEmuInfo.HEADER = NULL;
#elif SPECS_VERSION >= 0x0101
	g_strEmuInfo.hMainWindow = ControlInfo.hMainWindow;
//	g_strEmuInfo.MemoryBswaped = ControlInfo.MemoryBswaped;
//	g_strEmuInfo.HEADER = ControlInfo.HEADER;
	// UNDONE: Instead of just storing the header, figure out what ROM we're running and save that information somewhere
#endif // SPECS_VERSION

	// The emulator expects us to tell what controllers are plugged in and what their paks are at this point.

	if( !g_pDIHandle ) // if we don't have a directinput handle, we need to make one, attach it to the main window (so it will die if our emulator dies), and enumerate devices
	{
		if( InitDirectInput( g_strEmuInfo.hMainWindow ))
		{
			EnterCriticalSection ( &g_critical );
			InitMouse();
			g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY );
			LeaveCriticalSection ( &g_critical );
			DebugWriteA("InitDirectInput run in InitiateControllers, g_nDevices=%d\n", g_nDevices);
		}
		else
			return;
	}

	int iDevice;

	EnterCriticalSection( &g_critical );

	// ZeroMemory( g_apFFDevice, sizeof(g_apFFDevice) ); // NO, we'll reinit the existing reference if it's already loaded
	// ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); // NO, we'll release it with CloseControllerPak

	for( int i = 3; i >= 0; i-- )
	{
		SaveControllerPak( i );
		CloseControllerPak( i );
		// freePakData( &g_pcControllers[i] ); // already called by CloseControllerPak
		freeModifiers( &g_pcControllers[i] );
		SetControllerDefaults( &g_pcControllers[i] );
	}

	g_pcControllers[0].fPlugged = true;

	if (! LoadConfigFromINI() )
	{
		DebugWriteA("\tINI load failed, loading defaults from resource\n");
		for ( int i = 0; i < 4; i++ )
			LoadProfileFromResource( i, false );
		LoadShortcutsFromResource(false);
	}

	for( int i = 0; i < 4; i++)	// initiate xinput controller and plug then if connected --tecnicors
	{
		InitiateXInputController( &g_pcControllers[i].xiController, i );
		if( g_pcControllers[i].xiController.bConnected )
		{
			g_pcControllers[i].fPlugged = true;
			g_pcControllers[i].fGamePad = true;
		}
	}	// END

	// Init: Find force-feedback devices and init 
	for( int i = 3; i >= 0; i-- )
	{
		DebugWriteA("Controller %d: ", i+1);
		if( g_pcControllers[i].xiController.bConnected && g_pcControllers[i].fXInput)	// if xinput connected, we don't need other config --tecnicors
			continue;

		if( g_pcControllers[i].fPlugged )
		{
			// Search for right Controller
			iDevice = FindDeviceinList( g_pcControllers[i].guidFFDevice );
			if( iDevice != -1 && g_devList[iDevice].bEffType )
			{
				DebugWriteA("rumble device set, ");
			}
			else // we couldn't find the device specified in the INI file, or it was already null
			{
				g_pcControllers[i].guidFFDevice = GUID_NULL;
				DebugWriteA("no rumble device/effect type set, ");
			}

			if( g_pcControllers[i].nModifiers > 0)
				SetModifier( &g_pcControllers[i] );
			g_iFirstController = i;
			DebugWriteA("plugged in, with paktype %d, ", g_pcControllers[i].PakType);
			DebugWriteA("RawMode is %d\n", g_pcControllers[i].fRawData);
		}
		else
		{
			DebugWriteA("unplugged\n");
			freePakData( &g_pcControllers[i] );	// we don't need to do this again, but there's not much overhead so I'll leave it --rabid
			freeModifiers( &g_pcControllers[i] );
		}
	}

	PrepareInputDevices();

	if( g_bExclusiveMouse ) {
		// g_sysMouse.didHandle->Unacquire();
		// g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); // PrepareInputDevices does this.
		g_sysMouse.didHandle->Acquire();
	}

	InitiatePaks( true );

	g_strEmuInfo.fInitialisedPlugin = true;

	LeaveCriticalSection( &g_critical );

#if SPECS_VERSION == 0x0100
	FillControls(Controls);
#elif SPECS_VERSION >= 0x0101
	FillControls(ControlInfo.Controls);
#endif // SPECS_VERSION

	return;
} // end InitiateControllers
Example #15
0
/******************************************************************
  Function: DllConfig
  Purpose:  This function is optional function that is provided
            to allow the user to configure the dll
  input:    a handle to the window that calls this function
  output:   none
*******************************************************************/ 
EXPORT void CALL DllConfig ( HWND hParent )
{
	DebugWriteA("CALLED: DllConfig\n");
	static bool bInitCC = false;
	if( !prepareHeap())
		return;

	if( !g_pDIHandle )
	{
		if( InitDirectInput( hParent ))
		{
			EnterCriticalSection ( &g_critical );
			InitMouse();
			g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY );
			LeaveCriticalSection ( &g_critical );
			DebugWriteA("InitDirectInput run in DllConfig, g_nDevices=%d\n", g_nDevices);
		}
	}

	if( g_pDIHandle && !g_bConfiguring )
	{	
		g_bConfiguring = true;
		if( !bInitCC )
		{
			INITCOMMONCONTROLSEX ccCtrls =	{	sizeof(INITCOMMONCONTROLSEX), 
											ICC_BAR_CLASSES | ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES };
			InitCommonControlsEx( &ccCtrls ); // needed for TrackBars & Tabs
		}
		
		EnterCriticalSection( &g_critical );
		if( g_sysMouse.didHandle ) { // unlock mouse while configuring
			g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_DEVICE );
			g_sysMouse.didHandle->Acquire();
		}
		LeaveCriticalSection( &g_critical );

		int iOK = DialogBox( g_hResourceDLL, MAKEINTRESOURCE( IDD_MAINCFGDIALOG ), hParent, MainDlgProc );

		// If we go into the dialog box, and the user navigates to the Rumble window, our FF device can get unacquired.
		// So let's reinit them now if we're running, just to be safe --rabid
		if( g_bRunning )
		{
			EnterCriticalSection( &g_critical );
			// PrepareInputDevices resets g_bExclusiveMouse to false if no mouse keys are bound, and the only way to
			// re-enable exclusive mouse is with a shortcut.
			// This is undesirable behavior, but it beats the alternative (and we REALLY need to re-init FF devices here)
			PrepareInputDevices();
			if (iOK)
			{
				InitiatePaks( false );	// only re-init the mempaks and such if the user clicked Save or Use
			}
			
			if( g_sysMouse.didHandle ) {
				if ( g_bExclusiveMouse ) { // if we have exclusive mouse, we need to relock mouse after closing the config
					g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE );
					g_sysMouse.didHandle->Acquire();
					if (g_strEmuInfo.fDisplayShortPop)
					{
						LoadString( g_hResourceDLL, IDS_POP_MOUSELOCKED, g_pszThreadMessage, ARRAYSIZE(g_pszThreadMessage) );
						// HWND hMessage = CreateWindowEx( WS_EX_NOPARENTNOTIFY | WS_EX_STATICEDGE | WS_EX_TOPMOST, _T("STATIC"), pszMessage, WS_CHILD | WS_VISIBLE, 10, 10, 200, 30, g_strEmuInfo.hMainWindow, NULL, g_strEmuInfo.hinst, NULL );
						// SetTimer( hMessage, TIMER_MESSAGEWINDOW, 2000, MessageTimer );
						CreateThread(NULL, 0, MsgThreadFunction, g_pszThreadMessage, 0, NULL);
					}
				}
				else {
					g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_KEYBOARD );
					g_sysMouse.didHandle->Acquire();
				}
			}
			LeaveCriticalSection( &g_critical );
		}

		g_bConfiguring = false;
	}
	return;
}
Example #16
0
//-----------------------------------------------------------------------------
// Name: MainDialogProc
// Desc: Handles dialog messages
//-----------------------------------------------------------------------------
INT_PTR CALLBACK MainDialogProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
    HRESULT hr;

    switch( msg ) 
    {
        case WM_INITDIALOG:
        {
            // Set the icon for this dialog.
            HICON hIcon = LoadIcon( (HINSTANCE)GetModuleHandle(NULL), 
                                    MAKEINTRESOURCE( IDI_ICON ) );
            PostMessage( hDlg, WM_SETICON, ICON_BIG,   (LPARAM)hIcon );  // Set big icon
            PostMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon );  // Set small icon

            EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), FALSE );

            hr = InitDirectInput( hDlg );
            if( FAILED(hr) )
            {
                MessageBox( NULL, _T("Error Initializing DirectInput. ")
                                  _T("The sample will now exit."),
                                  _T("ReadFFE"), MB_ICONERROR | MB_OK );                
                EndDialog( hDlg, TRUE );
            }
            return TRUE;
        }

        case WM_COMMAND:
            switch( LOWORD(wParam) )
            {
                case IDCANCEL:
                    EndDialog( hDlg, FALSE ); 
                    return TRUE;

                case IDC_READ_FILE:
                    if( FAILED( hr = OnReadFile( hDlg ) ) )
                    {
                        MessageBox( NULL, _T("Error reading effects file."),
                                          _T("ReadFFE"), MB_ICONERROR | MB_OK );
                        EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), FALSE );
                    }
                    return TRUE;

                case IDC_PLAY_EFFECTS:
                    if( FAILED( hr = OnPlayEffects( hDlg ) ) )
                    {
                        MessageBox( NULL, _T("Error playing DirectInput effects. ")
                                          _T("The sample will now exit."), 
                                          _T("ReadFFE"), MB_ICONERROR | MB_OK );
                        EndDialog( hDlg, 1 );
                    }
                    return TRUE;
            }
            break;

        case WM_DESTROY:
            FreeDirectInput();   
            return TRUE;
    }

    return FALSE;
}
Example #17
0
int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow)
{
	RECT rc;
	int nWidth;
	int nHeight;

	HWND hWndTS = FindTSWindow();
	if(hWndTS != NULL) {
		GetWindowRect(hWndTS, &rc);
		nWidth = rc.right - rc.left;
		nHeight = rc.bottom - rc.top;
	} else {
		ExitProcess(0);
	}

	bool bUseJoystick = true;
	int nArgCount;
	LPSTR *pArgList;

	pArgList = CommandLineToArgvA(GetCommandLine(), &nArgCount);
	for (int i = 0; i < nArgCount; ++i)
	{
		if (pArgList[i][0] != '-')
			continue;

		if (strcmp(pArgList[i]+1, "j") == 0)
			bUseJoystick = !bUseJoystick;

		if (strcmp(pArgList[i]+1, "v") == 0)
			ToggleDisplaySection(0);

		if (strcmp(pArgList[i]+1, "f") == 0)
			ToggleFontOutline();

		if (strcmp(pArgList[i]+1, "s") == 0)
			ToggleSpeedLimitOnly();

		if (pArgList[i][1] == 'm')
		{
			if (isdigit(pArgList[i][2]))
			{
				int nSection = atoi(pArgList[i]+2);
				if (nSection >= 1 && nSection <= 12)
					ToggleDisplaySection(nSection);
			}
		}

		if (pArgList[i][1] == 's')
		{
			if (isdigit(pArgList[i][2]))
			{
				int nSection = atoi(pArgList[i]+2);
				if (nSection >= 1 && nSection <= 12)
					ToggleDisplaySection(nSection + 12);
			}
		}
	}

	margin.cxRightWidth = nWidth;
	margin.cyBottomHeight = nHeight;

	WNDCLASSEX wc;
	ZeroMemory(&wc, sizeof(WNDCLASSEX));

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)RGB(0,0,0);
	wc.lpszClassName = "WindowClass";

	RegisterClassEx(&wc);

	hWnd = CreateWindowEx(0,
		"WindowClass",
		"TrainSim Helper",
		WS_EX_TOPMOST | WS_POPUP,
		rc.left, rc.top,
		nWidth, nHeight,
		NULL,
		NULL,
		hInstance,
		NULL);

	SetWindowLong(hWnd, GWL_EXSTYLE,(int)GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED |WS_EX_TRANSPARENT);
	SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 255, ULW_COLORKEY | LWA_ALPHA);

	ShowWindow(hWnd, nCmdShow);

	InitD3D(hWnd, nWidth, nHeight);
	MSG msg;
	::SetWindowPos(hWndTS, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

	// V for the whole overlay
	RegisterHotKey(hWnd, 0, MOD_SHIFT | MOD_ALT, 0x56 /* V key */);

	// F1-F12 for the main overlay
	for (int i = 1; i <= 12; ++i)
		RegisterHotKey(hWnd, i, MOD_SHIFT | MOD_ALT, VK_F1 + i - 1);

	// F1-F12 for the steam overlay
	for (int i = 13; i <= 24; ++i)
		RegisterHotKey(hWnd, i, MOD_SHIFT | MOD_CONTROL, VK_F1 + i - 13);

	// 0-9 digits for the countdown
	for (int i = 100; i <= 109; ++i)
		RegisterHotKey(hWnd, i, MOD_SHIFT | MOD_ALT, 0x30 + i - 100);

	// R for the countdown reset
	RegisterHotKey(hWnd, 110, MOD_SHIFT | MOD_ALT, 0x52 /* R key */);

	// D for driving direction
	RegisterHotKey(hWnd, 201, MOD_SHIFT | MOD_ALT, 0x44 /* D key */);

	// F for font outline
	RegisterHotKey(hWnd, 202, MOD_SHIFT | MOD_ALT, 0x46 /* F key */);

	// S for speed limit only
	RegisterHotKey(hWnd, 203, MOD_SHIFT | MOD_ALT, 0x53 /* S key */);

	if (bUseJoystick)
		if (FAILED(InitDirectInput()))
			ExitProcess(0);

	bool fDone = false;

	while(!fDone)
	{
		hWndTS = FindTSWindow();
		if (!hWndTS)
		{
			msg.wParam = 0;
			break;
		}

		RECT rcNew;
		GetWindowRect(hWndTS, &rcNew);
		if (rcNew.left != rc.left || rcNew.top != rc.top)
		{
			rc = rcNew;
			MoveWindow(hWnd, rc.left, rc.top, nWidth, nHeight, FALSE);
		}

		::SetWindowPos(hWnd, HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		Sleep(10);

		RenderOverlay();
		if (bUseJoystick)
			UpdateJoystick();

		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);

			switch(msg.message)
			{
			case WM_QUIT:
				fDone = true;
				break;
			}
		}
	}

	if (bUseJoystick)
		FreeDirectInput();

	return msg.wParam;
}
CDirectInput8Manager::CDirectInput8Manager(HWND hWnd) :
m_pDI(NULL), m_pJoystick(NULL), m_bFilterOutXinputDevices(false), m_pXInputDeviceList(NULL)
{
	m_hWnd = hWnd;
	HRESULT hres = InitDirectInput(hWnd);
}
Example #19
0
// This is winmain, the main entry point for Windows applications
int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
	MSG msg;
	HWND hWnd;

	//register the class
	RegWindow(hInstance);

	//set up the screen in windowed or fullscreen mode
	DWORD style;
	if(FULLSCREEN)
		style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;
	else
		style = WS_OVERLAPPED;

	// create the window
	hWnd = CreateWindow( 
			APPTITLE,				//window class
			APPTITLE,				//title bar
			WS_OVERLAPPEDWINDOW,	//window style
			CW_USEDEFAULT,			//x position of window
			CW_USEDEFAULT,			//y position of window
			SCREEN_WIDTH,			//width of the window
			SCREEN_HEIGHT,			//height of the window
			NULL,					//parent window
			NULL,					//menu
			hInstance,				//application instance
			NULL);					//window parameters

	if(!hWnd)
		return FALSE;

	// Display the window on the screen
	ShowWindow( hWnd, SW_SHOW);
	UpdateWindow(hWnd);

	// Initialize the Direct Input Device
	if (!InitDirectInput(hWnd)){return FALSE;}

	// Initialize the Direct3D object
//	if(!InitDirect3D(hWnd, SCREEN_WIDTH, SCREEN_HEIGHT, FULLSCREEN)){return FALSE;}
	
	// Initialize the DirectSound object
	if(InitSound(hWnd) != AUDIO_SUCCESS){return FALSE;}

/*	// Initialize the game
	if(!InitGame(hWnd))
	{
		MessageBox(hWnd, L"Error initializing the game", L"Error", MB_OK);
		return 0;
	}
*/
	//Initialize the game
	game = new Game(hWnd);

	// main message loop:
	int done = 0;
	while(!done)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			//look for quit message
			if(msg.message == WM_QUIT)
				done = 1;

			//decode and pass messages to WndProc
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
			//process game loop
			game->GameRun();
	}
	return (int) msg.wParam;
}
Example #20
0
 bool initialize(unsigned int joystick_index)
 {
     return InitDirectInput(joystick_index) == S_OK;
 }
Example #21
0
void SystemInit(LPSTR lpCmdLine)
{
	CreateAlphaTable();
	createInitColorBuf();
	msgWnd.InitMessageParts();
	MessageMenuSet( off, TRUE );
	InitDirectInput(sysInf.hInstance);
	lpSoundDS = new ClSoundDS(
		sysInf.hWnd, readFile,
		pack_bgmfile, pack_sound, pack_voice,
		sysInf.bgmVolume, sysInf.seVolume, sysInf.voiceVolume,
		FALSE);

	if(sysInf.bAutoRead){
		CheckMenuItem( sysInf.hMenu, ID_AUTOREAD,   MF_CHECKED );
		msgWnd.msgBtn[3].SetState(btn_lock);	
	}
	if(sysInf.bInfo){
		sysInf.hDebugWnd = CreateDialog(
			sysInf.hInstance, MAKEINTRESOURCE(IDD_DEBUGWND), sysInf.hWnd, (DLGPROC)DebugDlgProc);
	}
	if(3==sysInf.movieQuality){
		GetCpuID();
		DWORD clock = GetCpuClock();
		if(clock >= 1800){
			sysInf.movieQuality = 2;
		}else if(clock>=1000){
			sysInf.movieQuality = 1;
		}else{
			sysInf.movieQuality = 0;
		}
	}
	if(2==sysInf.movieQuality){
		CheckMenuItem( sysInf.hMenu, ID_MOVIEHI,   MF_CHECKED );
	}else if(1==sysInf.movieQuality){
		CheckMenuItem( sysInf.hMenu, ID_MOVIEMID,  MF_CHECKED );
	}else{
		CheckMenuItem( sysInf.hMenu, ID_MOVIELOW,  MF_CHECKED );
	}
	if(2==sysInf.setFPS){
		CheckMenuItem( sysInf.hMenu, ID_FPS60,  MF_CHECKED );
	}else if(1==sysInf.setFPS){
		CheckMenuItem( sysInf.hMenu, ID_FPS30,  MF_CHECKED );
	}else{
		CheckMenuItem( sysInf.hMenu, ID_FPS20,  MF_CHECKED );
	}
	if(2==sysInf.nouseOverlay){
		char	buf[1024];
		int		i,j,device;
		device = EnumGraphicsDevice(  );
		for(i=0 ; i<device ; i++ ){
			strcpy( buf,GetGraphicsDeviceName(i) );
			for(j=0;j<strlen(buf);j++){
				buf[j] = tolower( buf[j] );
			}
			if( strstr(buf,"matrox") ){
				break;
			}
		}
		if(i<device){
			sysInf.nouseOverlay = 1;
		}else{
			sysInf.nouseOverlay = 0;
		}
	}
	if(sysInf.nouseOverlay==1){
		CheckMenuItem( sysInf.hMenu, ID_NOUSEOVERLAY,  MF_CHECKED );
	}
	toneConvert.ClearTable();
	InitReadFlag();
	rudderWnd = new RudderWnd;
	if(lpCmdLine[0]=='\0'){
		lpMovie = new CMovie(sysInf.nouseOverlay);
		lpMovie->OpenMovie("leaflogo.avi",-1,TRUE);
	}else{
		sysInf.bLookTitle = 1;	
		sysInf.bLookOpening = 1;
		int index = EXEC_ReadLang( lpCmdLine, &LangData );
		AVG_SetScenarioNo(index);
		EXEC_StartLang( &LangData, MAIN_SCRIPT );
		c_cls_all();
		msgWnd.MsgCLS();
		lpSoundDS->FadeOut(bgmHandle);
		changeExecMode( event_exec_mode );
	}
} // SystemInit