📄 okmfcview.cpp
字号:
//okCaptureThread(hBoard,BUFFER,0,3);//single
okCaptureTo(hBoard, BUFFER, 0, 1);//single
//okSleep(30);
times = okGetTickCount();
okGetCaptureStatus(hBoard, 1);
times = okGetTickCount() - times;
//buf->scr
exGetBitmapHeader(hBoard, BUFFER, lpbi);
exSetDataToDIB(BUFFER, 0, lpbi, (LPBYTE)lpdib);
//okStopCapture(hBoard);
}
lScrnOffset = exSetToWndRectEx(hBoard, hWnd, m_Centerscreen);
InvalidateRect(NULL, TRUE);
}
void COkMfcView::OnPaint()
{
// CPaintDC dc(this); // device context for painting
{
PAINTSTRUCT ps;
HDC hDC;
CDC* cdc;
LPBITMAPINFOHEADER lpBI;
LPBYTE lpDIB;
HDRAWDIB hdd;
//HPALETTE hPal;
//hWnd = GetSafeHwnd();
//hDC = ::BeginPaint(hWnd, &ps);
cdc = BeginPaint(&ps);
hDC = cdc->m_hDC;
exSetPaletteToWnd(hDC);
lpBI = lpbi;
lpDIB = (LPBYTE)lpdib;
if (lpBI)
{
RECT rect; POINT pt;
short scrbits;
scrbits = HIWORD(okSetCaptureParam(hBoard, CAPTURE_SCRRGBFORMAT, GETCURRPARAM));
GetClientRect(&rect);
if (lpBI->biHeight>rect.bottom)
rect.top = lpBI->biHeight-rect.bottom;
else
rect.top = 0;
//pt.x=rect.left;
//ClientToScreen(hWnd,&pt);
//adjust x abs. offset to 4 align
//pt.x=LOWORD(lScrnOffset);
//pt.x= pt.x%4 ? pt.x+4-pt.x%4 : pt.x;
//pt.y=HIWORD(lScrnOffset);
pt.x = LOWORD(lScrnOffset);
pt.y = HIWORD(lScrnOffset);
ClientToScreen(&pt);
//adjust x abs. offset to 4 align
pt.x = pt.x%4 ? pt.x+4-pt.x%4 : pt.x;
ScreenToClient(&pt);
hdd = DrawDibOpen(); //when to 8 bit dib on NT platform you should use function group DrawDib
//because they are too slow with GDI funtions group
// to use DrawDib you must add vfw.h and vfw32.lib
//hPal=exSetPaletteToWnd(hDC);
GetVersion();
if (m_MatchClient == 0)
if ((scrbits==8) && (lpBI->biBitCount != 8)) //only on NT4.0 need to do so
{
//DrawDibDraw can not support 16 and 32
DrawDibDraw(hdd, hDC, //you must add vfw32.lib
pt.x, pt.y,
lpBI->biWidth, lpBI->biHeight,
(LPBITMAPINFOHEADER)lpBI, lpDIB,
0, 0,
lpBI->biWidth, lpBI->biHeight,
//DDF_SAME_HDC );
DDF_BACKGROUNDPAL );
}
else //you can always use this on win95/98/2000
{
SetDIBitsToDevice(hDC,
pt.x, pt.y,
lpBI->biWidth, lpBI->biHeight,
0, 0,//rect.top,
0, lpBI->biHeight,
lpDIB,
(LPBITMAPINFO)lpBI,
DIB_RGB_COLORS
);
}
else //strech in order to match client rect
{
rect.left = pt.x;
rect.top = pt.y;
if ((iClientWidth > 0) && (iClientHeight>0))
{
rect.right = iClientWidth + rect.left;
rect.bottom = iClientHeight + rect.top;
}
if ((scrbits == 8) && (lpBI->biBitCount != 8)) //only on NT4.0 need to do so
{
DrawDibDraw(hdd, hDC,
rect.left,rect.top,
rect.right,rect.bottom,
(LPBITMAPINFOHEADER)lpBI, lpDIB,
0, 0,
lpBI->biWidth, lpBI->biHeight,
DDF_BACKGROUNDPAL );
}
else //you can always use this on win95/98/2000
{
SetStretchBltMode(hDC, STRETCH_DELETESCANS);
StretchDIBits(hDC,
rect.left, rect.top,
rect.right, rect.bottom,
0, 0,
lpBI->biWidth, lpBI->biHeight,
lpDIB, (LPBITMAPINFO)lpBI,
DIB_RGB_COLORS,SRCCOPY);
}
}
DrawDibClose(hdd);
}
EndPaint(&ps);
}
// Do not call CView::OnPaint() for painting messages
}
void COkMfcView::OnExttrigger()
{
//测试外触发
char string[128];
int trigger;
okCaptureToScreen(hBoard);
sprintf(string, " Waiting extern trigger...");
sBar->SetPaneText(0, string);
trigger = okWaitSignalEvent(hBoard, EVENT_EXTTRIGGER, 10000);//max 10 seconds
if (trigger == 1)
sprintf(string, " Extern trigger came.");
else if (trigger == -1)
sprintf(string, " Not support trigger");
else
sprintf(string, " Waiting time out");
okStopCapture(hBoard);
sBar->SetPaneText(0, string);
}
void COkMfcView::OnAbout()
{
//系统信息
CInfoBox infoBox;
infoBox.DoModal();
}
void COkMfcView::OnSignaleinfo()
{
//信号源信息
CSignBox signBox;
signBox.DoModal();
}
void COkMfcView::OnBacktoscreen()
{
//使序列采集显示
if (bDispToScreen)
bDispToScreen = 0;
else
bDispToScreen = 1;
}
void COkMfcView::OnUpdateBacktoscreen(CCmdUI* pCmdUI)
{
//菜单更新
pCmdUI->SetCheck(bDispToScreen);
}
void COkMfcView::OnCaptobuffer()
{
//序列采集到缓存
long num;
exEnableItem(IDM_FREEZE, TRUE);
okSetSeqCallback(hBoard, exBeginCapture, exBackDisplay, exEndCapture);
//okSetSeqProcWnd(hBoard,hWnd);
num = okGetBufferSize(hBoard, NULL, NULL);//
okCaptureTo(hBoard, BUFFER, 0, num);//
}
void COkMfcView::OnLooptobuffer()
{
//循环序列采集
exEnableItem(IDM_FREEZE, TRUE);
okSetSeqCallback(hBoard, exBeginCapture, exBackDisplay, exEndCapture);
//okSetSeqProcWnd(hBoard,hWnd);
okCaptureTo(hBoard, BUFFER, 0, -1);//-1: loop infiniately
//okCaptureSequence(hBoard, 0, -1);//-1: loop infiniately
}
void COkMfcView::OnSetupvideo()
{
//设置参数
okOpenSetParamDlg(hBoard, hWnd);
//dest(buffer) rect may be changed
exGetBitmapHeader(hBoard, BUFFER, lpbi);
//get current size
sampwidth = (short)lpbi->biWidth;
sampheight = (short)lpbi->biHeight;
lScrnOffset = exSetToWndRectEx(hBoard, hWnd, m_Centerscreen);
//get current mask mode
m_Enablemask = (short)okEnableMask(hBoard, -1);
if( !okSetConvertParam(hBoard,CONVERT_UPRIGHT,-1)) //rotate offed
{
m_UptoRight = TRUE;
m_UptoLeft = TRUE;
}
InvalidateRect(NULL, TRUE);
}
void COkMfcView::OnCapsequence()
{
//序列采集
total = okOpenSeqCaptureDlg(hBoard, hWnd);
//dest(buffer) rect may be changed
exGetBitmapHeader(hBoard, BUFFER, lpbi);
//get current size
sampwidth = (short)lpbi->biWidth;
sampheight = (short)lpbi->biHeight;
lScrnOffset = exSetToWndRectEx(hBoard, hWnd, m_Centerscreen);
}
void COkMfcView::OnUpdateCenterscreen(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_Centerscreen);
}
void COkMfcView::OnCenterscreen()
{
//使采集到屏幕中心
if (m_Centerscreen)
m_Centerscreen = 0;
else
m_Centerscreen = 1;
lScrnOffset = exSetToWndRectEx(hBoard, hWnd, m_Centerscreen);
InvalidateRect(NULL, TRUE);
}
void COkMfcView::OnEnablemask()
{
//允许采集位屏幕
if(m_Enablemask)
m_Enablemask = 0; //disable mask
else
m_Enablemask = 1; //positive mask
okEnableMask(hBoard, m_Enablemask); //set mask
}
void COkMfcView::OnReplaybuffer()
{
//回放缓存
total = (short)okGetBufferSize(hBoard, NULL, NULL);
okOpenReplayDlgEx(hBoard, hWnd, BUFFER, total, lpbi, (LPBYTE)lpdib);
}
void COkMfcView::OnReplaymemory()
{
//回放内存
int num;
num = dwMaxMemSize/exGetFrameSize(hBoard);
if (lpbi)
okOpenReplayDlgEx(hBoard, hWnd, (TARGET)lpMemory, num, lpbi, (LPBYTE)lpdib);
}
void COkMfcView::OnReplayfile()
{
//回放序列文件
char szFileName[128]="\0";
CSeqNum csf;
if (!exGetLoadName(hWnd, szFileName))
return;
if (stricmp(strrchr(szFileName, '.'), ".seq")) //non seq file
{
if (!csf.DoModal()) return;
}
else
//just get num
iNumImage = (short)okLoadImageFile(hBoard, szFileName, 0, SCREEN, 0, 0);
okOpenReplayDlgEx(hBoard, hWnd, (TARGET)szFileName, iNumImage, lpbi, (LPBYTE)lpdib);
}
void COkMfcView::OnBuffertoscreen()
{
//缓存0传到屏幕
exSetDataToDIB(BUFFER, 0, lpbi, (LPBYTE)lpdib);
InvalidateRect(NULL, FALSE);
}
void COkMfcView::OnScreentobuffer()
{
//屏幕传到缓存0
okConvertRect(hBoard, BUFFER, 0, SCREEN, 0, 1);
}
void COkMfcView::OnBuffer0tobuffer1()
{
//缓存0传到缓存1
okTransferRect(hBoard, BUFFER, 1, BUFFER, 0, 1);
}
void COkMfcView::OnBuffer1tobuffer0()
{
//缓存1传到缓存0
okTransferRect(hBoard, BUFFER, 0, BUFFER, 1, 1);
}
void COkMfcView::OnBuffertoframe()
{
//缓存0传到帧存
exEnableItem(IDM_FREEZE, TRUE);
if (okGetTypeCode(hBoard, NULL) == OK_M60) //special for M60 with frame
//can only by TransferRect for M60
okTransferRect(hBoard, FRAME, 0, BUFFER, 0, 1);
else
okConvertRect(hBoard, FRAME, 0, BUFFER, 0, 1);
}
void COkMfcView::OnFrametobuffer()
{
//帧存传到缓存0
okConvertRect(hBoard, BUFFER, 0, FRAME, 0, 1);
}
void COkMfcView::OnFrametoscreen()
{
//帧存传到屏幕
if (okConvertRect(hBoard, SCREEN, 0, FRAME, 0, 1) > 0)
{
//take buffer size
exGetBitmapHeader(hBoard, BUFFER, lpbi);
exSetDataToDIB(SCREEN, 0, lpbi, (LPBYTE)lpdib);
}
}
void COkMfcView::OnCaptomemory()
{
//序列采集到内存
exEnableItem(IDM_FREEZE, TRUE);
okSetSeqCallback(hBoard, exBeginCapture, exBackDisplay, exEndCapture);
if (lpbi) {
int num;
BLOCKINFO blk;
blk.iType = BLKHEADER;
blk.lpBits = (LPBYTE)lpMemory;
num = dwMaxMemSize/exGetFrameSize(hBoard);
lpMemory[0]=0;
//okCaptureByBuffer(hBoard, (TARGET)lpMemory, 0, num);
okCaptureByBuffer(hBoard,(TARGET)&blk,0,num);
}
}
void COkMfcView::OnCaptoseqfile()
{
//采集到文件
CSeqNum csf;
char szFileName[128]="\0";
if (!exGetSaveName(hWnd, szFileName))
return;
exEnableItem(IDM_FREEZE, TRUE);
okSetSeqCallback(hBoard, exBeginCapture, exBackDisplay, exEndCapture);
if (csf.DoModal())
{
//first delete ok.seq
DeleteFile(seqfile);
MessageBox(szFileName);
okCaptureByBuffer(hBoard, (TARGET)szFileName, 0, iNumImage);
}
else
{
exEnableItem(IDM_FREEZE, FALSE);
}
}
void COkMfcView::OnCaptoindirect()
{
//(经缓存)实时显示
exEnableItem(IDM_FREEZE, TRUE);
okSetConvertParam(hBoard, CONVERT_PALETTE, (LPARAM)NULL);
bDispToScreen = 2;
okSetSeqCallback(hBoard,exBeginCapture,exBackDisplay,exEndCapture);
//just capture to buffer
okCaptureByBuffer(hBoard, BUFFER, 0, 0);//0: cont.
}
void COkMfcView::OnCaptodirect()
{
//(待停)实时显
okStopCapture(hBoard);
//must not to upright
m_UptoRightCheck = FALSE;
m_UptoLeftCheck = FALSE;
okSetConvertParam(hBoard,CONVERT_UPRIGHT,0); //un to upright
lScrnOffset = exSetToWndRectEx(hBoard, hWnd, m_Centerscreen);
if (okCaptureToScreen(hBoard) <= 0)
MessageBox("Please try 256 color mode for B/W grabber, and 24 bits mode for color grabber.");
else {
MSG msg;
exEnableItem(IDM_ACTIVE, FALSE);
exEnableItem(IDM_FREEZE, TRUE);
bActive = 1;
//okCaptureTo(hBoard,BUFFER,0,0);//0: cont.
//SleepEx(40,TRUE);
SetCapture();
while (1) {
//PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
GetMessage(&msg, NULL, 0, 0);
if ((msg.message == WM_KEYDOWN) ||
(msg.message == WM_LBUTTONDOWN) ||
(msg.message == WM_NCLBUTTONDOWN)) {
break;
}
}
ReleaseCapture();
SendMessage(WM_COMMAND, IDM_FREEZE, 0);
InvalidateRect(NULL, TRUE);
//UpdateWindow(NULL);
}
}
void COkMfcView::OnCaptoforever()
{
//(恒久)实时显
//must to not match
m_MatchClient = 0;
//must not to upright
m_UptoRightCheck = FALSE;
m_UptoLeftCheck = FALSE;
okSetConvertParam(hBoard, CONVERT_UPRIGHT, 0); //un to upright
exGetBitmapHeader(hBoard, SCREEN, lpbi);
lScrnOffset = exSetToWndRectEx(hBoard, hWnd, m_Centerscreen);
//UpdateWindow(hWnd);
okStopCapture(hBoard); //confirm
//specail capture to frame
if (okGetTypeCode(hBoard, NULL) == OK_C70) {
okCaptureTo(hBoard, FRAME, 0, 0);
exEnableItem(IDM_ACTIVE, FALSE);
exEnableItem(IDM_FREEZE, TRUE);
} //normal to screen
else if (okCaptureToScreen(hBoard) <= 0)
MessageBox("Please try 256 color mode for B/W grabber, and 24 bits mode for color grabber.");
else {
exEnableItem(IDM_ACTIVE, FALSE);
exEnableItem(IDM_FREEZE, TRUE);
bActive = 2;
}
}
void COkMfcView::OnConttobuffer0()
{
//实时采到缓存0
exEnableItem(IDM_FREEZE, TRUE);
okCaptureTo(hBoard, BUFFER, 0, 0);
}
void COkMfcView::OnConttobuffer1()
{
//实时采到缓存1
exEnableItem(IDM_FREEZE, TRUE);
okCaptureTo(hBoard, BUFFER, 1, 0);
}
void COkMfcView::OnCaptoframe()
{
//实时采到帧存
exEnableItem(IDM_FREEZE, TRUE);
okCaptureTo(hBoard, FRAME, 0, 0); //cont.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -