www.pudn.com > renliandesanweichongjian.rar > FaceDlg.cpp
// FaceDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Face.h"
#include "FaceDlg.h"
#include "Dib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
COpenGL m_openGL;
/////////////////////////////////////////////////////////////////////////////
// CFaceDlg dialog
CFaceDlg::CFaceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFaceDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFaceDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFaceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFaceDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFaceDlg, CDialog)
//{{AFX_MSG_MAP(CFaceDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OpenFile, OnOpenFile)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_FACERECONSTR, OnFacereconstr)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFaceDlg message handlers
BOOL CFaceDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CWnd *pWnd0= GetDlgItem(IDC_BMPSHOW);
pDCShow = pWnd0->GetDC();
m_pMainDib = new CDib();
m_tOriPixelArray = NULL;
m_tResPixelArray = NULL;
m_pResMap = NULL;
m_nWndWidth = 0;
m_nWndHeight= 0;
m_sFileName = "";
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFaceDlg::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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFaceDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFaceDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
////////////////////////////////////////////////////////////////////////////////
// 生成新的位图
////////////////////////////////////////////////////////////////////////////////
CFaceDlg::MakeBitMap()
{
CClientDC ClientDC(pDCShow->GetWindow());
if(m_pResMap!=NULL) delete m_pResMap;
m_pResMap=new CBitmap();
m_pResMap->CreateCompatibleBitmap(&ClientDC,m_nWndWidth,m_nWndHeight);
CDC dc;
dc.CreateCompatibleDC(&ClientDC);
dc.SelectObject(m_pResMap);
for(int i=0; im_pDibBits;
int byteBitCount = pDib->GetBiBitCount()/8;
m_tOriPixelArray = new RGBQUAD*[m_nWndHeight];
m_tResPixelArray = new RGBQUAD*[m_nWndHeight];
for(int l=0 ; l=0; i--)
{
for(int j=0; jOpen(strFile);
m_nWndWidth = m_pMainDib->GetWidth();
m_nWndHeight= m_pMainDib->GetHeight();
m_sFileName = strFile;
SetCursor(LoadCursor(NULL,IDC_WAIT));
//获取像素的值
LoadOriPixel(m_pMainDib);
MakeBitMap();
SetCursor(LoadCursor(NULL,IDC_ARROW));
}
////////////////////////////////////////////////////////////////////////////////
// 画图
////////////////////////////////////////////////////////////////////////////////
void CFaceDlg::MyDraw()
{
CRect rc;
pDCShow->GetWindow()->GetClientRect(&rc);
pDCShow->Rectangle(&rc);
CDC dc;
CBitmap *pOldBitmap;
dc.CreateCompatibleDC(pDCShow);
pOldBitmap=dc.SelectObject(m_pResMap);
pDCShow->StretchBlt(0,0,m_nWndWidth,m_nWndHeight,&dc,0,0,m_nWndWidth,m_nWndHeight,SRCCOPY);
dc.SelectObject(pOldBitmap);
dc.DeleteDC();
}
void CFaceDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent == 1) {
m_openGL.RenderGLScene();
}
CDialog::OnTimer(nIDEvent);
}
void CFaceDlg::OnFacereconstr()
{
// TODO: Add your control notification handler code here
CRect rect;
CWnd *pWnd0= GetDlgItem(IDC_BMPSHOW);
GetDlgItem(IDC_BMPSHOW)->GetWindowRect(rect);
ScreenToClient(rect);
m_openGL.Create(rect, pWnd0);
SetTimer(1, 50, NULL);
}