タスクトレイから呼ぶフォーム用に、
「ひょこっ」とした感じでウィンドウを表示したかった。
結果
スライドアニメーション(AW_SLIDE
)はイマイチ。
・カクカク感がある
・タイトルバーが先に表示されてしまう(↓方向だけは視覚的にセーフ?)
フェードアニメーション(AW_BLEND
)は、まぁよさげ。
・ただし、時間設定を長め(1000msとか)にすると複数回フェードするような挙動をした。謎。
サンプルコード(簡素版)
usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;publicclassAnimateWindowTest:Form{Buttonbtn;classNativeMethods{[Flags]publicenumAnimateWindowFlags{AW_NONE=0,AW_HOR_POSITIVE=0x00000001,AW_HOR_NEGATIVE=0x00000002,AW_VER_POSITIVE=0x00000004,AW_VER_NEGATIVE=0x00000008,AW_CENTER=0x00000010,AW_HIDE=0x00010000,AW_ACTIVATE=0x00020000,AW_SLIDE=0x00040000,AW_BLEND=0x00080000}[DllImport("user32.dll")]publicstaticexternboolAnimateWindow(IntPtrhWnd,UInt32dwTimeMSec,AnimateWindowFlagsdwFlags);}AnimateWindowTest(){btn=newButton();btn.Text="New Window";btn.Click+=Btn_Click;Controls.Add(btn);ClientSize=newSize(200,100);}voidBtn_Click(objectsender,EventArgse){Formf=newForm();f.Controls.Add(newButton(){Text="button",Dock=DockStyle.Bottom});NativeMethods.AnimateWindow(f.Handle,500,// delay tiem in [ms]NativeMethods.AnimateWindowFlags.AW_ACTIVATE|NativeMethods.AnimateWindowFlags.AW_SLIDE|NativeMethods.AnimateWindowFlags.AW_VER_NEGATIVE);f.Show();}[STAThread]staticvoidMain(string[]args){Application.Run(newAnimateWindowTest());}}
サンプルコード(子Formに処理を持たせる版)
usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;publicclassAnimateWindowTest:Form{Buttonbtn;AnimateWindowTest(){btn=newButton();btn.Text="New Window";btn.Click+=Btn_Click;Controls.Add(btn);ClientSize=newSize(200,100);}voidBtn_Click(objectsender,EventArgse){Formf=newAnimForm();f.Show();}[STAThread]staticvoidMain(string[]args){Application.Run(newAnimateWindowTest());}}publicclassAnimForm:Form{classNativeMethods{[Flags]publicenumAnimateWindowFlags{AW_NONE=0,AW_HOR_POSITIVE=0x00000001,AW_HOR_NEGATIVE=0x00000002,AW_VER_POSITIVE=0x00000004,AW_VER_NEGATIVE=0x00000008,AW_CENTER=0x00000010,AW_HIDE=0x00010000,AW_ACTIVATE=0x00020000,AW_SLIDE=0x00040000,AW_BLEND=0x00080000}[DllImport("user32.dll")]publicstaticexternboolAnimateWindow(IntPtrhWnd,UInt32dwTimeMSec,AnimateWindowFlagsdwFlags);publicconstintWM_SHOWWINDOW=0x0018;}publicAnimForm(){Controls.Add(newButton(){Text="button",Dock=DockStyle.Bottom});}protectedoverridevoidWndProc(refMessagem){if(m.Msg==NativeMethods.WM_SHOWWINDOW){//base.WndProc(ref m);if(m.LParam==IntPtr.Zero&&m.WParam!=IntPtr.Zero){// lParam == 0 : message by ShowWindow// mParam == 1 : being shown// mParam == 0 : being hiddenNativeMethods.AnimateWindow(this.Handle,100,// delay tiem in [ms]NativeMethods.AnimateWindowFlags.AW_ACTIVATE|NativeMethods.AnimateWindowFlags.AW_BLEND//AW_SLIDE// | NativeMethods.AnimateWindowFlags.AW_VER_NEGATIVE);}else{base.WndProc(refm);}}else{base.WndProc(refm);}}}