Jump to content
  • Advertisement
Sign in to follow this  
rAm_y_

Understanding CreateWindowEx

This topic is 1305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It's not an open source function I know and Linux will have an open source[?] equivalent. So I am trying to understand what is underneath this API call, as far as I know it's one of only a few win32 API drawing functions, but then it can't be written in pure C/C++ as it's a fundamental graphics function?

 

So would the implementation of CreateWindowEx have to be directly written in assembly language, it was created before the days of GL/DX I believe so how exactly is this implemented at the lowest software/hardware level?

 

I never did any DOS programming so I don't really understand about mode 13h and the like etc I believe that's similar to how the old 8-bit z80 computers/consoles such as the ZX spectrum operated, where you had memory set aside for specific operation like drawing so that you could call a specific section of memory directly to do your task.

Share this post


Link to post
Share on other sites
Advertisement
CreateWindowEx was written in C. The system surrounding that was written in C. Below that was written in C and inline assembly. Below that was written in an HDL. Below that, it's turtles. It's turtles all the way down.

Share this post


Link to post
Share on other sites
CreateWindowEx is one of what can be considered a system call. You cannot reimplement it directly. It's a core part of Windows itself. HOW it's implemented is entirely irrelevant; the important part is just that it is the entry point to the Windows operating system telling the OS to create a window. All of the actual interesting work of creating a window is built-in to Windows. There may indeed be some assembly that actually links CreateWindowEx into Windows in order to execute the syscall, but those details are not terribly important unless you plan to write your own OS.

A rough equivalent on Linux might be xcb_create_window. That function is a bit higher-level as it is part of the XCB library, which you certainly could reimplement (its just plain C, and it speaks the X11 protocol to the display server running on your machine). Again, though, all of the actually interesting work of creating a window is in that display server, not the XCB code. On Linux you could write your own display server (again, just plain C works) but it's a very complicated task and requires interactions with the Linux kernel and the hardware for things like graphics, input, timing, etc.

While you can't reimplement CreateWindowEx on Microsoft Windows, you certainly can emulate it. The Wine project implements various Win32 functions like CreateWindowEx on top of XCB/X11 on Linux or Cacoa on OSX, for instance. The implementation of CreateWindowEx there probably just plain C.

There are also projects like ReactOS, which is an Open Source compatible clone of Windows. It naturally also has a CreateWindowEx function with full source code that you can look at to see exactly how that function is piped into the underlying OS.

Share this post


Link to post
Share on other sites
A rough overview of how it works:

A core DLL of the OS provides the CreateWindowEx call. Because it's a well-defined point of entry using a defined API, you can call it from virtually any language: assembly, C, Python, etc.

This DLL has what is probably a small amount of wrapper code. It may be written in C, assembly, or a combination. this code basically takes the function parameters and passes it over the appropriate channel to the OS, be that a low-level system call (how those work is OS dependent, but it usually involves some special assembly instruction and a specific calling convention) or an RPC call into another user-space service over a socket or the like (which itself boils down to a system call).

The windowing system then has heaps and heaps of code, usually written in C, that manages windows, states, events, and so on. It receives the system call request and executes its internal C functions just like any other program. Some of those internals may call into yet other parts of the OS to do things like create graphics handles.

It'll be a lot easier to learn all this by picking a simpler OS call, like opening a file, and then inspecting the documentation for the Linux kernel, which is very thorough and much more public than the internals of Windows. That said, if you care about Windows specifically, check the code/documentation for Wine and ReactOS, look at sites like https://technet.microsoft.com/en-US/sysinternals, or buy the book aforementioned site backs like http://www.amazon.com/Windows-Internals-Edition-Developer-Reference/dp/0735648735 - it's complicated enough that you're not going to get a detailed answer typed in a forum post. smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!