Many video files cannot be played normally.
Bool caviplayerdlg: oninitdialog ()
{
Cdialog: oninitdialog ();
// Add "about..." menu item to system menu.
// Idm_aboutbox must be in the system command range.
Assert (idm_aboutbox & 0xfff0) = idm_aboutbox );
Assert (idm_aboutbox <0xf000 );
Cmenu * psysmenu = getsystemmenu (false );
If (psysmenu! = NULL)
{
Cstring straboutmenu;
Straboutmenu. loadstring (ids_aboutbox );
If (! Straboutmenu. isempty ())
{
Psysmenu-> appendmenu (mf_separator );
Psysmenu-> appendmenu (mf_string, idm_aboutbox, straboutmenu );
}
}
// Set the icon for this dialog. The framework does this automatically
// When the application's main window is not a dialog
Seticon (m_hicon, true );
// Set big icon
Seticon (m_hicon, false );
// Set small icon
// Todo: add extra initialization here
M_haviwnd = mciwndcreate (m_stccarry.getsafehwnd (),
AfxGetInstanceHandle (),
Ws_child | ws_visible | mciwndf_nomenu, m_stravifile );
Return true; // return true unless you set the focus to a control
}
Void caviplayerdlg: onsyscommand (uint NID, lparam)
{
If (NID & 0xfff0) = idm_aboutbox)
{
Caboutdlg dlgabout;
Dlgabout. domodal ();
}
Else
{
Cdialog: onsyscommand (NID, lparam );
}
}
// If you add a Minimize button to your dialog, you will need the code below
// To draw the icon. For MFC applications using the document/view model,
// This is automatically done for you by the framework.
Void caviplayerdlg: onpaint ()
{
If (isiconic ())
{
Cpaintdc DC (this); // device context for painting
Sendmessage (wm_iconerasebkgnd, (wparam) DC. getsafehdc (), 0 );
// Center icon in client rectangle
Int cxicon = getsystemmetrics (sm_cxicon );
Int cyicon = getsystemmetrics (sm_cyicon );
Crect rect;
Getclientrect (& rect );
Int x = (rect. Width ()-cxicon + 1)/2;
Int y = (rect. Height ()-cyicon + 1)/2;
// Draw the icon
DC. drawicon (X, Y, m_hicon );
}
Else
{
Cdialog: onpaint ();
}
}
// The system callthis to obtain the cursor to display while the user drags
// The minimized window.
Hcursor caviplayerdlg: onquerydragicon ()
{
Return (hcursor) m_hicon;
}
Void caviplayerdlg: onbuttonplay ()
{
// Todo: add your control notification handler code here
Updatedata (true );
If (m_stravifile.isempty ())
{
Afxmessagebox ("select the AVI file to be played ");
Return;
}
Mciwndstop (m_haviwnd );
Mciwndopen (m_haviwnd, (lpctstr) m_stravifile, 0 );
Mciwndplay (m_haviwnd );
}
Void caviplayerdlg: onbuttonfind ()
{
// Todo: add your control notification handler code here
Cfiledialog DLG (true, null, null,
Ofn_hidereadonly | ofn_overwriteprompt,
"AVI file (*. AVI) | *. Avi | ");
If (DLG. domodal () = idok)
{
M_stravifile = DLG. getpathname ();
Updatedata (false );
}
}
Void caviplayerdlg: onclose ()
{
// Todo: add your message handler code here and/or call default
Mciwndstop (m_haviwnd );
Mciwnddestroy (m_haviwnd );
Cdialog: onclose ();
}