?? videownd.cpp
字號(hào):
//NetTalk
/*------------------------------------------------------------------------------*\
=============================
模塊名稱: VideoWnd.cpp
=============================
//Download by http://www.codefans.net
[版權(quán)]
2000-2002 115軟件工廠 版權(quán)所有
\*------------------------------------------------------------------------------*/
#include "WndX.h"
#include "WindowsX.h"
#include "AVIOMgr.h"
#include "VideoWnd.h"
#include "resource.h"
#include <Stdio.h>
/*------------------------------------------------------------------------------*/
extern CAVIOMgr AVIO;
/*------------------------------------------------------------------------------*/
//copied from MSDN,and modified a little
BOOL SaveBitmapFile(HDC hDC, HBITMAP hBmp, PSTR pszFileName)
{
int hFile;
OFSTRUCT ofReOpenBuff;
HBITMAP hTmpBmp, hBmpOld;
BOOL bSuccess;
BITMAPFILEHEADER bfh;
PBITMAPINFO pbmi;
PBYTE pBits;
BITMAPINFO bmi;
PBYTE pjTmp, pjTmpBmi;
ULONG sizBMI;
bSuccess = TRUE;
if (!hBmp)
{
return FALSE;
}
// Let the graphics engine to retrieve the dimension of the bitmap for us
// GetDIBits uses the size to determine if it's BITMAPCOREINFO or BITMAPINFO
// if BitCount != 0, color table will be retrieved
bmi.bmiHeader.biSize = 0x28; // GDI need this to work
bmi.bmiHeader.biBitCount = 0; // don't get the color table
if ((GetDIBits(hDC, hBmp, 0, 0, (LPSTR)NULL, &bmi, DIB_RGB_COLORS)) == 0)
{
return FALSE;
}
// Now that we know the size of the image, alloc enough memory to retrieve
// the actual bits
if ((pBits = (PBYTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,bmi.bmiHeader.biSizeImage)) == NULL)
{
return FALSE;
}
// Note: 24 bits per pixel has no color table. So, we don't have to
// allocate memory for retrieving that. Otherwise, we do.
pbmi = &bmi;
// assume no color table
switch (bmi.bmiHeader.biBitCount)
{
case 24: // has color table
sizBMI = sizeof(BITMAPINFOHEADER);
break;
case 16:
case 32:
sizBMI = sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3;
break;
default:
sizBMI = sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*(1<<bmi.bmiHeader.biBitCount);
break;
} // // Allocate memory for color table if it is not 24bpp... //
if (sizBMI != sizeof(BITMAPINFOHEADER))
{
ULONG sizTmp; // // I need more memory for the color table //
if ((pbmi = (PBITMAPINFO)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizBMI )) == NULL)
{
bSuccess = FALSE;
goto ErrExit1;
} // // Now that we've a bigger chunk of memory, let's copy the Bitmap
// info header data over //
pjTmp = (PBYTE)pbmi;
pjTmpBmi = (PBYTE)&bmi;
sizTmp = sizeof(BITMAPINFOHEADER);
while(sizTmp--)
{
*(((PBYTE)pjTmp)++) = *((pjTmpBmi)++);
}
} // // Let's open the file and get ready for writing //
if ((hFile = OpenFile(pszFileName, (LPOFSTRUCT)&ofReOpenBuff,OF_CREATE | OF_WRITE)) == -1)
{
goto ErrExit2;
} // // But first, fill in the info for the BitmapFileHeader //
bfh.bfType = 0x4D42; // 'BM'
bfh.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizBMI+pbmi->bmiHeader.biSizeImage;
bfh.bfReserved1 =bfh.bfReserved2 = 0;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER)+sizBMI; // // Write out the file header now //
if (_lwrite(hFile, (LPSTR)&bfh, sizeof(BITMAPFILEHEADER)) == -1)
{
bSuccess = FALSE;
goto ErrExit3;
} // // Bitmap can't be selected into a DC when calling GetDIBits
// Assume that the hDC is the DC where the bitmap would have been selected
// if indeed it has been selected //
if (hTmpBmp = CreateCompatibleBitmap(hDC, pbmi->bmiHeader.biWidth, pbmi->bmiHeader.biHeight))
{
hBmpOld = (HBITMAP)SelectObject(hDC, hTmpBmp);
if ((GetDIBits(hDC, hBmp, 0, pbmi->bmiHeader.biHeight, (LPSTR)pBits, pbmi, DIB_RGB_COLORS))==0)
{
bSuccess = FALSE;
goto ErrExit4;
}
}
else
{
bSuccess = FALSE;
goto ErrExit3;
} // // Now write out the BitmapInfoHeader and color table, if any //
if (_lwrite(hFile, (LPSTR)pbmi, sizBMI) == -1)
{
bSuccess = FALSE;
goto ErrExit4;
} // // write the bits also //
if (_lwrite(hFile, (LPSTR)pBits, pbmi->bmiHeader.biSizeImage) == -1)
{
bSuccess = FALSE;
goto ErrExit4;
}
ErrExit4:
SelectObject(hDC, hBmpOld);
DeleteObject(hTmpBmp);
ErrExit3:
_lclose(hFile);
ErrExit2:
GlobalFree(pbmi);
ErrExit1:
GlobalFree(pBits);
return bSuccess;
}
/*------------------------------------------------------------------------------*/
CVideoWnd::CVideoWnd()
{
}
/*------------------------------------------------------------------------------*/
CVideoWnd::~CVideoWnd()
{
}
/*------------------------------------------------------------------------------*/
LRESULT CVideoWnd::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_SAVEFRAME://save the current frame to file
{
if(IsWindowVisible(m_vs))
{
char szPath[256];
GetModuleFileName(0,szPath,255);
int i;
for(i=strlen(szPath);i>0;i--)
{
if(szPath[i]=='\\')
{
szPath[i+1]=0;
break;
}
}
//use the time as the file name
SYSTEMTIME st;
GetLocalTime(&st);
char szFileName[50];
sprintf(szFileName,"photos\\%d_%d_%d_%d.bmp",st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);
strcat(szPath,szFileName);
HDC hdc=GetDC(m_hWnd);
SaveBitmapFile(hdc,m_vs.m_hBmp,szPath);
ReleaseDC(m_hWnd,hdc);
}
}
break;
case IDC_ZOOM:
{
if(m_bZoomed)
{
POINT pt[5]={{0,11},{11,0},{184,0},{184,168},{0,168}};
HRGN hrgn=CreatePolygonRgn(pt,5,ALTERNATE);
SetWindowPos(m_hWnd,0,0,0,184,168,SWP_NOMOVE);
SetWindowRgn(m_hWnd,hrgn,0);
m_bZoomed=FALSE;
SetRect(&m_rc,0,0,184,168);
SetRect(&m_rcVideo,4,20,180,164);
SetWindowPos(m_vs,0,0,0,m_rcVideo.Width(),m_rcVideo.Height(),SWP_NOMOVE);
InvalidateRect(m_hWnd,0,TRUE);
SetWindowPos(m_btnClose,0,167,5,0,0,SWP_NOSIZE);
}
else
{
POINT pt[5]={{0,11},{11,0},{360,0},{360,312},{0,312}};
HRGN hrgn=CreatePolygonRgn(pt,5,ALTERNATE);
SetWindowPos(m_hWnd,0,0,0,360,312,SWP_NOMOVE);
SetWindowRgn(m_hWnd,hrgn,FALSE);
m_bZoomed=TRUE;
SetRect(&m_rc,0,0,360,312);
SetRect(&m_rcVideo,4,20,356,308);
SetWindowPos(m_vs,0,0,0,m_rcVideo.Width(),m_rcVideo.Height(),SWP_NOMOVE);
InvalidateRect(m_hWnd,0,TRUE);
SetWindowPos(m_btnClose,0,343,5,0,0,SWP_NOSIZE);
}
}
break;
case IDC_CLOSE:
SendMessage(m_hWnd,WM_CLOSE,0,0);
break;
}
}
break;
case WM_INITDIALOG:
return OnInitDialog();
break;
case WM_MOUSEMOVE:
{
POINT point;
point.x=GET_X_LPARAM(lParam);
point.y=GET_Y_LPARAM(lParam);
OnMouseMove(wParam,point);
}
break;
case WM_LBUTTONDOWN:
{
POINT point;
point.x=GET_X_LPARAM(lParam);
point.y=GET_Y_LPARAM(lParam);
OnLButtonDown(wParam,point);
}
break;
case WM_CLOSE:
if(m_bLocal)
SendMessage(GetParent(m_hWnd),WM_COMMAND,IDC_VIDEO_LOCAL,0);
else
SendMessage(GetParent(m_hWnd),WM_COMMAND,IDC_VIDEO_OUTVIEW,0);
break;
case WM_DESTROY:
OnDestroy();
break;
case WM_ERASEBKGND:
return OnEraseBkgnd((HDC)wParam);
break;
case WM_TIMER:
OnTimer(wParam);
break;
default:
return CDialogX::WndProc(uMsg,wParam,lParam);
}
return TRUE;
}
/*------------------------------------------------------------------------------*/
BOOL CVideoWnd::OnInitDialog()
{
POINT pt[5]={{0,11},{11,0},{184,0},{184,168},{0,168}};
HRGN hrgn=CreatePolygonRgn(pt,5,ALTERNATE);
SetWindowRgn(m_hWnd,hrgn,0);
POINT pt2[5]={{2,11},{11,2},{119,2},{105,16,},{2,15}};
m_hrgnTitle=CreatePolygonRgn(pt2,5,ALTERNATE);
SetRect(&m_rcVideo,4,20,180,164);
SetRect(&m_rcTitle,2,2,119,16);
m_bZoomed=FALSE;
m_bHilight=FALSE;
m_btnZoom.LoadBitmaps(IDB_ZOOM1,IDB_ZOOM2,IDB_ZOOM3);
m_btnZoom.Associate(m_hWnd,IDC_ZOOM);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -