Tutorial :How to make window application in ANSI C?


Until now I've been only writing console applications but I need to write a simple window application for a school assignment.

Could somebody point me to a good tutorial how to create windows and other ordinary windows elements such as buttons, 2d graphs etc in ANSI C? is there some good library I should use?

I tried googling but there are no tutorial websites devoted to C.

If you can, I would also appreciate some example code.

Thank you.

By the way, I use Dec C++.


There's nothing in the ANSI C standard about windows. If you want to make a windowed application, you'll have to use platform-specific libraries (e.g. Win32, Cocoa, or X11), or some sort of cross-platform library that encapsulates that (e.g. SDL, wxWidgets, or many more).


GTK is a good library to use, but may provide non-native looks under Windows. It looks great under GNU/Linux, especially using GNOME.

It is implemented in just C (Using the GObject Type System, part of the GLib library), so it will work great for your needs. There is also a RAD tool called Glade.


Common places to start are Charles Petzold's Programming Windows and theForger's Win32 API Programming Tutorial.

However in most cases C is no longer the preferred language for Windows development. Object oriented technology is far better suited to GUI development, and with the introduction of MFC, C++ became the preferred language, and later with .Net, C# and C++/CLI.

The Win32 API can be hard work, much of MFC is little better than a Win32 API wrapper, the .Net framework however was designed from the ground up, and is less encumbered by the legacy of the Win32 API monster, and working with it tends to result in far greater productivity.

Either way, Dev-C++ is not a great tool for GUI development.


http://support.microsoft.com/kb/829488 which also talks how to create

Windows application: Creates a simple Microsoft Windows-based application. The application files include a ProjectName.cpp file that contains a _tWinMain function. You can use this type of application to perform graphical user interface (GUI) based programming.

As for tutorials... use MSDN. Win32 API is C. You don't need "Win32 ANSI C tutorial" - you need Win32 tutorial (for example http://www.winprog.org/tutorial/start.html, http://www.functionx.com/win32/Lesson01.htm) - unless, of course, you don't know ANSI C but then you just look for ANSI C tutorial. These subjects are independent.


There are lots of good librariesâ€"too many for there to be an obvious choice without starting a religious war. I recommend that for your first library you learn something that will work on Windows, Linux, or OSX. Here are two good choices, not necessarily the best, but widely used and personal favorites:

  • Tcl/Tk. You write most of your application in the Tcl scripting language, but you can easily integrate your own ANSI C code into Tcl, which was designed from the beginning with such integration in mind. The Tk toolkit is very easy to learn, and you can write many simple GUIs in pure Tcl when you are getting started. Interactive, easy, and very well supported.

  • If you want to write everything in ANSI C, I don't know of any really simple choices, but I've been fairly happy with wxwidgets. All these tools have a pretty steep learning curve, however.


There are not many plain C GUI libraries as the strengths of the language lie elsewhere. Perhaps you should think about using a language with C bindings so you can still do the number crunching in C, but use something less painful for GUI development?

If you really want to stick to C, you can either use the OS' native API or the only current cross-platform C GUI lib I'm aware of: GTK+. If you don't really need a GUI but just graphical output, I'd go with SDL.


I suggest you download Microsoft Visual Studio 2008 Express Edition and use C#.Net.


As has been said, I suggest you use Winforms and switch to a .Net environment. It's 2009, and I think there are more suitable solutions to GUI's :P

Edit: Nvm, didn't see it was a school assignment.

However, here is a C++ guide on the Win32 API: http://www.relisoft.com/win32/index.htm

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »