WPF メッセージループ

using System.Windows.Interop;
using System.Runtime.InteropServices;

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
try
{
// handle WM_HOTKEY message and hotkeys
/*if ((lHKids != null) && (lHKids.Count > 0) && (m.Msg == Win32.WM_HOTKEY))
{
// WParam for WM_HOTKEY message holds id passed to
// RegisterHotKey() function
int idx = lHKids.IndexOf((int)m.WParam);
if (idx >= 0 && (idx != 2)) // without ctrl-v hotkey
{
Win32.SetForegroundWindow(this_window_handle);
MessageBox.Show(string.Format(“HotKey {0} pressed”, idx), “info”);
}
}*/
// respond to WM_MOUSEWHEEL message
if (msg == Win32.WM_MOUSEWHEEL)
{
// use the correct control handle
// in this case textbox instead of main form window
//Win32.SendMessage(exTextBox1.Handle, Win32.WM_PASTE, 0, 0);
Console.WriteLine(“aa”);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “WndProc() exception”);
}

return IntPtr.Zero;
}

WPF メッセージループ」への2件のフィードバック

コメントを残す

メールアドレスが公開されることはありません。