首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络游戏 >

DirectInput SetCursorProperties出错解决思路

2012-03-01 
DirectInput SetCursorProperties出错C/C++ codeHRESULT hreshres DirectInput8Create(GetModuleHandle

DirectInput SetCursorProperties出错

C/C++ code
HRESULT hres;    hres = DirectInput8Create(GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID *)&lpDI, NULL);    if(FAILED(hres))        return FALSE;    hres = lpDI->CreateDevice(GUID_SysMouse, &lpMouse,NULL);    if(FAILED(hres))        return FALSE;    hres = lpMouse->SetDataFormat(&c_dfDIMouse);    if(FAILED(hres))        return FALSE;    hres = lpMouse->SetCooperativeLevel(hWnd,DISCL_EXCLUSIVE | DISCL_FOREGROUND);    if(FAILED(hres))        return FALSE;    hMouseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);    if(!hMouseEvent)        return FALSE;    hres = lpMouse->SetEventNotification(hMouseEvent);    if(FAILED(hres))        return FALSE;    DIPROPDWORD dipdw;    dipdw.diph.dwSize = sizeof(DIPROPDWORD);    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);    dipdw.diph.dwObj = 0;    dipdw.diph.dwHow = DIPH_DEVICE;    dipdw.dwData = 16; // 预定义为16    hres = lpMouse->SetProperty(DIPROP_BUFFERSIZE,&dipdw.diph);    if(FAILED(hres))        return FALSE;        D3DXIMAGE_INFO imageInfo;    hres=D3DXGetImageInfoFromFile("Resource\\Picture\\cursor.bmp",&imageInfo);    if(FAILED(hres))        return FALSE;    D3DLOCKED_RECT dlr;    hres = d3d::GetDevice()->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height,imageInfo.Format,D3DPOOL_DEFAULT,&lpDSCursor,NULL);    if(FAILED(hres))        return FALSE;    hres =D3DXLoadSurfaceFromFile(lpDSCursor, NULL, NULL, "Resource\\Picture\\cursor.bmp", NULL, D3DX_FILTER_NONE, 0xFF000000, NULL);    if(FAILED(hres))        return FALSE;    SetCursor( NULL );    hres = d3d::GetDevice()->SetCursorProperties(0, 0, lpDSCursor);    if(FAILED(hres))        return FALSE;        d3d::GetDevice()->ShowCursor(TRUE);        lpMouse->Acquire();    return TRUE;

hres = d3d::GetDevice()->SetCursorProperties(0, 0, lpDSCursor); 这一步就出错了 初学DX 所以搞几天都不明白错哪

[解决办法]
我以前学习这块时也出现过问题,但是后来解决了,我把代码贴给你看看,希望对你有帮助。
C/C++ code
if(FAILED(m_pIDirect3DDevice->CreateOffscreenPlainSurface(32,32, D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT, &m_pMouseSurface,NULL)))    {        MessageBox(NULL,L"SetCursorProperties失败!",L"警告!",MB_OK);    }    if(FAILED(D3DXLoadSurfaceFromFile(m_pMouseSurface, NULL, NULL, _T("鼠标.jpg"), NULL, D3DX_FILTER_NONE, 0xFF000000, NULL)))    {        MessageBox(NULL,L"D3DXLoadSurfaceFromFile失败!",L"警告!",MB_OK);    }    if(FAILED(m_pIDirect3DDevice->SetCursorProperties(0, 0, m_pMouseSurface)))    {        MessageBox(NULL,L"SetCursorProperties失败!",L"警告!",MB_OK);    }    m_pIDirect3DDevice->SetCursorPosition(0, 0,D3DCURSOR_IMMEDIATE_UPDATE); 

热点排行