15,979
社区成员
发帖
与我相关
我的任务
分享
void CMFCImageDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
。。。。。。。省略
//显示CImage图片
img_show = img1;
CWnd *pWnd = GetDlgItem(IDC_STATIC);//获得pictrue控件窗口的句柄
CDC *pDC = pWnd->GetDC();//获得pictrue控件的DC
if (!img_show.IsNull())
{
img_show.Draw(pDC->m_hDC, pic_rect); //将图片画到Picture控件表示的矩形区域
}
ReleaseDC(pDC);//释放picture控件的DC
}
void CMFCImageDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
GetClientRect(&dlg_rect);
GetDlgItem(IDC_BUTTON1)->GetClientRect(&btn_rect);
GetDlgItem(IDC_STATIC)->GetClientRect(&pic_rect);
//设置按钮的位置
btn_rect.MoveToX(dlg_rect.right - 100);
btn_rect.MoveToY(dlg_rect.top + 50);
//设置图片控价的大小
if (get_image == true)
{
pic_rect.right = 3 * dlg_rect.Width() / 4;
pic_rect.bottom = pic_rect.right * aspect_ratio;
}
else
{
pic_rect.right = 3 * dlg_rect.Width() / 4;
pic_rect.bottom = dlg_rect.Height();
}
GetDlgItem(IDC_STATIC)->MoveWindow(pic_rect);
GetDlgItem(IDC_BUTTON1)->MoveWindow(btn_rect);
//显示CImage图片
CWnd *pWnd = GetDlgItem(IDC_STATIC);//获得pictrue控件窗口的句柄
CDC *pDC = pWnd->GetDC();//获得pictrue控件的DC
pDC->FillSolidRect(pic_rect, RGB(0, 0, 0));
if (!img1.IsNull())
{
img_show = img1;
img_show.Draw(pDC->m_hDC, pic_rect);
}
ReleaseDC(pDC);//释放picture控件的DC
}