MFC 填充系统 方法记录

1.设置按钮图片

 HBITMAP hbitmap;
 hbitmap = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(130));  //资源id 130
 ((CButton *)GetDlgItem(1005))->SetBitmap(hbitmap);
 ((CButton *)GetDlgItem(1006))->SetBitmap(hbitmap);

 

2.在onPaint 里响应的dc CPaintDC 其他函数内无效

void CregionTracingDlg::initColorPane(CStatic *cp, COLORREF color)
{
 CPaintDC ColorPaneDc(cp);

 CRect rect;
 cp->GetWindowRect(&rect);
 CBrush brs;
 CRect picrct;
 picrct.top = 0;
 picrct.left = 0;
 picrct.bottom = rect.Height();
 picrct.right = rect.Width();
 brs.CreateSolidBrush(color);
 ColorPaneDc.FillRect(&picrct, &brs);
}

 

3.通用文件对话框

 CFileDialog dlg(TRUE, _T("*.bmp"), NULL, OFN_FILEMUSTEXIST, _T("Bitmap File(*.bmp)|*.bmp|JPG Files (*.jpg)|*.jpg||"),NULL);
 
 
 if (dlg.DoModal() == IDOK)
 {}

 

4.动态设置指针

BOOL CregionTracingDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
 // TODO:  在此添加消息处理程序代码和/或调用默认值
 if (cursorFlag != 0)
 {
  HCURSOR m_cursorCur = LoadCursor(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDC_CURSOR1));
  SetCursor(m_cursorCur);
  return true;
 }
 
 return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

 

5.获取当前鼠标单击点的颜色

void CregionTracingDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
 // TODO:  在此添加消息处理程序代码和/或调用默认值
 if (cursorFlag == 1)
 {

  targetColor= GetPixel(this->GetDC()->GetSafeHdc(),point.x,point.y);

  refreshColorPane();
  cursorFlag = 0;
 }
 else if (cursorFlag == 2)
 {
  backgroundColor = GetPixel(this->GetDC()->GetSafeHdc(), point.x, point.y);

  refreshColorPane();
  cursorFlag = 0;
 }

 CDialogEx::OnLButtonDown(nFlags, point);
}


 

转载于:https://www.cnblogs.com/tyks/p/5059872.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值