HRESULT MainWindow::OnCreate()

in TTDQueries/app-sample/MainWindow.cpp [178:332]


HRESULT MainWindow::OnCreate()
{
	HRESULT hr = S_OK;

	// Create the background brush.
	brush = CreateHatchBrush(HS_BDIAGONAL, RGB(0, 0x80, 0xFF));
	if (brush == NULL)
	{
		hr = __HRESULT_FROM_WIN32(GetLastError());
	}

	// Create the rebar control.
	if (SUCCEEDED(hr))
	{
		hr = rebar.Create(m_hInstance, m_hwnd, IDC_REBAR_CONTROL);
	}

	// Create the toolbar control.
	if (SUCCEEDED(hr))
	{
		hr = toolbar.Create(m_hInstance, m_hwnd, IDC_TOOLBAR, TBSTYLE_FLAT | TBSTYLE_TOOLTIPS);
	}

	// Set the image list for toolbar buttons (normal state).
	if (SUCCEEDED(hr))
	{
		hr = toolbar.SetImageList(
			Toolbar::Normal,			// Image list for normal state
			IDB_TOOLBAR_IMAGES_NORMAL,	// Bitmap resource
			Size(48, 48),				// Size of each button
			5,							// Number of buttons
			RGB(0xFF, 0x00, 0xFF)		// Color mask
			);
	}

	// Set the image list for toolbar buttons (disabled state).
	if (SUCCEEDED(hr))
	{
		hr = toolbar.SetImageList(
			Toolbar::Disabled,			// Image list for normal state
			IDB_TOOLBAR_IMAGES_DISABLED,	// Bitmap resource
			Size(48, 48),				// Size of each button
			5,							// Number of buttons
			RGB(0xFF, 0x00, 0xFF)		// Color mask
			);
	}


	// Add buttons to the toolbar.
	if (SUCCEEDED(hr))
	{
		// Play
		hr = toolbar.AddButton(Toolbar::Button(ID_IMAGE_PLAY, IDC_BUTTON_PLAY));
	}
	
	if (SUCCEEDED(hr))
	{
		// Stop
		hr = toolbar.AddButton(Toolbar::Button(ID_IMAGE_STOP, IDC_BUTTON_STOP));
	}

	if (SUCCEEDED(hr))
	{
		// Pause
		hr = toolbar.AddButton(Toolbar::Button(ID_IMAGE_PAUSE, IDC_BUTTON_PAUSE));
	}

	if (SUCCEEDED(hr))
	{
		// Mute
		hr = toolbar.AddButton(Toolbar::Button(ID_IMAGE_MUTE_OFF, IDC_BUTTON_MUTE));
	}

	// Add the toolbar to the rebar control.
	if (SUCCEEDED(hr))
	{
		hr = rebar.AddBand(toolbar.Window(), 0);
	}

	//// Create the slider for seeking.

	if (SUCCEEDED(hr))
	{
		hr = Slider_Init();	// Initialize the Slider control.
	}

	if (SUCCEEDED(hr))
	{
		hr = seekbar.Create(m_hwnd, Rect(0, 0, 300, 16), IDC_SEEKBAR);
	}

	if (SUCCEEDED(hr))
	{
		hr = seekbar.SetThumbBitmap(IDB_SLIDER_THUMB);

		seekbar.SetBackground(CreateSolidBrush(RGB(239, 239, 231)));
		seekbar.Enable(FALSE);
	}

	if (SUCCEEDED(hr))
	{
		hr = rebar.AddBand(seekbar.Window(), 1);
	}

	//// Create the slider for changing the volume.

	if (SUCCEEDED(hr))
	{
		hr = volumeSlider.Create(m_hwnd, Rect(0, 0, 100, 32), IDC_VOLUME);
	}

	if (SUCCEEDED(hr))
	{
		hr = volumeSlider.SetThumbBitmap(IDB_SLIDER_VOLUME);

		volumeSlider.SetBackground(CreateSolidBrush(RGB(239, 239, 231)));
		volumeSlider.Enable(TRUE);

		// Set the range of the volume slider. In my experience, only the top half of the
		// range is audible.
		volumeSlider.SetRange(MIN_VOLUME / 2, MAX_VOLUME);
		volumeSlider.SetPosition(MAX_VOLUME);
	}

	if (SUCCEEDED(hr))
	{
		hr = rebar.AddBand(volumeSlider.Window(), 2);
	}



	// Create the DirectShow player object.
	if (SUCCEEDED(hr))
	{
		m_pPlayer = new DShowPlayer(m_hwnd);
		if (m_pPlayer == NULL)
		{
			hr = E_OUTOFMEMORY;
		}
	}

	// Set the event notification window.
	if (SUCCEEDED(hr))
	{
		hr = m_pPlayer->SetEventWindow(m_hwnd, WM_GRAPH_EVENT);
	}

	// Set default UI state.
	if (SUCCEEDED(hr))
	{
		UpdateUI();
	}

	return hr;
}