A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
1.8 KiB

// -----------------------------------------------------------------------
// <copyright file="WindowsPlatform.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Windows
{
using System;
using System.Collections.Generic;
using Perspex.Platform;
using Perspex.Threading;
using Perspex.Windows.Interop;
using Perspex.Windows.Threading;
using Splat;
public class WindowsPlatform : IPlatformThreadingInterface
{
private static WindowsPlatform instance = new WindowsPlatform();
private Dictionary<IntPtr, UnmanagedMethods.TimerProc> timerCallbacks =
new Dictionary<IntPtr, UnmanagedMethods.TimerProc>();
public static void Initialize()
{
var locator = Locator.CurrentMutable;
locator.Register(() => instance, typeof(IPlatformThreadingInterface));
}
public Dispatcher GetThreadDispatcher()
{
return WindowsDispatcher.GetThreadDispatcher();
}
public void KillTimer(object handle)
{
this.timerCallbacks.Remove((IntPtr)handle);
UnmanagedMethods.KillTimer(IntPtr.Zero, (IntPtr)handle);
}
public object StartTimer(TimeSpan interval, Action callback)
{
UnmanagedMethods.TimerProc timerDelegate = (UnmanagedMethods.TimerProc)
((hWnd, uMsg, nIDEvent, dwTime) => callback());
IntPtr handle = UnmanagedMethods.SetTimer(
IntPtr.Zero,
IntPtr.Zero,
(uint)interval.TotalMilliseconds,
timerDelegate);
this.timerCallbacks.Add(handle, timerDelegate);
return handle;
}
}
}