如何编写Autorun.inf令视频程序自动运行?

如何编写Autorun.inf令视频程序自动运行?,第1张

经常使用光盘的朋友都知道,有很多光盘放入光驱就会自动颤野派运行,它们是怎么做的呢?光盘一放入光驱就会自动被执行,主要依靠两个文件,一是光盘上的AutoRun.inf文件,另一个是 *** 作系统本身的系统文件之一的Cdvsd.vxd。Cdvsd.vxd会随时侦脊咐测光驱中是否有放入光盘的动作,如果有的话,便开始寻找光盘根目录下的AutoRun.inf文件。如果存在AutoRun.inf文件则执行它里面的预设程序。

AutoRun.inf不光能让光盘自动运行程序,也能让硬盘自动运行程序,方法很简单,先打开记事本,然后用鼠标右键点击该文件,在d出菜单中选择“重命名”,将其改名为AutoRun.inf,在AutoRun.inf中键入以下内容(//后面的是注释,可以不输入):

[AutoRun] //表示AutoRun部分开始,必须输入

Icon=C.ico //给光盘一个个性化的盘符图标C.ico

Open=1.exe //指定要运行程序的路径和名称,在此为光盘下的1.exe

保存该文件,按F5刷新桌面,再看“我的电脑”中的该盘符(在此为C盘),茄贺你会发现它的磁盘图标变了,还会自动播放光盘下的1.exe文件!

解释一下:“[AutoRun]”行是必须的固定格式,“Icon”行对应的是图标文件,“C:\C.ico”为图标文件路径和文件名,你在输入时可以将它改为你的图片文件所在路径和文件名。另外,“.ico”为图标文件的扩展名,如果你手头上没有这类文件,可以用看图软件ACDSee将其他格式的软件转换为ico格式,或者找到一个后缀名为BMP的文件,将它直接改名为ICO文件即可。

“Open”行指定要自动运行的文件及其盘符和路径。要特别说明的是,如果你要改变的硬盘跟目录下没有自动播放文件,就应该把“OPEN”行删掉,否则就会因为找不到自动播放文件而打不开硬盘,此时只能用鼠标右键单击盘符在d出菜单中选“打开”才行.

// MyScreen.cpp : implementation file

//

#include "stdafx.h"

#include "DvsClient.h"

#include "MyScreen.h"

#include "DvsClientDlg.h"

#include "Convert.h"

#include "SparrowBuffer.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__

#endif

/////////////带仿////////////////////////////////////橡衫///////////////////蠢如纤/////////

// CMyScreen dialog

CMyScreen::CMyScreen(CWnd* pParent /*=NULL*/)

: CDialog(CMyScreen::IDD, pParent)

{

//{{AFX_DATA_INIT(CMyScreen)

// NOTE: the ClassWizard will add member initialization here

//}}AFX_DATA_INIT

}

void CMyScreen::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX)

//{{AFX_DATA_MAP(CMyScreen)

// NOTE: the ClassWizard will add DDX and DDV calls here

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CMyScreen, CDialog)

//{{AFX_MSG_MAP(CMyScreen)

// NOTE: the ClassWizard will add message map macros here

ON_WM_CREATE()

ON_WM_PAINT()

ON_WM_LBUTTONDOWN()

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CMyScreen message handlers

CMyScreen::CMyScreen(int width, int height, int fr, int index)

{

s_sWidth = s_fWidth = width

s_sHeight = s_fHeight = height

s_Frame_Size = s_fWidth*s_fHeight

s_Frame_Rate = fr

s_Screen_Index = index

if (NULL== (Y = (unsigned char *)malloc(s_Frame_Size) ) )

{

AfxMessageBox("Couldn't allocate memory for RGBbuf\n")

return

}

if (NULL== (U = (unsigned char *)malloc(s_Frame_Size>>2) ) )

{

AfxMessageBox("Couldn't allocate memory for RGBbuf\n")

return

}

if (NULL== (V = (unsigned char *)malloc(s_Frame_Size>>2) ) )

{

AfxMessageBox("Couldn't allocate memory for RGBbuf\n")

return

}

if (NULL== (RGBbuf = (unsigned char *)malloc(s_Frame_Size*3) ) )

{

AfxMessageBox("Couldn't allocate memory for RGBbuf\n")

return

}

// initialize the screen background

memset(Y, 0, s_Frame_Size)

memset(U, 128, s_Frame_Size>>2)

memset(V, 128, s_Frame_Size>>2)

hloc = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE,

sizeof(BITMAPINFOHEADER) + (sizeof(RGBQUAD) * 256))

s_BmpInfo = (LPBITMAPINFO) GlobalLock(hloc)

Create(IDD_MYSCREEN, NULL)

MoveWindow(10, 10, s_sWidth+2, s_sHeight+2, true)

s_Wnd_Thread = NULL

s_Write_Thread = NULL

s_File_Name[0] = '\0'

s_bActive = FALSE

s_bPlay = FALSE

s_bFile_Open = FALSE

s_bLocal = TRUE

s_bConnect = FALSE

s_File_Buffer = NULL

hplay = CreateEvent(NULL, TRUE, TRUE, NULL)

s_Stream_Size = 1

s_File_Buffer = new CSparrowBuffer()

s_File_Buffer->InitBuffer()

}

CMyScreen::~CMyScreen()

{

HeapUnlock(hloc)

HeapFree(GetProcessHeap(), 0, hloc)

free(Y)

free(U)

free(V)

free(RGBbuf)

}

/**

* Details of function OnCreate(LPCREATESTRUCT lpCreateStruct)

*

* Parameter: LPCREATESTRUCT lpCreateStruct

*

* Function : Initialize the information for bitmap.

*

* Return Value: 0 if succeed

*/

int CMyScreen::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

if (CDialog::OnCreate(lpCreateStruct) == -1)

return -1

// TODO: Add your specialized creation code here

int i

HANDLE hloc1

RGBQUAD *argbq

hloc1 = LocalAlloc(LMEM_ZEROINIT | LMEM_MOVEABLE,(sizeof(RGBQUAD) * 256))

argbq = (RGBQUAD *) LocalLock(hloc1)

for(i = 0i <256i ++)

{

argbq[i].rgbBlue = i

argbq[i].rgbGreen = i

argbq[i].rgbRed = i

argbq[i].rgbReserved = 0

}

s_BmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER)

s_BmpInfo->bmiHeader.biPlanes = 1

s_BmpInfo->bmiHeader.biBitCount = 24 // true color

s_BmpInfo->bmiHeader.biCompression = BI_RGB

s_BmpInfo->bmiHeader.biWidth = s_fWidth

s_BmpInfo->bmiHeader.biHeight = s_fHeight

memcpy(s_BmpInfo->bmiColors, argbq, sizeof(RGBQUAD) * 256)

LocalUnlock(hloc1)

LocalFree(hloc1)

return 0

}

/**

* Details of function ShowImage(CDC *pDC, LPBYTE pImage)

*

* Parameter: CDC *pDC, LPBYTE pImage

*

* Function : display a s_fWidth X s_fHeight size bitmap on a

* s_sWidth X s_sHeight size screen.

*

* Return Value: None

*/

void CMyScreen::ShowImage(CDC *pDC, LPBYTE pImage)

{

pDC->SetStretchBltMode(STRETCH_DELETESCANS)

StretchDIBits(pDC->m_hDC, 1 ,1, s_sWidth, s_sHeight,

0, 0, s_fWidth, s_fHeight, pImage, s_BmpInfo, DIB_RGB_COLORS, SRCCOPY)

// draw border

DrawScreenBorder(pDC)

}

void CMyScreen::OnPaint()

{

CPaintDC dc(this)// device context for painting

// TODO: Add your message handler code here

// s_Conv.YV12_to_RGB24(Y, U, V, RGBbuf, s_fWidth, s_fHeight)

ShowImage(&dc, RGBbuf)

// Do not call CDialog::OnPaint() for painting messages

}

/**

* Details of function ReadFrameFromFile(FILE *fp, unsigned char *buf)

*

* Parameter: FILE *fp, unsigned char *buf

*

* Function : Read exactly a frame from a 264 file and transfer the

* information to a buffer.

*

* Return Value: the size of the information for a frame

*/

int CMyScreen::ReadFrameFromFile(FILE *fp, unsigned char *buf)

{

int i, state, size, v, gg=0

// static int ss=0, frame_start_found = 0

unsigned char *ptr = buf

state = s_Decode_State

if(state>13)

state= 7

for(i=0 !feof(fp)i++)

{

fread(ptr++, 1, 1, fp)

gg++

if(state==7)

{

for(!feof(fp)i++)

{

if(!buf[i])

{

state=2

break

}

fread(ptr++, 1, 1, fp)

gg++

}

}

else if(state<=2)

{

if(buf[i]==1)

state^= 5//2->7, 1->4, 0->5

else if(buf[i])

state = 7

else

state>>=1//2->1, 1->0, 0->0

}

else if(state<=5)

{

// int v = buf[i] &0x1F

v = buf[i] &0x1F

if(v==7 || v==8 || v==9)

{

if(s_Frame_Start_Found)

{

i++

found:

s_Decode_State=7

s_Frame_Start_Found = 0

size = i - (state&5)

fseek(fp, size - gg, SEEK_CUR)// no other way :-)

return size

}

}

else if(v==1 || v==2 || v==5)

{

if(s_Frame_Start_Found)

{

state+=8

continue

}else

s_Frame_Start_Found = 1

}

state= 7

}

else

{

if(buf[i] &0x80)

goto found

state= 7

}

}

s_Decode_State = state

return i

}

/**

* Details of function WriteFrameToScreen(st264_decoder *p_dec)

*

* Parameter: st264_decoder *p_dec

*

* Function : Initialize the yuv values on the screen.

*

* Return Value: 1

*/

int CMyScreen::WriteFrameToScreen(st264_decoder *p_dec)

{

memcpy(Y, p_dec->y, s_Frame_Size)

memcpy(U, p_dec->u, s_Frame_Size>>2)

memcpy(V, p_dec->v, s_Frame_Size>>2)

return 1

}

/**

* Details of function PlayVideo(char *in_file_name, int fr)

*

* Parameter: char *in_file_name, int fr

*

* Function : Decode and display the frames one by one.

*

* Return Value: None

*/

void CMyScreen::PlayVideo(char *in_file_name, int fr)

{

int timespan = 1000/fr

s_bPlay = TRUE

// open a 264 file

s_Input_File = fopen(in_file_name, "rb")

if (!s_Input_File)

{

AfxMessageBox("Can't open 264 file!")

return

}

s_bFile_Open = TRUE

/* if(st_create_decoder(&s_Decoder, s_fWidth, s_fHeight) <0)

{

AfxMessageBox("create st264 decoder error")

return

}*/

s_Frame_Start_Found = 0

s_Decode_State = 0

while (s_bFile_Open)

{

WaitForSingleObject(hplay, INFINITE)

DWORD start_t = GetTickCount()

s_Decoder.stream_size = ReadFrameFromFile(s_Input_File, s_Input_Buffer)

/* if( st_decode_one_frame(&s_Decoder, s_Input_Buffer) == 0 )

{

WriteFrameToScreen(&s_Decoder)

// Update the screen

InvalidateRect (NULL,FALSE)

UpdateWindow()

}

*/

if(feof(s_Input_File))

break

int rest_t = timespan - (GetTickCount()-start_t)

if (rest_t >0)

Sleep(rest_t)

}

// st_destroy_decoder(&s_Decoder)

fclose(s_Input_File)

s_bPlay = FALSE

s_bFile_Open = FALSE

}

/**

* Details of function DrawScreenBorder(CDC *pDC)

*

* Parameter: CDC *pDC

*

* Function : Draw screen border, red for active screen while green

* for inactive ones.

*

* Return Value: None

*/

void CMyScreen::DrawScreenBorder(CDC *pDC)

{

CRect rect

GetClientRect(&rect)

CPen pen

if (s_bActive)

pen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0))

else

pen.CreatePen(PS_SOLID, 1, RGB(0, 255, 0))

CPen* pOldPen = pDC->SelectObject(&pen)

pDC->MoveTo(rect.left, rect.top)

pDC->LineTo(rect.right-1, rect.top)

pDC->LineTo(rect.right-1, rect.bottom-1)

pDC->LineTo(rect.left, rect.bottom-1)

pDC->LineTo(rect.left, rect.top)

pDC->SelectObject(pOldPen)

}

/**

* Details of function OnLButtonDown(UINT nFlags, CPoint point)

*

* Parameter: UINT nFlags, CPoint point

*

* Function : Update the control information of the active screen

* on the main control board

*

* Return Value: None

*/

void CMyScreen::OnLButtonDown(UINT nFlags, CPoint point)

{

// TODO: Add your message handler code here and/or call default

CDvsClientDlg *mainwnd =(CDvsClientDlg*) AfxGetMainWnd()

if (mainwnd->v_Cur_Screen != s_Screen_Index)

{

mainwnd->v_pWnd[mainwnd->v_Cur_Screen]->s_bActive = FALSE

mainwnd->v_pWnd[mainwnd->v_Cur_Screen]->InvalidateRect (NULL,FALSE)

mainwnd->v_pWnd[mainwnd->v_Cur_Screen]->UpdateWindow()//Invalidate()

mainwnd->v_Cur_Screen = s_Screen_Index

s_bActive = TRUE

InvalidateRect (NULL,FALSE)

UpdateWindow()//Invalidate()

}

if (s_bPlay)

{

// mainwnd->m_bPlayVideo.SetWindowText("Pause")

}

else

{

// mainwnd->m_bPlayVideo.SetWindowText("Play")

}

CDialog::OnLButtonDown(nFlags, point)

}

/**

* Details of function DestroyWindow()

*

* Parameter: None

*

* Function : set the play flag to false in order to end

* the playvideo thread while destroying a screen

*

* Return Value: None

*/

BOOL CMyScreen::DestroyWindow()

{

// TODO: Add your specialized code here and/or call the base class

if (!s_bPlay)

{

SetEvent(hplay)

s_bPlay = FALSE

}

s_bFile_Open = FALSE

//Sleep(200)

return CDialog::DestroyWindow()

}

int CMyScreen::ReadFrameFromBuffer(CSparrowBuffer *bp, unsigned char *buf)

{

int i, state, size, v, gg=0

// static int ss=0, frame_start_found = 0

unsigned char *ptr = buf

state = s_Decode_State

if(state>13)

state= 7

for (i = 0i ++)

// for(i=0 !feof(fp)i++)

{

bp->ReadFromBuffer(ptr++, 1)

// fread(ptr++, 1, 1, fp)

gg++

if(state==7)

{

for (i ++)

// for(!feof(fp)i++)

{

if(!buf[i])

{

state=2

break

}

bp->ReadFromBuffer(ptr++, 1)

// fread(ptr++, 1, 1, fp)

gg++

}

}

else if(state<=2)

{

if(buf[i]==1)

state^= 5//2->7, 1->4, 0->5

else if(buf[i])

state = 7

else

state>>=1//2->1, 1->0, 0->0

}

else if(state<=5)

{

// int v = buf[i] &0x1F

v = buf[i] &0x1F

if(v==7 || v==8 || v==9)

{

if(s_Frame_Start_Found)

{

i++

found:

s_Decode_State=7

s_Frame_Start_Found = 0

size = i - (state&5)

bp->BufferSeek(size-gg)

// fseek(fp, size - gg, SEEK_CUR)// no other way :-)

return size

}

}

else if(v==1 || v==2 || v==5)

{

if(s_Frame_Start_Found)

{

state+=8

continue

}else

s_Frame_Start_Found = 1

}

state= 7

}

else

{

if(buf[i] &0x80)

goto found

state= 7

}

}

s_Decode_State = state

return i

}

void CMyScreen::PlayNetStream(int fr)

{

int timespan = 1000/fr

// open a 264 file

/* s_Input_File = fopen(s_File_Name, "rb")

if (!s_Input_File)

{

AfxMessageBox("Can't open 264 file!")

return

}

*/ s_bFile_Open = TRUE

/* if(st_create_decoder(&s_Decoder, s_fWidth, s_fHeight) <0)

{

AfxMessageBox("create st264 decoder error")

return

}

*/

s_Frame_Start_Found = 0

s_Decode_State = 0

while (s_bFile_Open)

{

WaitForSingleObject(hplay, INFINITE)

DWORD start_t = GetTickCount()

s_Decoder.stream_size = ReadFrameFromBuffer(s_File_Buffer, s_Input_Buffer)

/* if( st_decode_one_frame(&s_Decoder, s_Input_Buffer) == 0 )

{

WriteFrameToScreen(&s_Decoder)

// Update the screen

InvalidateRect (NULL,FALSE)

UpdateWindow()

}

*/

//if(feof(s_Input_File))

//break

int rest_t = timespan - (GetTickCount()-start_t)

if (rest_t >0)

Sleep(rest_t)

}

// st_destroy_decoder(&s_Decoder)

// fclose(s_Input_File)

s_bPlay = FALSE

s_bFile_Open = FALSE

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8260530.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存