tags:

views:

652

answers:

9

Hello,

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

+5  A: 

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

Adam Rosenfield
wxWidgets is a very nice library for that
Eloff
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
@Clifford: Sorry for the confusion, I've reworded my answer.
Adam Rosenfield
Then I removed the down-vote; not because the answer is great, but no longer misleading.
Clifford
Isn't wxWidgets a C++ lib - are C bindings available?
Christoph
+1  A: 

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

Roy Cotton
While MSVS is a great suggestion, OP says it's a school assignment, so he probably can't use C#.
Adam Rosenfield
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!
BobbyShaftoe
A: 

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

Dominic Bou-Samra
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
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.
BobbyShaftoe
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.
Dominic Bou-Samra
+2  A: 

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.

queen3
+1  A: 
Norman Ramsey
+5  A: 

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.

mathepic
It's debatable if GTK looks "great" under any window manager.
rlbond
It is debatable but I don't think its bad.
BobbyShaftoe
+2  A: 

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.

Clifford
+1  A: 

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.

Christoph
+1  A: 

so yeah I am going through the same stage and i need a pure C library to develop windows elements. I am guessing that all the libraries mentioned above are cross-platform?? if not please guide me through

Oh, and i was planning to go with Cocoa i don't know why i stopped and think of the object oriented nature of the library which is not C but Objective-C rather.

please.. help

BornToRule