using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; namespace MPC_PP { public partial class Form1:Form { public Form1() { InitializeComponent(); } /* ------------------------------ ini ------------------------------ */ public class IniFile { [DllImport("kernel32.dll")] private static extern int GetPrivateProfileString( string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedstring, int nSize, string lpFileName); [DllImport("kernel32.dll")] private static extern int WritePrivateProfileString( string lpApplicationName,string lpKeyName, string lpstring, string lpFileName); string filePath; public IniFile(string filePath) {this.filePath = filePath;} public string this[string section,string key] { set {WritePrivateProfileString(section, key, value, filePath);} get {StringBuilder sb = new StringBuilder(256); GetPrivateProfileString(section, key, string.Empty, sb, sb.Capacity, filePath); return sb.ToString(); } } public string GetValue(string section, string key, string defaultvalue) { StringBuilder sb = new StringBuilder(256); GetPrivateProfileString(section, key, defaultvalue, sb, sb.Capacity, filePath); return sb.ToString(); } } /* ------------------------------ ini ------------------------------ */ int F2C=0; public int TMLength=300; public int TMSeed=8; public Form2 F2; IniFile ini = new IniFile("./MPC_PP.ini"); //ツールボックス右クリック→アイテムの選択→COMコンポーネント→WinMediaPlayer private void Form1_Load(object sender, EventArgs e) { F2=new Form2(); F2.ShowInTaskbar=false; F2.F1=this; F2.Show(); //タスクバー非表示OP F2C=1; F2.Activate(); this.Activate(); if(ini["List", "Window_X"]!=""){ this.Left = int.Parse(ini["List", "Window_X"]); this.Top = int.Parse(ini["List", "Window_Y"]); this.Width= int.Parse(ini["List", "Size_X"]); this.Height= int.Parse(ini["List", "Size_Y"]); if(ini["List", "Check1"]=="1"){ F2.checkBox1.Checked=true; } if(ini["List","TimeLength"]!=""){ TMLength=int.Parse(ini["List","TimeLength"]); } } this.Text="MPC-PP"; this.axWindowsMediaPlayer1.uiMode="none"; this.axWindowsMediaPlayer1.stretchToFit=true; this.axWindowsMediaPlayer1.windowlessVideo=true; this.axWindowsMediaPlayer1.enableContextMenu=false; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if(this.Left>-1){ ini["List", "Window_X"]= this.Left+""; ini["List", "Window_Y"] = this.Top+""; ini["List", "Size_X"] = this.Width+""; ini["List", "Size_Y"]= this.Height+""; if(F2.checkBox1.Checked){ini["List","check1"]="1";} else{ini["List","check1"]="0";} ini["List","TimeLength"]=TMLength+""; } } private void Form1_DragEnter(object sender, DragEventArgs e){ e.Effect=DragDropEffects.All; } private void Form1_DragDrop(object sender, DragEventArgs e) { foreach (string item in (string[])e.Data.GetData(DataFormats.FileDrop)){ this.axWindowsMediaPlayer1.URL=item; } FirstContact=true; TRMax=0; EDPoint=0; //初期設定 timer1.Enabled=true; Start(); } public bool PLMode=false; //[再生中/停止中] 切替タイミング:動画クリック/↓キー切替 private void axWindowsMediaPlayer1_MouseDownEvent(object sender, AxWMPLib._WMPOCXEvents_MouseDownEvent e) { Start(); } //動画クリック private void Start(){ if(PLMode){ F2.Stop(); } else{ F2.Start(); } PLMode=!PLMode;//[再生中=停止/停止中=再生] } double STPoint=0; double EDPoint=0; private void axWindowsMediaPlayer1_KeyUpEvent(object sender, AxWMPLib._WMPOCXEvents_KeyUpEvent e) { KeyUP((int)e.nKeyCode); } //キーイベント public void KeyUP(int e){ if(e == 37){ axWindowsMediaPlayer1.settings.rate=0.01; F2.Start(); this.axWindowsMediaPlayer1.Ctlcontrols.currentPosition-=0.20; F2.Stop(); axWindowsMediaPlayer1.settings.rate=1.0;} //← if(e == 38){ this.Close(); } //↑ if(e == 39){ axWindowsMediaPlayer1.settings.rate=0.01; F2.Start(); this.axWindowsMediaPlayer1.Ctlcontrols.currentPosition+=0.08; F2.Stop(); axWindowsMediaPlayer1.settings.rate=1.0;} //→ if(e == 40){ Start(); } //↓ if(e == 122){ axWindowsMediaPlayer1.fullScreen= !axWindowsMediaPlayer1.fullScreen; } //F11 if(e == 13){ Start(); } //Enter [再生/停止] if(e == 32){ Start(); } //Space [再生/停止] if(e == 96){ F2=new Form2(); F2.ShowInTaskbar=false; F2.F1=this; F2.Show(); } //0 if(e == 97){ F2.ReStart(); PLMode=true; } //1 [早戻し] if(e == 98){ Start(); } //2 [再生/停止] if(e == 99){ F2.FullStart(); PLMode=true; } //3 [早送り] if(e == 100){} //4 if(e == 101){ Start(); } //5 [再生/停止] if(e == 102){ F2.Start(); this.axWindowsMediaPlayer1.Ctlcontrols.currentPosition+=0.01; F2.Stop(); } //6 if(e == 107){ axWindowsMediaPlayer1.settings.rate+=0.1; } //+ if(e == 109){ axWindowsMediaPlayer1.settings.rate-=0.1; } //- if(e == 106){ axWindowsMediaPlayer1.settings.rate =1.0; } //* if(e == 83) { STPoint=axWindowsMediaPlayer1.Ctlcontrols.currentPosition; } //S if(e == 69){ EDPoint=axWindowsMediaPlayer1.Ctlcontrols.currentPosition; } //E } #region 解像度固定 const double fixedRate = (double)16/9; const int WM_SIZING = 0x214; const int WMSZ_LEFT = 1; const int WMSZ_RIGHT =2; const int WMSZ_TOP = 3; const int WMSZ_TOPLEFT =4; const int WMSZ_TOPRIGHT =5; const int WMSZ_BOTTOM =6; const int WMSZ_BOTTOMLEFT =7; const int WMSZ_BOTTOMRIGHT = 8; [StructLayout(LayoutKind.Sequential)] struct RECT { public int left; public int top; public int right; public int bottom; } protected override void WndProc(ref Message m) { switch(m.Msg){ case WM_SIZING: RECT r = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT)); int w = r.right - r.left - (Size.Width - ClientSize.Width); int h = r.bottom - r.top - (Size.Height - ClientSize.Height); int dw = (int)(h * fixedRate + 0.5) - w; int dh = (int)(w / fixedRate + 0.5) - h; switch(m.WParam.ToInt32()) { case WMSZ_TOP: case WMSZ_BOTTOM: r.right += dw; break; case WMSZ_LEFT: case WMSZ_RIGHT: r.bottom += dh; break; case WMSZ_TOPLEFT: if(dw > 0) r.left -= dw; else r.top -= dh; break; case WMSZ_TOPRIGHT: if(dw > 0) r.right += dw; else r.top -= dh; break; case WMSZ_BOTTOMLEFT: if(dw > 0) r.left -= dw; else r.bottom += dh; break; case WMSZ_BOTTOMRIGHT: if(dw > 0) r.right += dw; else r.bottom += dh; break; } Marshal.StructureToPtr(r, m.LParam, false); goto default; default: base.WndProc(ref m); break; } } #endregion private void Form1_Move(object sender, EventArgs e) { FormChange(); } private void Form1_Resize(object sender, EventArgs e) { FormChange(); } private void axWindowsMediaPlayer1_MouseMoveEvent(object sender, AxWMPLib._WMPOCXEvents_MouseMoveEvent e) { if(e.fY>this.Height-100){ F2.Opacity=1; } else{ F2.Opacity=0.8; } } public void FormChange(){ if(F2C==1){ F2.WIMove(); } } public int TRMax=0; bool FirstContact=true; private void timer1_Tick(object sender, EventArgs e) { double Time = axWindowsMediaPlayer1.Ctlcontrols.currentPosition; TRMax= (int)(axWindowsMediaPlayer1.currentMedia.duration); if(FirstContact){ if(TRMax>0){ LengthCheck(); //トラックバー最大値切替 EDPoint=TRMax; FirstContact=false; } } if(!F2.checkBox1.Checked){ F2.trackBar1.Value=(int)((int)Time*TMSeed); } else { F2.trackBar1.Value=(int)((int)Time*TMSeed)-TMLength*TMSeed*((int)(Time/TMLength)); } //300制限 if(F2.checkBox2.Checked){ //A-Bループ if(STPoint0){ TMCount2=0; timer2.Enabled=false; } } //動画抑制 private void Form1_Click(object sender, EventArgs e) { F2.Activate(); this.Activate(); } private void axWindowsMediaPlayer1_ClickEvent(object sender, AxWMPLib._WMPOCXEvents_ClickEvent e) { F2.Activate(); this.Activate(); } public void LengthCheck(){ if(F2.checkBox1.Checked){ if(TRMax>=300){ F2.trackBar1.Maximum=TMLength*TMSeed; } else { F2.trackBar1.Maximum=TRMax *TMSeed; F2.checkBox1.Checked=false; } } else{ F2.trackBar1.Maximum=TRMax*TMSeed; } } } }