|
I have tried all, the result are
*this and GetSafeHwnd() will get error
*AfxGetMainWnd()
AfxGetMainWnd()->GetSafeHwnd()
both without error, but it will get a E_HANDLE after running the SetCooperativeLevel(...).
Please help!
|
|
|
|
|
I looked back through all your posts and I didn't see where you are making the call from.
Can you post the entire function that includes the call to SetCooperativeLevel()?
LaHaHa wrote: I have tried all, the result are
*this and GetSafeHwnd() will get error
Are you getting compiler error or runtime error?
|
|
|
|
|
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!
|
|
|
|
|
Thanks that helps!
I would pass the HWND into your InitDirectInput() function.
Void CT1Dlg::OnTimer(UINT nIDEvent)
{
...
if(!FAILED(InitDirectInput(*this)))
{
...
}
...
}
HRESULT InitDirectInput(HWND hwndMain)
{
...
if( FAILED( hr = g_pJoystick->SetCooperativeLevel(hwndMain, DISCL_NONEXCLUSIVE |
DISCL_BACKGROUND ) ) )
return hr;
...
}
If your dialog window is wrapped in (a client of) a frame window then you'd need to pass that
framewnd's handle.
I'm not sure what you're doing overall, but are you sure you want to initialize in response to a
timer event? Generally DirectX initializations are done once, you use the functionality, and
cleanup when you're done.
Mark
|
|
|
|
|
hr got E_HANDLE again!
Please help!
|
|
|
|
|
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.
|
|
|
|
|
The setting the dialog's "Overlapped Window" property is changed to true,
but the result is the same.
g_pJoystick = 0x001672d4
hwndMain = 0x0007059c {unused=???}
hr = E_HANDLE
Please help!
|
|
|
|
|
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!
|
|
|
|
|
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?
|
|
|
|
|
After I put the InitDirectInput(*this) in the OnInitDialog(), it is alright.
But my program need to check the joystick to be available periodically.
So how can I do it?
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
|
|
|
|
|
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! )
|
|
|
|
|
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
|
|
|
|
|
I think my problem is the initialization.
My program need to periodically do the initialization of joystick. Could you give me more suggestions?
Please help!
|
|
|
|
|
i am developing an mfc application for internet browsing centres. i have got a requirement. after booting my application window should be displayed and the user should not be able to interact with the system other than with my application.how can i acheive this?
|
|
|
|
|
i want to add a view to the client of a window
i do it by following code
BOOL CMainWindow::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
BOOL ret = m_wndSplitter.CreateStatic(this, 1, 1);
ret = ret | m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CTestView), CSize(100, 100), pContext);
return ret;
}
But it can get my goal. How can i do it?
Thank you~
just do it
|
|
|
|
|
Hello,
I have two document templates and through a menu option I want to open a new document of one document type through a menu option which is not File New option.How do I do it.
How to divert a message handler to CWinApp class instead of CView? ANd how do I pass parameters to CDocument class from CWinApp to initialize CDocument class.
Thanks
Prithaa.
|
|
|
|
|
When a web server sends a response that does not contain a Content-Length: header, and is not chunked, how is a application supposed to know when it has finished downloading the complete document?
The response headers give no clue how big the file is, so how does one know?
The web server is not closing the connection, BTW. So I need to avoid blocking.
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
Never mind, I found out how. When the document is done, the recv() function returns ZERO bytes received.
Thanks for reading my post!
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
Hey, guys.
My concert lighting app has been on the back burner for several years now. Having reached the point where I'm ready to start designing the lighting for my current show, I naturally found a few tweaks I wanted to make to the software. Tried to build it in VS 2003 and got a lot of whining about DAO being deprecated, and recalled that MFC is hard wired to DAO 3.5 (which the compiler also isn't liking). So, I guess I need to rewrite the db code. Not what I had in mind when I opened the lid on this thing.
This is a standalone MFC app talking to a local Access db, and since it involved realtime control of moving lights, performance is a consideration. The current code is using the CDatabase / CRecordset approach. Since Microsoft has kicked DAO to the curb, I'm wondering what db technology I should port this to. I absolutely do not want to drag the .NET framework into the app.
Is there a new set of database access classes that plays nice with Access that are non .NET? I'd appreciate any suggestions you guys might have as it's currently dead in the water.
By the way, looked at the ADO forum, but it seems to be mostly SQL related topics. What I need is help porting an app to whatever non .NET API is appropriate for MFC.
|
|
|
|
|
The ODBC classes are similar if not identical. If performance is an issue (it's unlikely ODBC is
noticeably faster or slower than DAO) then caching performance-critical data in RAM is the
way to go.
I'm curious (since I've been a musician forever) how are you interfacing to hardware?
Mark
|
|
|
|