BOOL QuerySaveChart (HWND hWndParent, PGRAPHSTRUCT pGraph) /* Effect: If the graph pGraph is modified, put up a message box allowing the user to save the current graph. Return whether the caller should proceed to load in a new or otherwise trash the current graph. */ { // QuerySaveChart #ifdef KEEP_QUERY int iReturn ; if (!pGraph->bModified) return (TRUE) ; iReturn = MessageBoxResource (hWndParent, IDS_SAVECHART, IDS_MODIFIEDCHART, MB_YESNOCANCEL | MB_ICONASTERISK) ; if (iReturn == IDCANCEL) return (FALSE) ; if (iReturn == IDYES) SaveChart (hWndGraphs, 0, 0) ; return (TRUE) ; #endif return (TRUE) ; // we don't want to query nor save change } // QuerySaveChart
HRESULT CSkeletalViewerApp::Nui_Init() { HRESULT hr; RECT rc; if (!m_pNuiInstance) { HRESULT hr = MSR_NuiCreateInstanceByIndex(0, &m_pNuiInstance); if (FAILED(hr)) { return hr; } if (m_instanceId) { ::SysFreeString(m_instanceId); } m_instanceId = m_pNuiInstance->NuiInstanceName(); } m_hNextDepthFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); m_hNextVideoFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); m_hNextSkeletonEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); GetWindowRect(GetDlgItem( m_hWnd, IDC_SKELETALVIEW ), &rc ); int width = rc.right - rc.left; int height = rc.bottom - rc.top; HDC hdc = GetDC(GetDlgItem( m_hWnd, IDC_SKELETALVIEW)); m_SkeletonBMP = CreateCompatibleBitmap( hdc, width, height ); m_SkeletonDC = CreateCompatibleDC( hdc ); ::ReleaseDC(GetDlgItem(m_hWnd,IDC_SKELETALVIEW), hdc ); m_SkeletonOldObj = SelectObject( m_SkeletonDC, m_SkeletonBMP ); hr = m_DrawDepth.CreateDevice( GetDlgItem( m_hWnd, IDC_DEPTHVIEWER ) ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DCREATE,MB_OK | MB_ICONHAND); return hr; } hr = m_DrawDepth.SetVideoType( 320, 240, 320 * 4 ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DVIDEOTYPE,MB_OK | MB_ICONHAND); return hr; } hr = m_DrawVideo.CreateDevice( GetDlgItem( m_hWnd, IDC_VIDEOVIEW ) ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DCREATE,MB_OK | MB_ICONHAND); return hr; } hr = m_DrawVideo.SetVideoType( 640, 480, 640 * 4 ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DVIDEOTYPE,MB_OK | MB_ICONHAND); return hr; } DWORD nuiFlags = NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | NUI_INITIALIZE_FLAG_USES_SKELETON | NUI_INITIALIZE_FLAG_USES_COLOR; hr = m_pNuiInstance->NuiInitialize(nuiFlags); if (E_NUI_SKELETAL_ENGINE_BUSY == hr) { nuiFlags = NUI_INITIALIZE_FLAG_USES_DEPTH | NUI_INITIALIZE_FLAG_USES_COLOR; hr = m_pNuiInstance->NuiInitialize(nuiFlags); } if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_NUIINIT,MB_OK | MB_ICONHAND); return hr; } if (HasSkeletalEngine(m_pNuiInstance)) { hr = m_pNuiInstance->NuiSkeletonTrackingEnable( m_hNextSkeletonEvent, 0 ); if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_SKELETONTRACKING,MB_OK | MB_ICONHAND); return hr; } } hr = m_pNuiInstance->NuiImageStreamOpen( NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 2, m_hNextVideoFrameEvent, &m_pVideoStreamHandle ); if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_VIDEOSTREAM,MB_OK | MB_ICONHAND); return hr; } hr = m_pNuiInstance->NuiImageStreamOpen( HasSkeletalEngine(m_pNuiInstance) ? NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX : NUI_IMAGE_TYPE_DEPTH, NUI_IMAGE_RESOLUTION_320x240, 0, 2, m_hNextDepthFrameEvent, &m_pDepthStreamHandle ); if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_DEPTHSTREAM,MB_OK | MB_ICONHAND); return hr; } // Start the Nui processing thread m_hEvNuiProcessStop=CreateEvent(NULL,FALSE,FALSE,NULL); m_hThNuiProcess=CreateThread(NULL,0,Nui_ProcessThread,this,0,NULL); return hr; }
HRESULT CSkeletalViewerApp::Nui_Init() { HRESULT hr; RECT rc; m_hNextDepthFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); m_hNextVideoFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); m_hNextSkeletonEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); GetWindowRect(GetDlgItem( m_hWnd, IDC_SKELETALVIEW ), &rc ); int width = rc.right - rc.left; int height = rc.bottom - rc.top; HDC hdc = GetDC(GetDlgItem( m_hWnd, IDC_SKELETALVIEW)); m_SkeletonBMP = CreateCompatibleBitmap( hdc, width, height ); m_SkeletonDC = CreateCompatibleDC( hdc ); ::ReleaseDC(GetDlgItem(m_hWnd,IDC_SKELETALVIEW), hdc ); m_SkeletonOldObj = SelectObject( m_SkeletonDC, m_SkeletonBMP ); hr = m_DrawDepth.CreateDevice( GetDlgItem( m_hWnd, IDC_DEPTHVIEWER ) ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DCREATE,MB_OK | MB_ICONHAND); return hr; } hr = m_DrawDepth.SetVideoType( 320, 240, 320 * 4 ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DVIDEOTYPE,MB_OK | MB_ICONHAND); return hr; } hr = m_DrawVideo.CreateDevice( GetDlgItem( m_hWnd, IDC_VIDEOVIEW ) ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DCREATE,MB_OK | MB_ICONHAND); return hr; } hr = m_DrawVideo.SetVideoType( 640, 480, 640 * 4 ); if( FAILED( hr ) ) { MessageBoxResource( m_hWnd,IDS_ERROR_D3DVIDEOTYPE,MB_OK | MB_ICONHAND); return hr; } hr = NuiInitialize( NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | NUI_INITIALIZE_FLAG_USES_SKELETON | NUI_INITIALIZE_FLAG_USES_COLOR); if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_NUIINIT,MB_OK | MB_ICONHAND); return hr; } hr = NuiSkeletonTrackingEnable( m_hNextSkeletonEvent, 0 ); if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_SKELETONTRACKING,MB_OK | MB_ICONHAND); return hr; } hr = NuiImageStreamOpen( NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 2, m_hNextVideoFrameEvent, &m_pVideoStreamHandle ); if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_VIDEOSTREAM,MB_OK | MB_ICONHAND); return hr; } hr = NuiImageStreamOpen( NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, NUI_IMAGE_RESOLUTION_320x240, 0, 2, m_hNextDepthFrameEvent, &m_pDepthStreamHandle ); if( FAILED( hr ) ) { MessageBoxResource(m_hWnd,IDS_ERROR_DEPTHSTREAM,MB_OK | MB_ICONHAND); return hr; } // Start the Nui processing thread m_hEvNuiProcessStop=CreateEvent(NULL,FALSE,FALSE,NULL); m_hThNuiProcess=CreateThread(NULL,0,Nui_ProcessThread,this,0,NULL); //initialize background subtraction. initialdepth = (USHORT*)malloc(320*480*sizeof(USHORT)); FrameCount = 0; return hr; }