#2
by YuO » 6年前
普通,Application.Runはデフォルトで作られるProgram.csの中に置いたまま使います。
今回のように,Form派生クラスの,それもインスタンスメソッドに書くことはまず行いません。
で,Application.Runは実質的にはメッセージループを回します。
コード:
MSG msg;
BOOL result;
while ((result = GetMessage(&msg, NULL, 0, 0)) != FALSE && result != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
に相当する物です。
実際には,メッセージフィルターなどがあるため,もっとややこしくなりますが。
ref)
Application.Run,
Application+ThreadContext.RunMessageLoopInner,
Application+ThreadContext.LocalModalMessageLoop from
Reference Source
Application.RunやControl.Showでフォームを表示させたときのイベント発生順は,
Order of Events in Windows Forms (古いドキュメント:
Windows フォームのイベントの順序) にあります。
普通,Application.Runはデフォルトで作られるProgram.csの中に置いたまま使います。
今回のように,Form派生クラスの,それもインスタンスメソッドに書くことはまず行いません。
で,Application.Runは実質的にはメッセージループを回します。[code=C]MSG msg;
BOOL result;
while ((result = GetMessage(&msg, NULL, 0, 0)) != FALSE && result != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}[/code]に相当する物です。
実際には,メッセージフィルターなどがあるため,もっとややこしくなりますが。
ref) [url=https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Application.cs,aa4c1e44b81dc7f3]Application.Run[/url], [url=https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Application.cs,d7cd7464da6bb836]Application+ThreadContext.RunMessageLoopInner[/url], [url=https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Application.cs,737fa4e71a0b8efe]Application+ThreadContext.LocalModalMessageLoop[/url] from [url=https://referencesource.microsoft.com]Reference Source[/url]
Application.RunやControl.Showでフォームを表示させたときのイベント発生順は,[url=https://docs.microsoft.com/en-us/dotnet/framework/winforms/order-of-events-in-windows-forms]Order of Events in Windows Forms[/url] (古いドキュメント:[url=https://msdn.microsoft.com/ja-jp/library/86faxx0d.aspx]Windows フォームのイベントの順序[/url]) にあります。