2

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++.

2
  • Why is your question tagged C and C++. They are not the same language! Nov 7, 2009 at 22:27
  • Someone edited it to include the C++ tag. I've corrected this.
    – asveikau
    Nov 7, 2009 at 22:29

8 Answers 8

7

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.

2
  • It's debatable if GTK looks "great" under any window manager.
    – rlbond
    Nov 7, 2009 at 22:28
  • It is debatable but I don't think its bad. Nov 7, 2009 at 23:06
6

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).

5
  • wxWidgets is a very nice library for that
    – Eloff
    Nov 7, 2009 at 22:07
  • That is just nonsense; the language standard and the library standard are separate things, using libraries other than the standard C library, does not make the resulting code "Not ANSI C". "ANSI C" and "portability" are not synonymous.
    – Clifford
    Nov 7, 2009 at 22:11
  • @Clifford: Sorry for the confusion, I've reworded my answer. Nov 7, 2009 at 22:18
  • Then I removed the down-vote; not because the answer is great, but no longer misleading.
    – Clifford
    Nov 7, 2009 at 22:23
  • 2
    Isn't wxWidgets a C++ lib - are C bindings available?
    – Christoph
    Nov 7, 2009 at 22:30
2

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.

4
  • I know it's been many years, but is C still a subset of C++? I've been trying to start working with C on Windows and I'm having a hell of a time finding the right standalone compiler. I've run into the issue of not knowing if I need a Windows compiler for C++ and one for C, or something else. I've been going through Microsoft page after Microsoft page. Closest I've gotten is Visual Studio Express.
    – Ungeheuer
    Jul 7, 2017 at 6:15
  • @Ungeheuer : I am not sure how your comment relates to my post, or this thread. If you have a question of your own, post a new question. The last Visual Studio Express edition was for Visual Studio 2015, Visual Studio Community Edition is more fully functional (allows plug-ins) but more restrictively licenced (commercial use only for "small" enterprises). Visual Studio 217 Community Edition is current. The Visual C++ component of Visual Studio both C and C++. If the source files have a .c extension C rather then C++ compilation will be used (and they can of course be mixed).
    – Clifford
    Jul 7, 2017 at 11:39
  • @Ungeheuer : The application wizards and templates are for C++, so start with the "empty project" template and create/add files manually.
    – Clifford
    Jul 7, 2017 at 11:40
  • looking at this again, not sure what I was thinking at 3am...my train of thought was probably along the lines of Dev-C++ doesn't come with the official Windows C/C++ compiler. To write fully compatible C programs in Windows, I was told one needs the official Windows compiler, and I've got no idea what it is. I'll probably ask a question.
    – Ungeheuer
    Jul 7, 2017 at 15:16
2

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.

1

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.

1

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.

0

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

2
  • While MSVS is a great suggestion, OP says it's a school assignment, so he probably can't use C#. Nov 7, 2009 at 22:10
  • 5
    This doesn't make any sense. How do you use C# in C when the question is clearly marked ANSI C. There is so much anti-C propaganda on this site already; I don't think we need more! Nov 7, 2009 at 23:03
-1

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

3
  • 5
    Typical of managed coders to heckle and troll people for their language choice. It's 2009, yes, and apparently people are getting stupider, because everyone on this site seems to be afraid of C. :P
    – asveikau
    Nov 7, 2009 at 22:23
  • 2
    Why don't you tell Microsoft that. heh. If someone wants to program GUI applications in C that is their choice. Also, C++ isn't ANSI C just FYI. Nov 7, 2009 at 23:05
  • 1
    I never said I was afraid of C/C++... nor that it was poor choice. My post merely shed light on an arguably easier and more relevant direction for the OP. There's nothing wrong with suggesting an alternative path. Nov 7, 2009 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.