Coffeehouse Thread

25 posts

Win32.NET to replace Windows Forms

Back to Forum: Coffeehouse
  • User profile image
    TommyCarlier

    I've been working on a small library to create Win32-applications in .NET, without using Windows Forms. Yesterday, I was able to run my first demo, which just showed a window. It's not much, but it's incredibly fast.
    When compiled in release mode, the Win32 library (TC.Win32.dll) is only 64KB and the demo app is only 16KB!
    The library currently only has references to mscorlib.dll and System.dll and via PInvoke also to KERNEL32.DLL and USER32.DLL. The demo app only has references to mscorlib.dll and TC.Win32.dll.

    Here's the source code of the demo app:

    using System;
    using System.Collections.Generic;
    namespace TC.Win32.Test
    {
     static class Program
     {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
       WindowClass lClass = new WindowClass("Test", WindowProcedure);
       lClass.Register();

       Window lWindow = Window.Create("Test", "Win32.NET Test", 10, 10, 300, 200, Window.Null, WindowStyles.OverlappedWindow | WindowStyles.Visible, WindowExStyles.Left);

       Message lMessage;
       while (Window.Null.GetMessage(out lMessage))
        lMessage.Dispatch();
      }

      static int WindowProcedure(Window window, WindowMessage message, int wParam, int lParam)
      {
       if (message == WindowMessage.Destroy) Window.PostQuitMessage(0);
       return window.DefaultWindowProcedure(message, wParam, lParam);
      }
     }
    }
  • User profile image
    littleguru

    Wow! This looks nice. Did you do some tests with WinForms vs your API?

  • User profile image
    TommyCarlier

    No, not yet.

  • User profile image
    rhm

    OMG, it's like going back to the dark-ages of SDK programming on Windows 3 but with C#. Why would anyone want to do such a thing?

  • User profile image
    Khamul

    Coz it's fun!

  • User profile image
    Wells

    This is cool. I <3 Win32! Although it's very difficult to create an object-based wrapper for it... many have failed.

  • User profile image
    Lee_Dale

    Its not .Net though is it?  The only .net it's using is PInvoke?

    Why would you want to do this? Create the same program with C++ and i bet its 1000 times faster and smaller

  • User profile image
    TommyCarlier

    What? No .NET? Just because I use PInvoke makes it not .NET? That's ridiculous. Then how do you define what is .NET and what isn't? You can't make a Win32 wrapper without using PInvoke.

  • User profile image
    littleguru

    Khamul wrote:
    Coz it's fun!


    Seconded. There is no real use for it... At least I can't see one, because it makes everything so much complicater. But it's a lot fun Smiley

  • User profile image
    TommyCarlier

    There is a real use for it. My first idea was to build a high-level UI library like Windows Forms, but designed to be lighter and more platform-independent. To be able to do this, I need a low-level platform-dependent layer to build it on. You can not build a high-level UI library on nothing. That's why I started my Win32.NET project. It is not my intention to build applications directly on top of Win32.NET, although it is possible, and probably not that hard, if you're familiar with Win32.

  • User profile image
    littleguru

    Ah ok... Makes sense. Smiley

  • User profile image
    TommyCarlier

    But of course, it's mostly for fun Wink

  • User profile image
    Foxfire

    Why don't you help mono get their Managed.Windows.Forms implementation ready?
    That would not only be fun but also have some positive effect Wink

  • User profile image
    Lee_Dale

    TommyCarlier wrote:
    What? No .NET? Just because I use PInvoke makes it not .NET? That's ridiculous. Then how do you define what is .NET and what isn't? You can't make a Win32 wrapper without using PInvoke.


    Its not .Net its not managed code is it?

    Its just a WIN32 app with the added overhead of using PInvoke to access WIN32 functions rather than calling them directly with C++


  • User profile image
    TommyCarlier

    If you're refering to the demo app you see above: it's just a demo. It was a little something I wrote to TEST my library. Like I explained, Win32.NET is not meant as an application platform, but as a 'support' library: to support a high-level UI library built on top of it.

  • User profile image
    ZippyV

    You could get more people on your side if you showed something that can't be done in the current Winforms.

  • User profile image
    TommyCarlier

    I have nothing agains Windows Forms, I use it myself, but if you've programmed long enough in WinForms, you find certain quirks and limitations. One thing that bothers me: every Control in WinForms needs a Win32 handle (hWnd). But there is a limit on the number of handles an application can use. If you have a large WinForms application with lots of windows and controls, it's not hard to hit that limit. One of the ideas of my high-level UI library would be to have controls without handles; to only use handles when it's really necessary.

  • User profile image
    Lee_Dale

    TommyCarlier wrote:
    I have nothing agains Windows Forms, I use it myself, but if you've programmed long enough in WinForms, you find certain quirks and limitations. One thing that bothers me: every Control in WinForms needs a Win32 handle (hWnd). But there is a limit on the number of handles an application can use. If you have a large WinForms application with lots of windows and controls, it's not hard to hit that limit. One of the ideas of my high-level UI library would be to have controls without handles; to only use handles when it's really necessary.


    Sorry i dont mean to piss on your parade or anything i'm just a little confused as how this benefits over using C++ and WIN32 directly apart from the fact that you can use the C# language. If winforms didn't provide enough functionality or was too bloated for what I wanted to do, then I would probably turn to using WIN32 directly in a C++ app because that all your really doing with this PInvoke route except your bloating it by using PInvoke, it kinda sits in the middle of full 'do everything yourself' C++ and 'does everything for you' C#, can't really see who would want that?

    Again I'm not trying to stifle you or anything just trying to see what your getting at.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.