Home > Mobile >  How does .NET create a window?
How does .NET create a window?

Time:02-04

For example where is the window created? Is any Win32 native function called? I tried to search in the mscoree.dll but I didn't find a function like CreateWindowEx that could do this.

CodePudding user response:

The UI frameworks of .NET, WinForms/WPF and many more, are in general wrappers over native OS UI frameworks (either Win32 on Windows, or Cocoa on macOS, or GTK on Linux).

To learn how they wrap over such native APIs, you should search within their source code repos, not mscoree.dll,

CodePudding user response:

So a bit of poking around with ILSpy.exe on System.Windows.Forms.dll found the following method chain:

new Form();
|
Form.CreateHandle();
|
Control.CreateHandle();
|
NativeWindow.CreateHandle();
|
WindowClass.Create();
|
new WindowClass();
|
WindowClass.RegisterClass();
|   
UnsafeNativeMethods.GetProcAddress(
    new HandleRef(null, 
        UnsafeNativeMethods.GetModuleHandle("user32.dll")), "DefWindowProcW");

I am not that familiar with Win32 windowing and I might have missed the actual window creation sequence, but I bet it is burred somewhere in the NativeWindow class.

  •  Tags:  
  • Related