关闭

如何在窗口绘制背景图片,并且在图片上话一个矩形

标签: 背景图片矩形CImageCBitmap
1227人阅读 评论(0) 收藏 举报
分类:
void CPtestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
        CPaintDC dc(this);
        CImage ii;
        BOOL b = ii.Load(_T("c:\\flower.jpg"));
        HBITMAP hbmp =(HBITMAP)ii.operator HBITMAP();
        CBitmap bm;
        bm.Attach(hbmp);
   
        CRect   rect;   
        GetClientRect(&rect);   
        CDC   dcMem;   
        dcMem.CreateCompatibleDC(&dc);   
        
        CBitmap   *pbmpOld=dcMem.SelectObject(&bm);   
        dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,   
        rect.Width(), rect.Height(), SRCCOPY);   
        CPen NewPen(PS_SOLID, 2, RGB(255,0,0));
        dc.SelectObject(&NewPen);
        dc.SetROP2(R2_COPYPEN);
        dc.SelectStockObject(NULL_BRUSH); 
        dc.Rectangle(rect.left+20,rect.top+ 30, 126,126);
        //      dc.SelectStockObject(NULL_BRUSH); 
        DeleteObject(&dcMem);
		CDialog::OnPaint();
	}
}

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:77540次
    • 积分:1601
    • 等级:
    • 排名:千里之外
    • 原创:55篇
    • 转载:9篇
    • 译文:9篇
    • 评论:38条
    最新评论