Почему переменные поля не изменяются?C#

Место общения программистов C#
Anonymous
Почему переменные поля не изменяются?

Сообщение Anonymous »

Я отлаживал во многих отношениях, но LastfocusedWindow всегда был 0. public partial class MainWindow : Window
{
private static volatile IntPtr lastFocusedWindow = IntPtr.Zero;

public MainWindow()
{
InitializeComponent();
AllocConsole();
this.Topmost = true;

Automation.AddAutomationFocusChangedEventHandler(OnFocusChangedHandler);
}

private void OnFocusChangedHandler(Object src, AutomationFocusChangedEventArgs args)
{
AutomationElement element = src as AutomationElement;

if (element == null)
{
return;
}

IntPtr hwnd = new IntPtr(element.Current.NativeWindowHandle);

if (hwnd == IntPtr.Zero || hwnd == (new WindowInteropHelper(this)).Handle)
{
Console.WriteLine("no changes");
return;
}

lastFocusedWindow = hwnd;
Console.WriteLine("change to: {0}", hwnd);
}

private void SendKey(byte vk)
{
Console.WriteLine("last: {0}", lastFocusedWindow);

if (lastFocusedWindow != IntPtr.Zero)
{
SetForegroundWindow(lastFocusedWindow);
mutex.WaitOne();
keybd_event(vk, 0, KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero);
keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero);
mutex.ReleaseMutex();
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/797 ... not-change

Вернуться в «C#»