picture control

来源:互联网 发布:治风湿病专科医院知乎 编辑:程序博客网 时间:2024/04/28 21:26
 

DDX_Control(pDX, IDC_STATIC_PICTURE, m_picture);

 // TODO: 在此添加控件通知处理程序代码
 HBITMAP hBmp = LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP2) );

 BITMAP   bmp;
 GetObject(hBmp,sizeof(bmp),&bmp);
 CRect rc;
 GetClientRect(&rc);

 if (bmp.bmHeight>rc.Height() )
 {
  rc.bottom = rc.top + bmp.bmHeight;
  MoveWindow(&rc);
  m_picture.MoveWindow(&rc);
 }

 if (bmp.bmWidth>rc.Width() )
 {
  rc.right = rc.left + bmp.bmWidth;
  MoveWindow(&rc);
  m_picture.MoveWindow(&rc);
 }
 m_picture.SetBitmap(hBmp);

 

 

void CpictureDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // 用于绘制的设备上下文

  SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

  // 使图标在工作矩形中居中
  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;

  // 绘制图标
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CDialog::OnPaint();
 }
}