|
From: FerretallicA <fer...@ho...> - 2003-08-08 07:27:45
|
Hrmph...
It appears I am a moron and can't manage to reply to the list instead of to
individuals. It would explain a few things... anyways the following to the
list just for reference. If anyone else has problems with DirectInput it
might help them...
Cheers,
-FerretallicA
MESSAGE 1:
Oo oi,
No more c_dfDIKeyboard errors... and yes I know what SDL is :)
Thanks to all who have offered their input (no pun intended)!
Cheers,
-FerretallicA
----- Original Message -----
From: Damien
To: dev...@li...
Sent: Thursday, August 07, 2003 11:36 PM
Subject: Re: [Dev-C++] Direct Input Problems
Yeah, I did, but I had to 'borrow' a few lines out of the SDL source. The
only problem you should be having is the linker error involving
c_dfDIKeyboard. Take a look at SDL_dx5video.c, and copy and paste the
definitions in your code. Copy "static DIOBJECTDATAFORMAT KBD_fmt" and
"const DIDATAFORMAT c_dfDIKeyboard". Its a whole lot of code, so I won't
paste it in here. Just place it at the end of your source code. You do know
what SDL is ...right?
MESSAGE 2:
Oo oi,
I tried it out and it still gives this problem-
[Linker error] undefined reference to `c_dfDIMouse'
Thanks for the help still!
Cheers,
-FerretallicA
----- Original Message -----
From: "w.y." <yok...@be...>
Cc: "Dev-C++ Users Mailing List" <dev...@li...>
Sent: Thursday, August 07, 2003 7:47 PM
Subject: Re: [Dev-C++] Direct Input Problems
I copied and pasted from the examples from my book and got something
working. This uses Direct Input to read the mouse. It would take some
more tweaking to get something more useful, but this is something
at least. Assuming you have some basic windows app with menu choices,
pick a menu choice to use and call the 3 functions like this:
initDImouse(MainInstance, hwnd);
readDIMouse(hwnd);
shutDownDImouse();
"MainInstance" is a global I'm using obtained from the HINSTANCE
you get from WinMain. "hwnd" you probably know..
Merge the code below with your app, or put in a separate file (you'll
need to make a header file). The only library I included was
libdinput8.a (and libwinmm.a for something else) and I'm using
DevC++ 4.9.8.0
This all compiles with no problem for me.
////////////////////////////////////////////////////////////////
#define INITGUID
#include<windows.h>
#include<windowsx.h>
#include<dinput.h>
#include<cstdio>
#include"DImouse.h"
LPDIRECTINPUT8 lpdi = NULL; // dinput object
LPDIRECTINPUTDEVICE8 lpdimouse = NULL; // dinput mouse
const int winWidth = 640;
const int winHeight = 480;
int initDImouse(HINSTANCE, HWND);
int shutDownDImouse();
int readDIMouse(HWND);
int initDImouse(HINSTANCE hinstance,HWND hwnd)
{
DirectInput8Create(hinstance,DIRECTINPUT_VERSION,IID_IDirectInput8,
(void **)&lpdi,NULL);
// create a mouse device /////////////////////////////////////
lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL);
// set cooperation level
lpdimouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE |
DISCL_BACKGROUND);
// set data format
lpdimouse->SetDataFormat(&c_dfDIMouse);
// acquire the mouse
lpdimouse->Acquire();
return 1;
}
int shutDownDImouse()
{
// first unacquire the mouse
lpdimouse->Unacquire();
// now release the mouse
lpdimouse->Release();
// release directinput
lpdi->Release();
return 1;
}
int readDIMouse(HWND hwnd)
{
DIMOUSESTATE mouse_state;
int mouse_x = winWidth >> 1,
mouse_y = winHeight >> 1, prevX=mouse_x, prevY=mouse_y;
HDC hdc = GetDC(hwnd);
do
{ // get the input from the mouse
lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state);
// move the mouse cursor
mouse_x += (mouse_state.lX); // relative movement
mouse_y += (mouse_state.lY); // returned....
// test bounds
// first x boundaries
if (mouse_x >= winWidth) mouse_x = winWidth-1;
else if (mouse_x < 0) mouse_x = 0;
// now the y boundaries
if (mouse_y >= winHeight) mouse_y= winHeight-1;
else if (mouse_y < 0) mouse_y = 0;
// Update output if changed
if ( (prevX != mouse_x) || (prevY != mouse_y) )
{
prevX = mouse_x; prevY = mouse_y;
char strbuf[250];
sprintf(strbuf,"Right click to exit. Direct Mouse: %3i, %3i
",mouse_x, mouse_y);
TextOut(hdc,10,20,strbuf,strlen(strbuf));
}
} while ( !mouse_state.rgbButtons[0] );
ReleaseDC(hwnd,hdc);
return 1;
}
|