📄 mainform.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "MAINFORM.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(OpenDialog1->Execute())
{
// loading AVI files can be slow. repaint form now (so it doesn't
// look dead), then set the cursor to the hourglass until
Update();
Screen->Cursor = crHourGlass;
MediaPlayer1->FileName=OpenDialog1->FileName; // set filename and
try // try to open file
{
MediaPlayer1->Open();
}
catch (...)
{
Application->MessageBox("Error opening file",mtWarning,MB_ICONWARNING|MB_OK);
}
Screen->Cursor = crArrow; // reset cursor
// use DisplayRect to autosize the MediaPlayer
MediaPlayer1->DisplayRect = Rect(4,4,0,0);
// re-adjust the controls, use temp varables during calculations. note
// that DisplayRect.Right = AVI width and DisplayRect.Bottom = Height
int TempPanelWidth = MediaPlayer1->DisplayRect.Right + 8; // four pixels
int TempPanelHeight = MediaPlayer1->DisplayRect.Bottom + 8; // oneach side
int TempPanelLeft;
int TempPanelTop;
int TempFormWidth;
int TempFormHeight;
int TempMediaPlayerLeft;
// determine form's width based on the widest cntrol on the form.
if(TempPanelWidth < MediaPlayer1->Width) // if MediaPlayer1 is widest
{ // make the form 4 pixels wider
TempFormWidth = MediaPlayer1->Width + 4; // than MediaPlayer1
TempMediaPlayerLeft = 2; // place MP 2 pixels in and
TempPanelLeft = TempMediaPlayerLeft + // center the panel
(MediaPlayer1->Width - TempPanelWidth)/2;
}
else // else, panel is wider
{ // make form 4 pixels
TempFormWidth = TempPanelWidth + 4; // wider than panel
TempPanelLeft = 2;
TempMediaPlayerLeft = (TempFormWidth - // center MediaPlayer
MediaPlayer1->Width)/2;
}
TempPanelTop = MediaPlayer1->Top + MediaPlayer1->Height + 15;
TempFormHeight = TempPanelTop + TempPanelHeight +2;
ClientWidth = TempFormWidth; // copy temps into their
ClientHeight = TempFormHeight; // corresponding properties
Panel1->Left = TempPanelLeft; // every control should be
Panel1->Width = TempPanelWidth; // centered when finished,
Panel1->Top = TempPanelTop; // video should fit nicely
Panel1->Height = TempPanelHeight; // on form and panel.
MediaPlayer1->Left = TempMediaPlayerLeft;
Panel1->Visible = true; // display the panel
Button1->Left = (ClientWidth-Button1->Width) / 2;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -