|
???????DirectX9 User Interfaces Design and Implementation ????????????????????????????????????????????????SetCooperativeLevel(hwnd,DISCL_FOREGROUND);???????????????????????????????????????????????????????????????????????????????????????
bool Init_Dinpute(HINSTANCE hInst)
{
//???????
D3DXGetImageInfoFromFile("../image/111.bmp",&Info);
Device->CreateOffscreenPlainSurface(Info.Width,Info.Height,D3DFMT_A8R8G8B8,
D3DPOOL_SYSTEMMEM,&g_MouseCursor,NULL);
if(g_MouseCursor==NULL)
MessageBox(NULL,"g_MouseCursor is empty","error",NULL);
D3DXLoadSurfaceFromFile(g_MouseCursor,NULL,NULL,"../image/111.bmp",NULL,D3DX_FILTER_NONE,0xFF000000,NULL);
DirectInput8Create(hInst, DIRECTINPUT_VERSION,IID_IDirectInput8, (void**)&g_lpDI, NULL);
if(g_lpDI!=NULL)
{
g_lpDI->CreateDevice(GUID_SysMouse, &g_Mouse, NULL);//????
g_Mouse->SetCooperativeLevel(hwnd,DISCL_NONEXCLUSIVE|DISCL_FOREGROUND);//??????
g_Mouse->SetDataFormat(&c_dfDIMouse );//??????
hMouseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(!hMouseEvent)
MessageBoxA(NULL,"hMouseEvent is NULL","",NULL);
g_Mouse->SetEventNotification(hMouseEvent);
DIPROPDWORD property;
property.diph.dwSize = sizeof(DIPROPDWORD);
property.diph.dwHeaderSize = sizeof(DIPROPHEADER);
property.diph.dwObj = 0;
property.diph.dwHow = DIPH_DEVICE;
property.dwData = 16;
g_Mouse->SetProperty(DIPROP_BUFFERSIZE, &property.diph);
Device->SetCursorProperties(0,0,g_MouseCursor);//????
Device->SetCursorPosition(0,0,D3DCURSOR_IMMEDIATE_UPDATE);
Device->ShowCursor(true);
return true;
}
return false;
}
void UpdateInpute()
{
if(SUCCEEDED(g_Mouse->Acquire()))//??????
{
DIMOUSESTATE State;
g_Mouse->GetDeviceState(sizeof(State),(LPVOID)&State);
g_MouseX += State.lX;
g_MouseY += State.lY;
Device->SetCursorPosition(g_MouseX,g_MouseY,D3DCURSOR_IMMEDIATE_UPDATE);
if(KEYDOWN(State.rgbButtons,1))
MessageBox(hwnd,"You pressed the right button","",MB_OK);
if(KEYDOWN(State.rgbButtons,0))
MessageBox(hwnd,"You pressed the left button","",MB_OK);
}
g_Mouse->Unacquire();
}
|
|