void CALLBACK CSkeletalViewerApp::Nui_StatusProc(const NuiStatusData *pStatusData) { if (SUCCEEDED(pStatusData->hrStatus)) { // Update UI ::PostMessageW(m_hWnd, WM_USER_UPDATE_COMBO, 0, 0); if (m_instanceId && 0 == wcscmp(pStatusData->instanceName, m_instanceId)) { Nui_Init(m_instanceId); } else if (!m_pNuiInstance) { Nui_Init(0); } } else { if (0 == wcscmp(pStatusData->instanceName, m_instanceId)) { Nui_UnInit(); Nui_Zero(); } } }
//------------------------------------------------------------------- // Nui_StatusProc // // Callback to handle Kinect status changes //------------------------------------------------------------------- void CALLBACK SkeletalTracker::Nui_StatusProc( HRESULT hrStatus, const OLECHAR* instanceName, const OLECHAR* uniqueDeviceName ) { // Update UI // PostMessageW( m_hWnd, WM_USER_UPDATE_COMBO, 0, 0 ); if( SUCCEEDED(hrStatus) ) { if ( S_OK == hrStatus ) { // Nui_Init(); } } else { Nui_UnInit(); Nui_Zero(); } }
//------------------------------------------------------------------- // Destructor //------------------------------------------------------------------- SkeletalTracker::~SkeletalTracker() { Nui_UnInit(); Nui_Zero(); }
CSkeletalViewerApp::~CSkeletalViewerApp() { ::DeleteCriticalSection(&m_critSecUi); Nui_Zero(); ::SysFreeString(m_instanceId); }
CSkeletalViewerApp::CSkeletalViewerApp() { ::InitializeCriticalSection(&m_critSecUi); m_fUpdatingUi = false; Nui_Zero(); }
LRESULT CALLBACK CSkeletalViewerApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: { LOGFONT lf; // Clean state the class Nui_Zero(); // Bind application window handle m_hWnd=hWnd; // Initialize and start NUI processing Nui_Init(); // Set the font for Frames Per Second GetObject((HFONT) GetStockObject(DEFAULT_GUI_FONT),sizeof(lf),&lf); lf.lfHeight*=4; m_hFontFPS=CreateFontIndirect(&lf); SendDlgItemMessage(hWnd,IDC_FPS,WM_SETFONT,(WPARAM) m_hFontFPS,0); // Use the same font for distance and user SendDlgItemMessage(hWnd,IDC_DISTANCE,WM_SETFONT,(WPARAM) m_hFontFPS,0); SendDlgItemMessage(hWnd,IDC_USER,WM_SETFONT,(WPARAM) m_hFontFPS,0); UpdateComboBox(); SendDlgItemMessage (m_hWnd, IDC_CAMERAS, CB_SETCURSEL, 0, 0); } break; case WM_USER_UPDATE_FPS: { ::SetDlgItemInt( m_hWnd, static_cast<int>(wParam), static_cast<int>(lParam), FALSE ); } break; case WM_USER_UPDATE_DISTANCE: { ::SetDlgItemInt( m_hWnd, static_cast<int>(wParam), static_cast<int>(lParam), FALSE ); } break; case WM_USER_UPDATE_USER: { ::SetDlgItemInt( m_hWnd, static_cast<int>(wParam), static_cast<int>(lParam), FALSE ); } break; case WM_USER_UPDATE_COMBO: { UpdateComboBox(); } break; case WM_COMMAND: if( HIWORD( wParam ) == CBN_SELCHANGE ) { LRESULT index = ::SendDlgItemMessage(m_hWnd, IDC_CAMERAS, CB_GETCURSEL, 0, 0); switch (LOWORD(wParam)) { case IDC_CAMERAS: { if (!m_fUpdatingUi) // Don't reconnect as a result of updating the combo box. { Nui_UnInit(); Nui_Zero(); Nui_Init(static_cast<int>(index)); } } break; } } break; // Handle key presses case WM_KEYUP: switch (wParam) { default: // Print the info about the key I just pressed char msg[1024]; sprintf_s (msg, 1024, "wParam: %s lParam: %s", wParam, lParam); WCHAR msg_u[1024]; MultiByteToWideChar(0, 0, msg, 1024, msg_u, 6); MessageBox(hWnd, msg_u, TEXT("Display pressed character"), NULL); } break; // If the titlebar X is clicked destroy app case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: // Uninitialize NUI Nui_UnInit(); // Other cleanup DeleteObject(m_hFontFPS); // Quit the main message pump PostQuitMessage(0); break; } return (FALSE); }