📄 demodlg.cpp
字号:
// DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PPPServer.h"
#include "DemoDlg.h"
#include "pppserverdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CPPPServerDlg *m_main_dlg;
extern bool m_all_run_flag;
extern CList<LOGFONT,LOGFONT&> m_all_logfont;
extern SYSTEM_PARAMETER m_system_para;
#define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog
CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemoDlg::IDD, pParent)
{
m_pGraph = NULL;
m_pMediaControl = NULL;
m_pEvent = NULL;
m_pMediaSeeking = NULL;
pBV=NULL;
//m_strMediaFile = "";
m_isPlaying = FALSE;
m_video_finished_flag=false;
//{{AFX_DATA_INIT(CDemoDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemoDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
//{{AFX_MSG_MAP(CDemoDlg)
ON_WM_PAINT()
ON_WM_LBUTTONUP()
ON_WM_SIZE()
ON_WM_MOVE()
ON_MESSAGE(WM_GRAPHNOTIFY, OnGraphNotify)
ON_MESSAGE(WM_STOPVIDEO,OnStopVideo)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg message handlers
BOOL CDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//自定义调色板 for gif
for(int ii=0;ii<256;ii++)
{
user_myrgb[3*ii+0]=ii;
user_myrgb[3*ii+1]=ii;
user_myrgb[3*ii+2]=ii;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDemoDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if(m_isPlaying == FALSE)
{
// CClientDC dc(GetDlgItem(IDC_VW_FRAME));
dc.SetBkColor(RGB(0,0,0));
CRect rc;//(0,0,320,240);
//GetDlgItem(IDC_VW_FRAME)->
GetClientRect(rc);
//ClientToScreen(rc);
dc.FillRect(rc, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
// GetDlgItem(IDC_VW_FRAME)->Invalidate();
}
// Do not call CDialog::OnPaint() for painting messages
}
void CDemoDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
::PostMessage(m_main_dlg->GetSafeHwnd(),WM_SHOW_MAINWND_MESSAGE,0,0);
CDialog::OnLButtonUp(nFlags, point);
}
///////////////////////////////////////////////////
void CDemoDlg::ShowTextFile(CString filename,int in,int out,long speed,long delaytime,TEXTPROPERTY tp)
{
// TEXTPROPERTY
FILE *fp1;
fp1=_tfopen(filename,L"rb");
if(!fp1) return;
LOGFONT lg,lf;
memset(&lf, 0, sizeof(LOGFONT)); // Zero out the structure.
POSITION pos=m_all_logfont.FindIndex( tp.m_text_font_name);
if(pos)
{
lg=m_all_logfont.GetAt(pos);
lf=lg;
//lstrcpy(lf.lfFaceName, lg.lfFaceName);
lf.lfWidth=tp.m_text_font_width;
lf.lfHeight=tp.m_text_font_height;
//fc,bc
}
else
{
lf.lfHeight = 16; // Request a 16-pixel-height font.
lf.lfWidth =16 ;
lstrcpy(lf.lfFaceName, _T("Arial")); // Request a face name "Arial".
}
CFont font;
//create font
VERIFY(font.CreateFontIndirect(&lf)); // Create the font.
CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
//rect.Width
DWORD w,h;
w=rect.Width();
h=rect.Height();
//create brush for fillrect by black color
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
CDC MemDC;
CBitmap tmpbmp,*oldbmp;
// CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
// CBitmap tmpbmp,*oldbmp;
tmpbmp.CreateCompatibleBitmap(&dc,w,h);
oldbmp=MemDC.SelectObject(&tmpbmp); //
//MemDC.SetBkMode(TRANSPARENT);
//cls
MemDC.FillRect(CRect(0,0,w,h),&brush);
//select cur font
CFont* def_font = MemDC.SelectObject(&font);
//set text color
//set bkcolor
MemDC.SetTextColor(tp.m_text_fc_color);
MemDC.SetBkColor(tp.m_text_bc_color);
//set text property
//MemDC.m_hDC
// HDC hdc; // handle to device context
TEXTMETRIC tm; // structure for text metrics
//hdc = ::GetDC(this->m_hWnd);
//GetTextMetrics(hdc, &tm);
::GetTextMetrics(MemDC.m_hAttribDC,&tm);
///
// Save the average character width and height.
DWORD dwCharX; // average width of characters
DWORD dwCharY; // height of characters
dwCharX = tm.tmAveCharWidth;
dwCharY = tm.tmHeight;
///
DWORD dwLineLen; // line length
DWORD dwLines; // text lines in client area
//
dwLineLen = w - dwCharX;
dwLines = h / dwCharY;
//
//// Retrieve the character's width
// the character.
int nCharWidth = 0; // width of a character
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
TCHAR ch[2];
DWORD X,Y;
X=0;
Y=0;
FILE *fp;
fp=_tfopen(filename,L"rb");
//if(!fp) goto exit_text;
while(!feof(fp))
{
if(m_all_run_flag==false) break;
//
if(fread((char *)&ch[0],1,sizeof(ch[0]),fp)!=sizeof(ch[0])) break;
//
// if( ferror( fp ) )
// {
//debug
// int k,d;
// k=0;
// d=k;
// }
if(ch[0]<_T(' '))//0x20
{
if(ch[0]==_T('\n'))
{
//
X = 0;
++Y;
if(Y>=dwLines)
{
Y=0;
//draw cur full text pic
//....
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//
Sleep(delaytime);
//cls
MemDC.FillRect(CRect(0,0,w,h),&brush);
}
}
continue;
}
//
ch[1]=NULL;
GetCharWidth32(MemDC.m_hAttribDC, ch[0], ch[0], &nCharWidth);
// nCharWidth=GetFontSizeW(MemDC.m_hAttribDC, ch, 1);
if(X+nCharWidth>w)
{
X=0;
++Y;
if(Y>=dwLines)
{
Y=0;
//draw cur full text pic
//....
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//delaytime
Sleep(delaytime);
//cls
MemDC.FillRect(CRect(0,0,w,h),&brush);
}
//
}
//DRAW CHAR nCaretPosY * dwCharY
MemDC.ExtTextOut(X, Y*dwCharY, ETO_OPAQUE, NULL, ch, 1,NULL);
X += nCharWidth;
}
//the rest half screen text
if(Y>0||X>0)
{
//draw cur full text pic
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//delaytime
Sleep(delaytime);
}
///////////////////////////////////////////////////////
//close file
fclose(fp);
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//exit_text:
//....
//delete brush
brush.DeleteObject();
//DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//::ReleaseDC(this->m_hWnd, hdc);
//release font
MemDC.SelectObject(def_font);
//Finished with the font, now delete the font object.
font.DeleteObject();
//releasse dc and bitmap
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
}
void CDemoDlg::ShowPicture(CString filename,int in,int out,long speed,long delaytime,int position)
{
if(filename.IsEmpty()) return;
FILE *fp;
fp=_tfopen(filename,L"rb");
if(!fp) return;
fclose(fp);
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
CDC MemDC;
CBitmap tmpbmp,*oldbmp;
//CString filename;
CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
int w,h;
w=rect.Width();
h=rect.Height();
//draw picture:bmp,jpg,jpeg,gif(pic),others:png,etc.
MemDC.CreateCompatibleDC(&dc);
tmpbmp.CreateCompatibleBitmap(&dc,w,h);
oldbmp=MemDC.SelectObject(&tmpbmp);
CVOImage m_image;
//MemDC.GetSafeHdc()
//Load pic file
if(!m_image.Load(MemDC.GetSafeHdc(),filename))
{
//release resource
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
return;
}
//copy...
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
long pw,ph;
pw=m_image.GetWidth();
ph=m_image.GetHeight();
if(position==0)//center
{
long sx,sy;
if(pw>=w)
sx=0;
else
sx=(w-pw)/2;
///////////////////
if(ph>=h)
sy=0;
else
sy=(h-ph)/2;
//draw
m_image.Draw(MemDC.GetSafeHdc(),sx,sy,pw,ph);
}
else if(position==1)//stretch
{
//draw
m_image.Draw(MemDC.GetSafeHdc(),0,0,w,h);
}
else//flat--对视频无效
{
CBitmap tb,*ob;
CDC mdc;
//######################################################################
mdc.CreateCompatibleDC(&dc);
tb.CreateCompatibleBitmap(&dc,pw,ph);
ob=mdc.SelectObject(&tb);
//draw
m_image.Draw(mdc.GetSafeHdc(),0,0,pw,ph);
//flat 贴图
int xx,yy;
xx=w/pw;
yy=h/ph;
if(w%pw!=0) xx++;
if(h%ph!=0) yy++;
//水平方向://垂直方向
for(int i=0;i<xx;i++)
for(int j=0;j<yy;j++)
{
MemDC.BitBlt(i*pw, j*ph, pw,ph, &mdc, 0, 0, SRCCOPY);
}
////内部 release resource
mdc.SelectObject(ob);
tb.DeleteObject();
mdc.DeleteDC();
}
//
//SHOW==========================================
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//
//release resource
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
//#################################################
}
void CDemoDlg::ShowGifAni(CString filename,long speed,long times,int position)
{
CClientDC dc(this);
//LPCGLOBAL_INFO gi;
// LPCFRAME fm;
//
//CGif89a gif;
// HBITMAP m_hBitmap;
// BYTE *imageData;
//
//打开GIF图象文件
//
if(!gif.open(filename,false))
{
//AfxMessageBox(TEXT("open gif error"),MB_OK);
return;
}
//Memo1->Lines->Add("版本="+StrPas(gif.getVer())+"\r\n");
gi = gif.getGlobalInfo();
//get data to buffer
imageData= (UNALIGNED BYTE*)::malloc(gi->scrWidth*gi->scrHeight*3);
if(!imageData)
{
gif.close();
return ;
}
//create dc buffer
//MemDC.CreateCompatibleDC(&dc);
CRect rect;
GetClientRect(&rect);
long ttt=times;
if(ttt<=0) ttt=1;
for(int kkk=0;kkk<ttt;kkk++)
{
if(m_all_run_flag==false) break;
//reset gif
gif.Reset();
//显示所有显示帧画面
for(UINT n=0;n<gi->frames;n++)
{
if(m_all_run_flag==false) break;
// get cur gif frame
fm = gif.getNextFrame();
if(fm == NULL)
{
gif.close();
::free(imageData);
imageData=NULL;
return;
}
if(m_all_run_flag==false) break;
//Load cur frame
HBITMAP m_hBitmap;
m_hBitmap =LoadGifCurFrame(imageData,gi,fm);
if (! m_hBitmap)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -