NativeWindow.cs :  » 2.6.4-mono-.net-core » System.Windows.Forms » System » Windows » Forms » 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 » 2.6.4 mono .net core » System.Windows.Forms 
System.Windows.Forms » System » Windows » Forms » NativeWindow.cs
//
// System.Windows.Forms.NativeWindow.cs
//
// Author:
//   stubbed out by Paul Osman (paul.osman@sympatico.ca)
//   Dennis Hayes (dennish@Raytek.com)
//   WINELib implementation started by John Sohn (jsohn@columbus.rr.com)
//
// (C) 2002 Ximian, Inc
//

using System.Runtime.Remoting;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Collections;

namespace System.Windows.Forms{

  // <summary>
  // Implementation started.
  //
  // </summary>

  public class NativeWindow : MarshalByRefObject {

    // the window's HWND
    private IntPtr windowHandle;
    static private Hashtable windowCollection = new Hashtable ();
    static bool registeredClass = false;

    //
    //  --- Constructor
    //
    public NativeWindow () 
    {
      windowHandle = (IntPtr) 0;
    }

    //
    //  --- Public Properties
    //
    public IntPtr Handle 
    {
      get {
        return windowHandle;
      }
    }

    //
    //  --- Public Methods
    //
    public void AssignHandle (IntPtr handle) 
    {
      if (windowHandle != (IntPtr) 0)
        windowCollection.Remove (windowHandle);

      windowHandle = handle;
      windowCollection.Add (windowHandle, this);
      OnHandleChange ();
    }

    public virtual void CreateHandle (CreateParams cp) 
    {
      IntPtr createdHWnd = (IntPtr) 0;
      Object lpParam = new Object();

      if (!registeredClass) {
        Win32.WndProc wp = new Win32.WndProc (WndProc);
        if (Win32.MonoRegisterClass(
           (int) (Win32.CS_OWNDC | 
           Win32.CS_VREDRAW | 
           Win32.CS_HREDRAW), 
           wp, 0, 0, (IntPtr) 0, (IntPtr) 0,
          (IntPtr) 0, (IntPtr) 6, "", 
          "mono_native_window") != 0) {
          registeredClass = true;
        } else {
          windowHandle = (IntPtr) 0;
          return;
        }
      }

      windowHandle = Win32.CreateWindowExA (
        (uint) cp.ExStyle, cp.ClassName,
        cp.Caption,(uint) cp.Style,
        cp.X, cp.Y, cp.Width, cp.Height,
        (IntPtr) cp.Parent, (IntPtr) 0,
        (IntPtr) 0, ref lpParam);
      
      if (windowHandle != (IntPtr) 0)
        windowCollection.Add (windowHandle, this);
    }

    [MonoTODO]
    public override ObjRef CreateObjRef (Type requestedType) 
    {
      throw new NotImplementedException ();
    }

    public void DefWndProc (ref Message m) 
    {
      m.Result = Win32.DefWindowProcA (m.HWnd, m.Msg, 
               m.WParam, m.LParam);
    }

    public virtual void DestroyHandle () 
    {
      windowCollection.Remove (windowHandle);
      Win32.DestroyWindow (windowHandle);
    }

    [MonoTODO]
    public override bool Equals (object o) 
    {
      throw new NotImplementedException ();
    }

    //inherited
    //public static bool Equals(object o1, object o2)
    //{
    //  throw new NotImplementedException ();
    //}
    [MonoTODO]
    public override int GetHashCode () 
    {
      //FIXME add our proprities
      return base.GetHashCode ();
    }

    public static NativeWindow FromHandle (IntPtr handle) 
    {
      NativeWindow window = new NativeWindow ();
      window.AssignHandle (handle);
      return window;
    }

    //inherited
    //public object GetLifetimeService() {
    //  throw new NotImplementedException ();
    //}

    //public Type GetType() {
    //  throw new NotImplementedException ();
    //}

    //public virtual object InitializeLifetimeService(){
    //  throw new NotImplementedException ();
    //}

    public virtual void ReleaseHandle () 
    {
      windowHandle = (IntPtr) 0;
      OnHandleChange ();
    }

    [MonoTODO]
    public override string ToString () 
    {
      throw new NotImplementedException ();
    }

    //
    //  --- Protected Methods
    //
    //inherited
    //protected object MemberwiseClone() {
    //  throw new NotImplementedException ();
    //}

    [MonoTODO]
    protected virtual void OnHandleChange () 
    {
      // to be overridden
    }

    [MonoTODO]
    protected virtual void OnThreadException (Exception e) 
    {
      throw new NotImplementedException ();
    }

    protected virtual void WndProc (ref Message m) 
    {
      if (m.Msg == Win32.WM_CREATE)
        Console.WriteLine ("NW WndProc WM_CREATE");
      DefWndProc (ref m);
    }

    //
    //  --- Destructor
    //
    [MonoTODO]
    ~NativeWindow ()
    {
    }

     static private IntPtr WndProc (
      IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) 
    {
      // windowCollection is a collection of all the 
      // NativeWindow(s) that have been created.
      // Dispatch the current message to the approriate
      // window.
       NativeWindow window = 
              (NativeWindow) windowCollection[hWnd];
       Message message = new Message ();
      message.HWnd = hWnd;
      message.Msg = msg;
      message.WParam = wParam;
      message.LParam = lParam;
       message.Result = (IntPtr) 0;

      if (msg == Win32.WM_CREATE)
        Console.WriteLine ("WM_CREATE (static)");

       if (window != null) {
      if (msg == Win32.WM_CREATE)
        Console.WriteLine ("WM_CREATE (static != null)");
         window.WndProc(ref message);
       } else {
        Console.WriteLine ("no window, defwndproc");
         // even though we are not managing the
         // window let the window get the message
         message.Result = Win32.DefWindowProcA (
          hWnd, msg, wParam, lParam);
       }

       return message.Result;
     }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.