⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 Windows 2000下PCI数据采集卡WDM驱动,非常完整
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if (m_hOldPal && (m_pBmpInfo->bmiHeader.biBitCount == 8)) {
		::SelectPalette(pDC->GetSafeHdc(), m_hOldPal, FALSE);
		::RealizePalette(pDC->GetSafeHdc());
	}

}




void CMainFrame::OnSnapOne() 
{
	// TODO: Add your command handler code here
	BOOL bRead = FALSE;

	int nWidth = 0, nHeight = 0;
	
	nWidth	= MAX_WIDTH - m_nXDelay;
	nWidth	= nWidth - nWidth % 4;
	nHeight = MAX_HEIGHT- m_nYDelay;
	nHeight = nHeight - nHeight % 2;


	if (m_bDecode) {
		if (ReadImage(m_pSrcData, 0, m_nXDelay, m_nYDelay, MAX_WIDTH, MAX_HEIGHT)) {
			DecodeImage(m_pImageBuffer, m_pSrcData, nWidth, nHeight);	
			m_pBmpInfo->bmiHeader.biBitCount	= 24;
			bRead = TRUE;
		}
	}
	else{
		if (ReadImage(m_pImageBuffer, 0, m_nXDelay, m_nYDelay, MAX_WIDTH, MAX_HEIGHT)) {
			m_pBmpInfo->bmiHeader.biBitCount	= 8;
			bRead = TRUE;
		}
	}

	if (bRead) {
		CView *pView = GetActiveView();
		ASSERT(pView);
		CDC *pDC = pView->GetDC();
		ASSERT(pDC);
		
		m_pBmpInfo->bmiHeader.biWidth		= nWidth;
		m_pBmpInfo->bmiHeader.biHeight		= nHeight;

			
		ShowImage(pDC);	

		pView->ReleaseDC(pDC);
	}
	
}

void CMainFrame::OnDecode() 
{
	// TODO: Add your command handler code here
	m_bDecode = !m_bDecode;
}

void CMainFrame::OnUpdateDecode(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_bDecode);
}

void CMainFrame::OnLoad() 
{
	// TODO: Add your command handler code here
	DSPSTATUS status	= DSP_OK;
	HDSP100 hdsp		= NULL;

	DWORD dwSegment		= 0;
	DWORD dwOffset		= 0;
	
	DWORD dwData		= 0;

	DWORD dwAddress		= 0;
	DWORD dwPages       = 0;

	HANDLE hMap			= NULL;
	BYTE *pBuffer		= NULL;
	
	CFileDialog dlg(TRUE, "bin", "*.bin", 0, "DSP Program Files (*.bin)|*.bin", NULL);
	
	if (dlg.DoModal() == IDOK) {
		status = BeginDSP100(1, &hdsp);
		
		//Lock 4m memory window
		status = DSP100LockMem(hdsp, -1, -1 , &hMap, (PVOID *)&pBuffer);
		
		if (DSP_SUCCESS(status)) {
			//Reset DSP
			status = DSP100ReadPortULong(hdsp, HDCR, &dwData);
			if (DSP_SUCCESS(status)) {
				dwData |= 0x1;
				status = DSP100WritePortULong(hdsp, HDCR, dwData);
			}
			
			//Load bin file to interal program RAM
			status = DSP100WritePortULong(hdsp, DSPP, 0x400);
			status = DSP100LoadProgram(pBuffer, dlg.GetPathName().GetBuffer(0));
			
			//Initialize DSP write and PCI only read zone
			dwSegment	=  0x8000ffe0 / 0x400000;
			dwSegment	|= 0x400;
			dwOffset	=  0x8000ffe0 % 0x400000;
			DSP100WritePortULong(hdsp, DSPP, dwSegment);
			ZeroMemory(pBuffer + dwOffset, 32 * 4);

			//Initialize PCI write and DSP only read zone
			dwSegment	=  0x8000ffc0 / 0x400000;
			dwSegment	|= 0x400;
			dwOffset	=  0x8000ffc0 % 0x400000;
			DSP100WritePortULong(hdsp, DSPP, dwSegment);
			ZeroMemory(pBuffer + dwOffset, 32 * 4);
		
			//Set static memory physcial address
			if (DvcGetStaticMem(&dwPages, &dwAddress)) {
				*((DWORD *)(pBuffer + dwOffset)) = dwAddress;

				//Set DSPINT and release dsp from reset
				status = DSP100ReadPortULong(hdsp, HDCR, &dwData);
				if (DSP_SUCCESS(status)) {
					dwData |= 0x2;
					status = DSP100WritePortULong(hdsp, HDCR, dwData);
				}
			}

			//Read DSP zone
			dwSegment	=  0x8000ffe0 / 0x400000;
			dwSegment	|= 0x400;
			dwOffset	=  0x8000ffe0 % 0x400000;
			DSP100WritePortULong(hdsp, DSPP, dwSegment);
			dwData = *((DWORD *)(pBuffer + dwOffset));
			
			dwData = *((DWORD *)(pBuffer + dwOffset) + 1);

			//Unlock 
			status = DSP100UnlockMem(hdsp, hMap);
		}
		
		status = EndDSP100(hdsp);
	}
}



void CMainFrame::OnClear() 
{
	// TODO: Add your command handler code here
	DWORD dwSize = 0, dwAddr = 0;
	SECTION_MAP_INFO info = {0};

	if (DvcGetStaticMem(&dwSize, &dwAddr)) {
		info.dwStartOffset = 0;
		info.dwLength = dwSize * 4 * 1024;

		if (DvcStaticMemLock(&info)) {
			ZeroMemory(info.pLinearAddress, info.dwLength);
			DvcStaticMemUnlock(&info);
			
			SendMessage(WM_COMMAND, ID_SHOW, 0);
		}
	}
}



void CMainFrame::OnFlip() 
{
	// TODO: Add your command handler code here
	m_bFlip = !m_bFlip;
}



void CMainFrame::OnUpdateFlip(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_bFlip);	
}





void CMainFrame::OnSnappingNumber() 
{
	// TODO: Add your command handler code here
	CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();	
	CString str;

	DSPSTATUS status	= DSP_OK;
	HDSP100 hdsp		= NULL;
	
	DWORD dwSegment		= 0;
	DWORD dwOffset		= 0;
	
	DWORD dwData		= 0;
	
	DWORD dwAddress		= 0;
	DWORD dwPages       = 0;
	
	HANDLE hMap			= NULL;
	BYTE *pBuffer		= NULL;
	
	if (pFrame) {
		status = BeginDSP100(1, &hdsp);
		
		//Lock 4m memory window
		status = DSP100LockMem(hdsp, -1, -1 , &hMap, (PVOID *)&pBuffer);
		
		if (DSP_SUCCESS(status)) {
			//Read DSP zone
			dwSegment	=  0x8000ffe0 / 0x400000;
			dwSegment	|= 0x400;
			dwOffset	=  0x8000ffe0 % 0x400000;
			DSP100WritePortULong(hdsp, DSPP, dwSegment);
			
			
			for (int i = 0; i < 10000; i++){
				dwData = *((DWORD *)(pBuffer + dwOffset));
				str.Format("%d", dwData);
				pFrame->SetWindowText(str);
		//		Sleep(100);
			}
			
			//Unlock 
			status = DSP100UnlockMem(hdsp, hMap);
		}

		status = EndDSP100(hdsp);

	}
}

void CMainFrame::OnSnapContinue() 
{
	// TODO: Add your command handler code here
	MSG msg;

	DSPSTATUS status	= DSP_OK;
	HDSP100 hdsp		= NULL;
	
	DWORD dwSegment		= 0;
	DWORD dwOffset		= 0;
	
	DWORD dwData		= 0;
	
	DWORD dwAddress		= 0;
	DWORD dwPages       = 0;
	
	HANDLE hMap			= NULL;
	BYTE *pBuffer		= NULL;

	DWORD dwMemOff		= 0;
	DWORD dwLastNum		= -1;

	BOOL bRead			= FALSE;

	int nWidth = 0, nHeight = 0;

	CView *pView = GetActiveView();
	ASSERT(pView);
	CDC *pDC = pView->GetDC();
	ASSERT(pDC);

	nWidth	= MAX_WIDTH - m_nXDelay;
	nWidth	= nWidth - nWidth % 4;
	nHeight = MAX_HEIGHT- m_nYDelay;
	nHeight = nHeight - nHeight % 2;

	m_pBmpInfo->bmiHeader.biWidth		= nWidth;
	m_pBmpInfo->bmiHeader.biHeight		= nHeight;
	
	status = BeginDSP100(1, &hdsp);
	
	//Lock 4m memory window
	status = DSP100LockMem(hdsp, -1, -1 , &hMap, (PVOID *)&pBuffer);
	
	if (DSP_SUCCESS(status)) {
		//Read DSP zone
		dwSegment	=  0x8000ffe0 / 0x400000;
		dwSegment	|= 0x400;
		dwOffset	=  0x8000ffe0 % 0x400000;
		DSP100WritePortULong(hdsp, DSPP, dwSegment);
		
		while(1){
			dwData = *((DWORD *)(pBuffer + dwOffset));

			if ((dwData != dwLastNum)) {
				dwLastNum = dwData;
					
				dwMemOff = dwData * MAX_WIDTH * MAX_HEIGHT;
				
				bRead = FALSE;
				
				if (m_bDecode) {
					if (ReadImage(m_pSrcData, dwMemOff, m_nXDelay, m_nYDelay, MAX_WIDTH, MAX_HEIGHT)) {
						DecodeImage(m_pImageBuffer, m_pSrcData, nWidth, nHeight);	
						m_pBmpInfo->bmiHeader.biBitCount	= 24;
						bRead = TRUE;
					}
				}
				else{
					if (ReadImage(m_pImageBuffer, dwMemOff, m_nXDelay, m_nYDelay, MAX_WIDTH, MAX_HEIGHT)) {
						m_pBmpInfo->bmiHeader.biBitCount	= 24;
						bRead = TRUE;
					}
				}
				
				if (bRead) {
					ShowImage(pDC);	
				}
			}
							
			if (PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE)) {
				if( (GetKeyState(VK_ESCAPE) & 0x80) == 0x80 ){
					break;
				}
				
		//		TranslateMessage(&msg);
		//		DispatchMessage(&msg);
			}
		}
		
		//Unlock 
		status = DSP100UnlockMem(hdsp, hMap);
	}
	
	status = EndDSP100(hdsp);

	pView->ReleaseDC(pDC);
	
}



void CMainFrame::OnUpdateSnapContinue(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here

}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	

	CFrameWnd::OnClose();
}

void CMainFrame::OnUpdateSnapOne(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
}

void CMainFrame::OnUpdateSnapNumber(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -