Win32PlatformManager.cs :  » Game » RealmForge » Axiom » Platforms » Win32 » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » Axiom » Platforms » Win32 » Win32PlatformManager.cs
using System;
using System.Runtime.InteropServices;
using Axiom.Core;
using Axiom.Input;

namespace Axiom.Platforms.Win32{
  /// <summary>
  ///    Platform management specialization for Microsoft Windows (r) platform.
  /// </summary>
  public class Win32PlatformManager : IPlatformManager {
    #region Fields

    /// <summary>
    ///    Reference to the current input reader.
    /// </summary>
    private InputReader inputReader;
    /// <summary>
    ///    Reference to the current active timer.
    /// </summary>
        private ITimer timer;

    #endregion Fields

    #region IPlatformManager Members

    /// <summary>
    ///    Creates an InputReader implemented using Microsoft DirectInput (tm).
    /// </summary>
    /// <returns></returns>
    public Axiom.Input.InputReader CreateInputReader() {
      inputReader = new Win32InputReader();
      return inputReader;
    }

    /// <summary>
    ///    Creates a high precision Windows timer.
    /// </summary>
    /// <returns></returns>
    public ITimer CreateTimer() {
            timer = new Win32Timer();
      return timer;
    }

    /// <summary>
    ///    Implements the Microsoft Windows (r) message pump for allowing the OS to process
    ///    pending events.
    /// </summary>
    public void DoEvents() {
      Msg msg;

      // pump those events!
      while(!(PeekMessage(out msg, IntPtr.Zero, 0, 0, PM_REMOVE) == 0)) {
        TranslateMessage(ref msg);
        DispatchMessage(ref msg);
      }
    }

        /// <summary>
        ///     Called when the engine is being shutdown.
        /// </summary>
        public void Dispose() {
            if (inputReader != null) {
                inputReader.Dispose();
            }
        }

    #endregion

    #region P/Invoke Declarations

    struct Msg {
      public int hWnd;
      public int Message;
      public int wParam;
      public int lParam;
      public int time;
      public POINTAPI pt;
    }

    struct POINTAPI {
      public int x;
      public int y;

      // Just to get rid of Warning CS0649.
      public POINTAPI(int x, int y) {
        this.x = x;
        this.y = y;
      }
    }

    /// <summary>
    ///    PeekMessage option to remove the message from the queue after processing.
    /// </summary>
    const int PM_REMOVE = 0x0001;
    const string USER_DLL = "user32.dll";

    /// <summary>
    ///    The PeekMessage function dispatches incoming sent messages, checks the thread message 
    ///    queue for a posted message, and retrieves the message (if any exist).
    /// </summary>
    /// <param name="msg">A <see cref="Msg"/> structure that receives message information.</param>
    /// <param name="handle"></param>
    /// <param name="msgFilterMin"></param>
    /// <param name="msgFilterMax"></param>
    /// <param name="removeMsg"></param>
    [DllImport(USER_DLL)]
    private static extern int PeekMessage(out Msg msg, IntPtr handle, int msgFilterMin, int msgFilterMax, int removeMsg);

    /// <summary>
    ///    The TranslateMessage function translates virtual-key messages into character messages.
    /// </summary>
    /// <param name="msg">
    ///    an MSG structure that contains message information retrieved from the calling thread's message queue 
    ///    by using the GetMessage or <see cref="PeekMessage"/> function.
    /// </param>
    [DllImport(USER_DLL)]
    private static extern void TranslateMessage(ref Msg msg);

    /// <summary>
    ///    The DispatchMessage function dispatches a message to a window procedure.
    /// </summary>
    /// <param name="msg">A <see cref="Msg"/> structure containing the message.</param>
    [DllImport(USER_DLL)]
    private static extern void DispatchMessage(ref Msg msg);

    #endregion P/Invoke Declarations
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.