Sign in to follow this  
winston123

how to get keyboard/mouse input priority from MFC win32 message?

Recommended Posts

how to get keyboard/mouse input priority from MFC win32 message? I established a MFC program with Dialog model. then create direct3d device, with this main dialog to show direct3d graphics, the project works fine. now I want to import the directinput mechanics to replace the win32 keyboard/mouse response function. this is my directinput code snippet:
Quote:
if(FAILED(DirectInput8Create(hInst,DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&g_pIDirectInput,NULL))){ MessageBox(NULL,"failed to create IDIRECTINPUT8 interface.","warning",MB_OK|MB_ICONINFORMATION); return false; } if(FAILED(g_pIDirectInput->CreateDevice(GUID_SysKeyboard,&m_pKeyboardDevice,NULL))){ MessageBox(NULL,"failed to create input device.","warning",MB_OK|MB_ICONINFORMATION); InputRelease(); return false; } if(FAILED(m_pKeyboardDevice->SetDataFormat(&c_dfDIKeyboard))){ MessageBox(NULL,"failed to set data format for keyboard.","warning",MB_OK|MB_ICONINFORMATION); InputRelease(); return false; } if(FAILED(m_pKeyboardDevice->SetCooperativeLevel(hWnd,DISCL_FOREGROUND|DISCL_NONEXCLUSIVE))){ MessageBox(NULL,"failed to set keyboard cooperativelevel.","warning",MB_OK|MB_ICONINFORMATION); InputRelease(); return false; } HRESULT RT=m_pKeyboardDevice->Acquire(); if(FAILED(RT)) { if(RT== DIERR_INVALIDPARAM) MessageBox(NULL,"failed to acquare keyboard access right, invalid parameters.","warning",MB_OK|MB_ICONINFORMATION); else if(RT==DIERR_NOTINITIALIZED) MessageBox(NULL,"failed to acquare keyboard access right,no intialization.","warning",MB_OK|MB_ICONINFORMATION); else if(RT==DIERR_OTHERAPPHASPRIO) MessageBox(NULL,"failed to acquare keyboard access right,other application has priority.","warning",MB_OK|MB_ICONINFORMATION); InputRelease(); return false; }
I put the code above into Mydialog::InitDialog(), get
Quote:
failed to acquare keyboard access right,other application has priority.
I realized maybe the code should not put there,since it says the window message (MFC) already got the keyboard access right. then where should I put it? even i change the parameter to Execlusive right, it get the same result SetCooperativeLevel(hWnd,DISCL_FOREGROUND|DISCL_EXCLUSIVE) anybody familiar with MFC? could you give me some hint? thanks a lot. winston.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this