How to get the HWND of mfc DialogBox for .Net
-
If you put a breakpoint at the SetCooperativeLevel() call, what's the value of the window handle?
-
Also, what are the properties of your dialog resource? Try setting the dialog's "Overlapped Window" property to true.
-
Also, what are the properties of your dialog resource? Try setting the dialog's "Overlapped Window" property to true.
-
Hmm something else is going wrong. The dialog doesn't have the WS_CHILD style does it? Maybe a dialog is unacceptable as a "top-level window"? Just for the heck of it, maybe try calling your InitDirectInput() from your dialog's WM_INITDIALOG handler.
-
Hmm something else is going wrong. The dialog doesn't have the WS_CHILD style does it? Maybe a dialog is unacceptable as a "top-level window"? Just for the heck of it, maybe try calling your InitDirectInput() from your dialog's WM_INITDIALOG handler.
I have created the project again. Now it will not get the E_HANDLE. The InitDirectInput(*this) coding is called from OnTimer as before. It can detect the joystick, but it cannot get any data from the joystick. The coding are if(!FAILED(InitDirectInput(*this))) { if( NULL != g_pJoystick ) { HRESULT hr; TCHAR strText[512] = {0}; // Device state text DIJOYSTATE2 js; // DInput joystick state // Poll the device to read the current state hr = g_pJoystick->Poll(); if(FAILED(hr) ) { hr = g_pJoystick->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pJoystick->Acquire(); } if( !FAILED( hr = g_pJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &js ) ) ) { for( int i = 0; i < 128; i++ ) { if ( js.rgbButtons[i] & 0x80 ) { TCHAR sz[128]; StringCchPrintf( sz, 128, TEXT("%02d "), i ); StringCchCat( strText, 512, sz ); } } } Please help!
-
HRESULT InitDirectInput(); Void CT1Dlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default switch (nIDEvent) { case 5: KillTimer(5); if(!FAILED(InitDirectInput())) { . . . HRESULT InitDirectInput() { HRESULT hr; if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) return hr; if( FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY ) ) ) return hr; if( NULL == g_pJoystick ) { // MessageBox( NULL, TEXT("Joystick not found. The sample will now exit."), // TEXT("DirectInput Sample"), // MB_ICONERROR | MB_OK ); return 0; } if( FAILED( hr = g_pJoystick->SetDataFormat( &c_dfDIJoystick2 ) ) ) return hr; HWND hDlg=AfxGetMainWnd()->GetSafeHwnd(); if( FAILED( hr = g_pJoystick->SetCooperativeLevel(hDlg, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND ) ) ) return hr; if( FAILED( hr = g_pJoystick->EnumObjects( EnumObjectsCallback, (VOID*)hDlg, DIDFT_ALL ) ) ) return hr; return S_OK; } I just call it by OnTimer() function. Please help!
I don't see anything except GetDeviceState() can return DIERR_INPUTLOST but Acquire() doesn't.
-
I don't see anything except GetDeviceState() can return DIERR_INPUTLOST but Acquire() doesn't.
-
I found that the first Poll() get "Invalid". After the Acquire(), the hr is S_OK. Then if I Poll() it again, it will get a S_False. Why? Please help!
LaHaHa wrote:
I found that the first Poll() get "Invalid". After the Acquire(), the hr is S_OK. Then if I Poll() it again, it will get a S_False. Why?
Poll returns what? DI_OK, DI_NOEFFECT or error DIERR_INPUTLOST, DIERR_NOTACQUIRED, or DIERR_NOTINITIALIZED? You only need to acquire the device once right?
-
LaHaHa wrote:
I found that the first Poll() get "Invalid". After the Acquire(), the hr is S_OK. Then if I Poll() it again, it will get a S_False. Why?
Poll returns what? DI_OK, DI_NOEFFECT or error DIERR_INPUTLOST, DIERR_NOTACQUIRED, or DIERR_NOTINITIALIZED? You only need to acquire the device once right?
-
I found that the first Poll() get "Invalid". After the Acquire(), the hr is S_OK. Then if I Poll() it again, it will get a S_False. Why? Please help!
check if it's available periodically or check for input? Are you going to poll or use events and separate thread(s)? p.s. sorry I'm replying to different messages - The site is not letting me reply sometimes :laugh:
-
check if it's available periodically or check for input? Are you going to poll or use events and separate thread(s)? p.s. sorry I'm replying to different messages - The site is not letting me reply sometimes :laugh:
If the joystick is plugged at the beginning, it is alright. If not, the program cannot detect it. I would like to make some response for the joystick button. Could you give me more suggestion? (Sorry for making trouble to you!;P Thank you for your help!:-D)
-
I found that the first Poll() get "Invalid". After the Acquire(), the hr is S_OK. Then if I Poll() it again, it will get a S_False. Why? Please help!
LaHaHa wrote:
I would like to make some response for the joystick button. Could you give me more suggestion?
In the DirextX SDK see the following sections under DirectInput/Programming Guide/DirectInput Device Data: Polling and Event Notification Joystick Data It's explained there better than I ever could :)
-
LaHaHa wrote:
I would like to make some response for the joystick button. Could you give me more suggestion?
In the DirextX SDK see the following sections under DirectInput/Programming Guide/DirectInput Device Data: Polling and Event Notification Joystick Data It's explained there better than I ever could :)