【正文】
MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CDetectAndTrackDlg message handlersBOOL CDetectAndTrackDlg::OnInitDialog(){ CDialog::OnInitDialog()。 // Add About... menu item to system menu. // IDM_ABOUTBOX must be in the system mand range. ASSERT((IDM_ABOUTBOX amp。 0xFFF0) == IDM_ABOUTBOX)。 ASSERT(IDM_ABOUTBOX 0xF000)。 CMenu* pSysMenu = GetSystemMenu(FALSE)。 if (pSysMenu != NULL) { CString strAboutMenu。 (IDS_ABOUTBOX)。 if (!()) { pSysMenuAppendMenu(MF_SEPARATOR)。 pSysMenuAppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu)。 } } // Set the icon for this dialog. The framework does this automatically // when the application39。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 (0,BackGround,WS_CHILD|WS_VISIBLE,CRect(10,10,330,310), this, 10000)。 (0,Detect,WS_CHILD|WS_VISIBLE,CRect(370,10,690,310), this,10001)。 (0,Difference,WS_CHILD|WS_VISIBLE,CRect(10,320,330,620), this,10002)。 //初始化不允許統(tǒng)計(jì) (CFrameWnd*)AfxGetMainWnd()GetMenu()EnableMenuItem(IDM_COUNT_OBJECTS,MF_GRAYED)。 return TRUE。 // return TRUE unless you set the focus to a control}void CDetectAndTrackDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID amp。 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout。 ()。 } else { CDialog::OnSysCommand(nID, lParam)。 }}// 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 CDetectAndTrackDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this)。 // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) (), 0)。 // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON)。 int cyIcon = GetSystemMetrics(SM_CYICON)。 CRect rect。 GetClientRect(amp。rect)。 int x = (() cxIcon + 1) / 2。 int y = (() cyIcon + 1) / 2。 // Draw the icon (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 CDetectAndTrackDlg::OnQueryDragIcon(){ return (HCURSOR) m_hIcon。}//獲取數(shù)據(jù)void CDetectAndTrackDlg::GetPoints(int nWidth, int nHeight, BYTE *pbtBits, BYTE *pbtPoints){ int x,y,p。 int nByteWidth=nWidth*3。 if (nByteWidth%4) nByteWidth+=4(nByteWidth%4)。 for(y=0。ynHeight。y++) { for(x=0。xnWidth。x++) { p=x*3+y*nByteWidth。 pbtPoints[x+y*nWidth]=(BYTE)(*(float)pbtBits[p+2]+*(float)pbtBits[p+1]+*(float)pbtBits[p]+)。 } }}//輸出數(shù)據(jù)void CDetectAndTrackDlg::PutPoints(int nWidth, int nHeight, BYTE *pbtBits, BYTE *pbtPoints){ int nByteWidth=nWidth*3。 if (nByteWidth%4) nByteWidth+=4(nByteWidth%4)。 int x,y,p,p1。 for(y=0。ynHeight。y++) { for(x=0。xnWidth。x++) { p=x*3+y*nByteWidth。 p1=x+y*nWidth。 pbtBits[p]=pbtPoints[p1]。 pbtBits[p+1]=pbtPoints[p1]。 pbtBits[p+2]=pbtPoints[p1]。 } }}//載入圖像void CDetectAndTrackDlg::LoadBitmap(){ BITMAPINFOHEADER *pInfo。 //位圖信息頭 pInfo=(BITMAPINFOHEADER *)(m_pbtBitmap+sizeof(BITMAPFILEHEADER))。 m_nWidth=pInfobiWidth。 //獲取位圖寬度(單位為像素) m_nByteWidth=m_nWidth*3。 //擴(kuò)展包含RGB分量 if (m_nByteWidth%4) m_nByteWidth+=4(m_nByteWidth%4)。 //字節(jié)寬度一定要是四的整數(shù)倍,不足應(yīng)該在后補(bǔ)零 m_nHeight=pInfobiHeight。 //獲取位圖高度 if (pInfobiBitCount!=24) //判斷是否為真彩色位圖 { if (pInfobiBitCount!=8) //只處理256灰度級(jí)的位圖 { AfxMessageBox(無(wú)效位圖)。 //發(fā)出警告 delete m_pbtBitmap。 //刪除位圖 m_pbtBitmap=0。 //為下次加載做初始化 return。 } unsigned int PaletteSize=1pInfobiBitCount。 //獲取調(diào)色板大小 if (pInfobiClrUsed!=0 amp。amp。 pInfobiClrUsedPaletteSize) //判斷文件中出現(xiàn)的灰度色級(jí)是否超出biBitCount所表示的范圍. PaletteSize=pInfobiClrUsed。 m_pbtBits=m_pbtBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)。 //獲取顏色表指針 RGBQUAD *pPalette=(RGBQUAD *)m_pbtBits。 //定義顏色表結(jié)構(gòu),并讓其指向位圖文件中的顏色表 m_pbtBits+=sizeof(RGBQUAD)*PaletteSize。 //讓lpBits指向BMP文件的IMAGEDATA區(qū)域 m_nLen=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+m_nByteWidth*m_nHeight。 //計(jì)算文件大小 BYTE *lpTemp=m_pbtBitmap。 m_pbtBitmap=new BYTE[m_nLen]。 //開辟空間 BITMAPFILEHEADER bmh。 //定義位圖文件頭結(jié)構(gòu) BITMAPINFOHEADER bmi。 //定義位圖信息頭結(jié)構(gòu) =39。B39。+39。M39。*256。 //文件類型賦值為位圖類型 =m_nLen。 //文件大小為m_nLen =0。 //保留值必須為0 =0。 =54。 //文件頭到數(shù)據(jù)的偏移 =sizeof(BITMAPINFOHEADER)。 //固定值 =m_nWidth。 //位圖寬度 =m_nHeight。 //位圖高度 =1。 //目標(biāo)設(shè)備的位面數(shù),必須為1 =24。 //顏色深度,即每個(gè)像素占24位 =BI_RGB。 //壓縮類型為BI_RGB =0。 =0。 //水平分辨率 =0。 //垂直分辨率 =0。 //表示使用2的biBitCount次方的色級(jí) =0。 //無(wú)重要顏色 int nBWidth=pInfobiWidth。 //獲取位圖寬度 if (nBWidth%4) nBWidth+=4(nBWidth%4)。 // memset(m_pbtBitmap,0,m_nLen)。 //清零函數(shù) memcpy(m_pbtBitmap,amp。bmh,sizeof(BITMAPFILEHEADER))。 //將BITMAPFILEHEADER內(nèi)容拷到到bmh中 memcpy(m_pbtBitmap+sizeof(BITMAPFILEHEADER),amp。bmi,sizeof(BITMAPINFOHEADER))。 //將BITMAPINFOHEADER內(nèi)容拷到bmi中 BYTE*lpBits2=m_pbtBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)。 //lpBits2指向調(diào)色板 int x,y,p1,p2,Palette。 //像素色彩值的讀取 for(y=0。ym_nHeight。y++) { for(x=0。xm_nWidth。x++) {p1=y*nBWidth+x。 //取得像素下標(biāo) p2=y*m_nByteWidth+x*3。 //三個(gè)一組的移動(dòng) if (m_pbtBits[p1]PaletteSize) Palette=m_pbtBits[p1]。 //取得在biClrUsed范圍的象素值,如果超出范圍則賦值為0 else Palette=0。 lpBits2[p2]=pPalette[Palette].rgbBlue。 lpBits2[p2+1]=pPalette[Palette].rgbGreen。 //對(duì)調(diào)色板的分量進(jìn)行賦值 lpBits2[p2+2]=pPalette[Palette].rgbRed。 } } delete lpTemp。 } m_pbtBits=m_pbtBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)。 //對(duì)于真彩色位圖直接獲取IMAGEDATA if (m_p