|
最近一直在学习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();
}
|
|