Exemple #1
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 大小改变
VOID CChildWnd::OnSize(WPARAM wParam, LPARAM lParam)
{
	RECT rtRect;
	INT iToolbar;
	INT iStatusBar;
	SIZE sizeToolbar;

	// 如果指定要获取窗口大小
	if (lParam == 0)
	{
		GetClientRect(m_hWnd, &rtRect);
		lParam = MAKELONG(_RectWidth(rtRect), _RectHeight(rtRect));
	}

	// 获取工具栏和状态栏的高度
	if (CMainWnd::IsMenuChecked(IDM_View_Toolbar))
	{
		ShowWindow(m_hToolbar, SW_SHOW);
		GetWindowRect(m_hToolbar, &rtRect);
		iToolbar = _RectHeight(rtRect);
	}
	else
	{
		ShowWindow(m_hToolbar, SW_HIDE);
		iToolbar = 0;
	}
	if (CMainWnd::IsMenuChecked(IDM_View_StatusBar))
	{
		ShowWindow(m_hStatusBar, SW_SHOW);
		GetWindowRect(m_hStatusBar, &rtRect);
		iStatusBar = _RectHeight(rtRect);
	}
	else
	{
		ShowWindow(m_hStatusBar, SW_HIDE);
		iStatusBar = 0;
	}

	// 调整播放窗口大小及位置
	MoveWindow(m_hPlayWnd, 0, iToolbar, LOWORD(lParam), HIWORD(lParam) - iToolbar - iStatusBar, TRUE);
	SetDrawRect();

	// 调整状态栏大小及位置
	AdjustStatusBar(wParam, lParam);

	// 调整工具栏大小及位置
	SendMessage(m_hToolbar, TB_AUTOSIZE, 0, 0);

	// 调整定位栏的大小
	SendMessage(m_hToolbar, TB_GETMAXSIZE, 0, (LPARAM) &sizeToolbar);
	MoveWindow(m_hSeekBar, sizeToolbar.cx, 1, LOWORD(lParam) - sizeToolbar.cx, sizeToolbar.cy - 2, TRUE);

	// 调整客户窗口边框
	if (m_hWnd == CClientWnd::GetActive())
	{
		CClientWnd::SetEdge(wParam != SIZE_MAXIMIZED);
	}
}
void CDTDisplay::SetScrollExtend()
{
	RECT rc;
	GetClientRect(&rc);
 	if(0 == m_Scale)
	{
		m_WndHeight = rc.bottom - rc.top;
		m_WndWidth = rc.right - rc.left;
	}
	else
	{//The Content size thould the bigger one of Windows' client area and the Image Size
		m_WndHeight = m_Height*sqrt((float)m_Scale) + DISP_BLANK_H;
		if(m_WndHeight<(rc.bottom - rc.top))
			m_WndHeight = rc.bottom - rc.top;
		m_WndWidth = m_Width*sqrt((float)m_Scale) + DISP_BLANK_W;
		if(m_WndWidth < (rc.right - rc.left))
			m_WndWidth = rc.right - rc.left;
	}
	SetDrawRect();
}
void CDrawCommon::DrawBitmap(CBitmap & bitmap, CPoint start_point, CSize size, StretchMode stretch_mode)
{
	CDC memDC;

	//获取图像实际大小
	BITMAP bm;
	GetObject(bitmap, sizeof(BITMAP), &bm);

	memDC.CreateCompatibleDC(m_pDC);
	memDC.SelectObject(&bitmap);
	// 以下两行避免图片失真
	m_pDC->SetStretchBltMode(HALFTONE);
	m_pDC->SetBrushOrg(0, 0);
	CSize draw_size;
	if (size.cx == 0 || size.cy == 0)		//如果指定的size为0,则使用位图的实际大小绘制
	{
		draw_size = CSize(bm.bmWidth, bm.bmHeight);
	}
	else
	{
		draw_size = size;
		if (stretch_mode == StretchMode::FILL)
		{
			SetDrawRect(CRect(start_point, draw_size));
			float w_h_radio, w_h_radio_draw;		//图像的宽高比、绘制大小的宽高比
			w_h_radio = static_cast<float>(bm.bmWidth) / bm.bmHeight;
			w_h_radio_draw = static_cast<float>(size.cx) / size.cy;
			if (w_h_radio > w_h_radio_draw)		//如果图像的宽高比大于绘制区域的宽高比,则需要裁剪两边的图像
			{
				int image_width;		//按比例缩放后的宽度
				image_width = bm.bmWidth * draw_size.cy / bm.bmHeight;
				start_point.x -= ((image_width - draw_size.cx) / 2);
				draw_size.cx = image_width;
			}
			else
			{
				int image_height;		//按比例缩放后的高度
				image_height = bm.bmHeight * draw_size.cx / bm.bmWidth;
				start_point.y -= ((image_height - draw_size.cy) / 2);
				draw_size.cy = image_height;
			}
		}
		else if (stretch_mode == StretchMode::FIT)
		{
			draw_size = CSize(bm.bmWidth, bm.bmHeight);
			float w_h_radio, w_h_radio_draw;		//图像的宽高比、绘制大小的宽高比
			w_h_radio = static_cast<float>(bm.bmWidth) / bm.bmHeight;
			w_h_radio_draw = static_cast<float>(size.cx) / size.cy;
			if (w_h_radio > w_h_radio_draw)		//如果图像的宽高比大于绘制区域的宽高比
			{
				draw_size.cy = draw_size.cy * size.cx / draw_size.cx;
				draw_size.cx = size.cx;
				start_point.y += ((size.cy - draw_size.cy) / 2);
			}
			else
			{
				draw_size.cx = draw_size.cx * size.cy / draw_size.cy;
				draw_size.cy = size.cy;
				start_point.x += ((size.cx - draw_size.cx) / 2);
			}
		}
	}

	m_pDC->StretchBlt(start_point.x, start_point.y, draw_size.cx, draw_size.cy, &memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
	memDC.DeleteDC();
}
void CMMABitmapWindow::SetDrawRectThread(const TRect& aRect)
{
    // Bitmap window's rect can be set in any thread.
    SetDrawRect(aRect);
}