Question

If I use the System.Windows.Forms.MessageBox class' show function to draw a message box, a window pops up. I would like to know where the actual code to draw this window is? Is it in some Win32 API or user32.dll etc.? Through reflector I am unable to see the definition of Show method.

Also, is .NET a wrapper around win32 api then? I know that when we compile .net code it generates IL which is converted to CPU specific instructions at run time and then our CPU executes those instructions. But I have a feeling that there is some common code in Windows OS that's responsible for drawing a window (or reading from text file etc.). All these languages like C++, F#, C#, Java etc. eventually call that code from within the framework. But the question how can I go about finding it and verify it?

For example: in MFC or Win32 whichever function we called to draw a window on the screen, MessageBox.Show also calls the same function but its abstracted from us?

Then on the other hand we can inter operate between two languages.

So I am little confused here. Also I am reading CLR via C# these days so my brain is in super excited state :-)

Était-ce utile?

La solution

I think that you are on the right track. No matter the language or the framework, at the very bottom is the Operating System, so everything ends there, eventually: system calls.

For example, to open a file in Windows the system call is CreateFile(), no matter if you used C fopen, C++ ifstream, C# System.IO.* or Java java.io.*.

About your questions of System.Windows.Forms, they use the usual Win32 windows, so the windows are identified by HWND values, represented in the CLR as IntPtr.

And about the function to show the window, your question is a bit misleading, as there are several functions involved, and several layers in the Win32 API.

For example to create a window, you call CreateWindowEx(), to show it if hidden call ShowWindow(), and the paint itself will be handled when the window procedure (a callback you have to write) receives the WM_PAINT message. But in order to receive messages you have to write a message pump (GetMessagte() / DispatchMessage()).

But to create a simple MessageBox() there is a function already available that does all that for you: MessageBox(), for which the System.Windows.Forms.MessageBox class is a direct wrapper.

So now, what was the question? Ah, yes, can we interoperate between System.Windows.Forms and Win32? Yes!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top