Top / JUNK / NativeWindowBase

C#

using System;
using System.Windows.Forms;

public class NativeWindowBase<T> : NativeWindow where T : Control
{
    public NativeWindowBase(T owner) {
        Owner = owner;
        if (owner.IsHandleCreated) {
            AssignHandle(owner.Handle);
        }
        owner.HandleCreated += Owner_HandleCreated;
    }

    public T Owner { get; }

    private void Owner_HandleCreated(object sender, EventArgs e) {
        AssignHandle(((T)sender).Handle);
    }

    protected override void WndProc(ref Message m) {
        const int WM_NCDESTROY = 0x0082;
        switch (m.Msg) {
            case WM_NCDESTROY:
                base.WndProc(ref m);
                ReleaseHandle();
                break;

            default:
                base.WndProc(ref m);
                break;
        }
    }
}

VB

Imports System
Imports System.Windows.Forms

Public Class NativeWindowBase(Of T As Control)
    Inherits NativeWindow

    Public ReadOnly Property Owner As T

    Public Sub New(ByVal owner As T)
        Me.Owner = owner
        If (owner.IsHandleCreated) Then
            MyBase.AssignHandle(owner.Handle)
        End If
        AddHandler owner.HandleCreated, AddressOf Me.Owner_HandleCreated
    End Sub

    Private Sub Owner_HandleCreated(ByVal sender As Object, ByVal e As EventArgs)
        MyBase.AssignHandle(DirectCast(sender, T).Handle)
    End Sub

    Protected Overrides Sub WndProc(ByRef m As Message)
        Const WM_NCDESTROY As Integer = &H82
        If (m.Msg = WM_NCDESTROY) Then
            MyBase.WndProc(m)
            Me.ReleaseHandle()
        Else
            MyBase.WndProc(m)
        End If
    End Sub
End Class



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2019-11-18 (月) 11:11:26 (27d)