Making a GUI without a framework in C - c

I'm learning C (I just finished Chapter 2 or Unit 2) of the C Programming Language, I skimmed to the end and saw that at no point anything was said about how to create a GUI, and from what I've looked up, it seems I have to use a framework, but I hate the idea of that. How would I create a GUI without a framework? How exactly do these frameworks work and what language are they written in? I'm not making a massive application, even if it takes me a week, would it be feasible to write a GUI application (in C) to do something simple like creating a window?

You can build your own framework based on OpenGL or Xlib. Or use good graphics library like Motif or CGUI. Or use something awful like GTK.

Not the best road to take. I would suggest a cross platform library, like GTK+.

Yeah, no go.
C can't do anything except manage memory and possibly do software interrupts (if you do pointer hacking).
You need a library to do anything.
GUI is very complex, you can't do anything "simple" with it. It's a problem I face every single day.
If you want a window in C, you need X11, GTK, Windows API, Video hacking, or other fun stuff.
Oh, and Video hacking is a no go, OS will throw an exception if you even try to touch video memory without its permission.
Oh, and the "simple button" you speak of, in Windows API is actually a Window itself, not very simple.

You can make a basic framework using the WINAPI
There is a great tutorial here.
The problem with using C and primitive frameworks like WINAPI is that manging layout and state becomes exceedingly difficult.
If you targeting a normal operating system, the C only requirement becomes unreasonable. I recommend you go with C++ and Qt and compile your C code in a C++ compiler.

Related

Making a GUI simulator in C

Hello StackOverflow Community,
I am writing a MicroMouse Simulator in C language. And I wanted something to visualize the way the maze is being solved like this -- http://www.youtube.com/watch?v=N9TkDgJNJso
I've been researching a way to accomplish this, but I haven't found anything with enough documentation to accomplish my goal.
I don't want to implement this using ASCII symbols, to me it doesn't look professional.
Is there any good GUI interfaces that I could use in C to help me accomplish this? And if so, how would I use it? I don't mind having to code in another language like Java or Python to accomplish my goal.
I saw the video that you want to make. After watching the video I feel you don't need a GUI library for this simulator program.
Here is a list of libraries that you can use.
1.OpenGL This is a 3D graphics API which also can be used for 2D and can be used with both c/c++
2.SDL This library is easy to understand for a beginner. For your program this library is better and can be used with both c/c++.
3.winBGIm This is same as the graphics.h that you found and can be used both c/c++ but it is only for windows.
If you are looking for GUI library then here's a short list.
1.GTK This is written in c and is a popular GUI library for c. You can find a GUI editor for gtk forms called glade which enables quick & easy development of user interfaces.
2.WxWidgets This is written in c++ so you have to use c++ rather than c.
3.FLTK
There are many more libraries besides these which you can find in google. You said
I do not mind having to code in another language like Java or Python to accomplish my goal.
Then for java you can use swing and If you are windows developer then use the windows form application in visual c++; then development of your program will be very easy.
SDL is one of candidate for C in order to make GUI Simulation. Lazyfoo is one of the best site I found for beginner.
SDL is strongly portable. It's written in C and there're a lot of documentation and tutorials.

User Interface for C-code

I've written a code in linux OS which produces prog.out as output file.
Now I've to write GUI for the code.
what are best ways to write it?
PS - I wanted to choose between Java Swings and openGL.
Which is best for writing a simple GUI and integrating it with my C- Application
Thanks in advance
OpenGL is a rendering library, not a UI toolkit. Comparing it to Swing doesn't make sense. And you can't choose Swing for a C application, unless you'd rather do the UI in Java and interact with a C "backend".
For a pure C solution, the best choice would probably be the GTK+ toolkit.
Try Anjuta...
http://projects.gnome.org/anjuta/
If you are prepared to use another language (you mention Java) then you may find C++ and Qt to be a good fit. Linking to the existing C code will be trivial and Qt works well on a great many platforms should you ever wish to support other platforms in addition to Linux.

2D game development basics

I would like to write some simple Mario-like game from scratch using language C. But honestly I have no idea how to do so, and I canĀ“t find any good tutorial for this, which is for free.
But to the actuall question, I have only written WinAPI programs so far, so all event handling and user input was handled by OS, with minimum work, But to develope game, with for example menus with non-rectangular buttons, animations, and so, I guess, there is no such thing in WinAPI taht could help me with this more than just some basic routines mouse pointer location and keypresses.
So, is the right way to write your game to write entire draw part of game engine by manipulating objects for player, enemies, and even background yourself, and than just use directdraw for output to screen?
EDIT:
I actually want to learn how to write games from scratch, becouse it must be great programming experience, and if you consider games like Commander Keen on DOS, created with no framework or libraries, but still so great.
A good approach to this would be to have a look at the SDL library. I'm not saying it's necessarily the best library for 2D games, but it's easy to get started with and the web is flooded with tutorials and open source code samples for simple homebrew 2D games written using SDL.
I do recommand the SDL too, but you should definitely have a look on lazyfoo tutorial, which is just great.
When I started programming I started doing it with Allegro, back in the good old DOS days. It was the first usable library which worked with SVGA libraries, and had a good sprite support. Then version3 came and they added support for windows (using GDI and Directy X, you could choose at runtime which engine to use). The linux port came to life, and all is good.
It's a very basic 2D library, and it will teach you the very basics of graphics and animations. Now it even contains audio support which is a very needed addition (well, I still remember V 2.9X...). They are in betas for version 5, and I think this is an interesting project for you to look into.
http://www.talula.demon.co.uk/allegro/
What are you guys talking about, the WinAPI has low level drawing routines.
Although using an established library like SDL is probably a better idea you could create your own abstractions to the WinAPI drawing routines without too much difficulty.
Then it's just a matter of creating the while loop that has all the drawing instructions and interpreting input. For 2D games this isn't too difficult.
I also used SDL, but try to look at HGE. It requires at least DirectX 8.0 so your applications will work only on Windows but on their forum you will find many topics on how to port it to OpenGL. In my opinion HGE will be easier to learn than SDL, because SDL is a low level library and you will have to learn how to handle many things by yourself. HGE is more ready to start just out of the box.
In short, yes - there's nothing in the WinAPI that will help you much. However, there are dozens of game engines that you could build your game on that would take a huge amount of gruntwork out of creating the game itself. A bit of Googling will help you.
(Personal recommendation: although it's technically a 3D engine, something like Unity is an excellent engine that includes tutorials for creating 2D games. Unity isn't C, but it does make your life a lot easier...)
EDIT: I actually want to learn how to write games from scratch, becouse it must be great programming experience, and if you consider games like Commander Keen on DOS, created with no framework or libraries, but still so great.
This is actually not quite right. Commander Keen (and any DOS games) do use libraries: the ones provided by DOS, BIOS, etc. Without libraries of one form or another, you wouldn't be able to do anything useful with C. For game programming, you really do want to leave all the low level details to someone else.
I'd recommend Allegro as a beginning game programming library.
Check out this one Game dev starting
They have realy a big resource related to game programming and a lot of beginner stuff. SDL is good, but you should consider about learning basic game techniques before start coding and even before start thinking about the api/libs you use.
Clear out how much "intelligence" you need (Ki), consider about loading/Saving a an early time, ... so much things that you should keep in mind if you want to finish your project.
Do you need a game editor? (Also..work) What about sound/graphics? Writing all this stuff on your own will take a lot of time (if you do not have experience). Creating the content is another big issue which can consume a lot of time, if you make it at all.
Maybe it will help you to have a look on some dev kids, because that will give you the idea how their engine works. Like this one (outdated) Dev kid
I've just started a similar project a few days ago, you can check it out over at GitHub.
It should give you some ideas about how the game is structured. As well as some details on a scrolling 2D map with collision (which turns out to be quite complicated if you want to get it 100% bug free). Oh, and it's using SDL as many here have already suggested.
As for me, this is my first C project. But I'll have to admit that I've done similar stuff in Java and Python before, so this was a good way for me to quickly learn C. And since it's learning and not any productive stuff, I'm using plain C99, which makes the task even "funnier".
But back to the game, you really need to think about your design before you start coding, write it down on a sheet of paper, or if you're like me and you don't have tree stuff in reach write it in pseudocode.
Think about as many possible game states as you can, nothing's worse than having to re-implement the whole player/map/whatever stuff from scratch just because you did not think about feature XYZ before.
Design is very important, if you don't have a goal to begin with, your project will reach a point where it fails, just like my Tuff did, well it also failed due to missing music and somebody who would have designed enemies, etc.
Speaking of graphics and such, bear in mind that the game will consist of much more than just the plain code. If you aren't good in graphics then take that into account while designing. Because you will quickly lose your motivation when the only things on the screen are colored rectangles.
Action Arcade Adventure Set (originally published as a book) is probably one of the most complete tutorials on how to write a 2D side-scrolling game. Although an older reference, many fundamentals for developing a 2D side-scroller have not changed.
Full source code examples and some tools to develop a side-scroller are provided as downloads. There is only one external library used to handle graphics primitives. As this is an older DOS program, you may have to use a DOS emulator like DOSBox or modify the examples for more modern environments.
I suggest you skim chapters 1 to 9 and focus on chapters 10 to 17.

C win32 wrapper

I'm developing a win32 app in the C Programming Language. This is my first experience with the native win32 apis and they seem to be completely brutally unreadable (simple window).
I was wondering if there was a wrapper for the entire API that I could use, instead of having to smash my head with this stuff.
Other frameworks/libs won't do since I want to work with Windows' native api.
Thanks!
Other GUI frameworks/libs won't do since I want to work with Windows' native api.
If you want to work with the Win32 API... you have to work with the Win32 API. You'll want to get your hands on a copy of Petzold (http://www.charlespetzold.com/pw5/) and go from there. The example you posted is not incredibly complex, once you have seen the explanation for what the code does you will probably be less worried.
MFC/ATL/Qt/wxWidgets will all allow you to get handles to the controls if you need to customise anything.
Is there any particular reason you want to work with the native Win32 API?
Once you understand the code its not that complicated; the main issue is that you need to deal with all the boiler plate stuff yourself and which is where you lose more time. I don't know your situation, but would using a framework like MFC be acceptible? The same window in C is relatively easier in MFC as shown here and it hides some of the boilerplate code. Also there are a few cross platform options such as Qt4, but not sure if those will be acceptible or not.
If you're using pure C, then none of the common frameworks (MFC, ATL, etc) will help you. There might be other libraries (TCL?) but it's going to be fairly evil.
Even today not all of the tutorials online utilize the Message Crackers in Windowsx.h. Make sure you're familiar with those, they will save you some grief and help make your app easier to migrate.
WinForms on the .Net framework is a nice (nearly comprehensive) wrapper around the Win32 windows api.
In the C/C++ world, the ATL api is a (somewhat) higher level alternative to using the raw apis
Rad Studio which include C++ Builder and the VCL can be a good choice

Help needed in writing a GUI app in C

I want to write a standalone GUI based app for administering one of the most popular enterprise middleware products from a very big company. But that big company already has a admin tool and its free.
But guess what , its very very slow , since its written on the java/Eclipse platform.
I want to write a very fast responsive GUI tool natively for windows.
I do not have much experience programming for windows , So what library(open source preferably) i can use on windows to get the job done.
Note: I need to write it in C, Not C++ , But if i dont have any choice I guess i can do with C++.
So I basically need to write a GUI app in C with some good GUI library.
Please help me out.
Thanks.
Edit : I do not know OOP and don't prefer using it.
Edit : So my choice is down to Win32API and Qt.
my requirement is that of a simple GUI , nothing fancy. I will be using simple windows ,buttons and menus. But I may need to do some processing , which means GUI should not take up much resources.
Based on this I m thinking of using Win32 API , even if I have to take the pain to hopefully satisfy the users.
its very very slow , since its written
on the java/Eclipse platform.
Are you sure that this is the reason for the application's slowness? I am no
fan of Java, but before you reach any conclusion, have you made sure that
writing the software in c makes it noticably faster? It could be that the
application is slow for reasons that are not under the control of the GUI programmer,
such as a slow database or bad network latencies.
Also, I don't mean to be rude here, but do
I want to write a very fast responsive
GUI tool natively for windows.
and
I do not have much experience
programming for windows
not contradict each other?
If you want to write a C GUI app, stick to Win32 or GTK+.
Win32 is blazingly fast, and will let you access everything available to Windows. Take a look at this tutorial.
GTK+ is extremely easy to use, cross platform, and provides tons of extra functionality. Start by downloading the all-in-one bundle, and move onto a tutorial and the documentation.
Personally I'd recommend going straight to Python if you need quick, responsive GUIs, and just need to wrap some lower level stuff.
Why are you limiting yourself to C? Windows Forms and WPF and SIlverLight are all viable UI frameworks that are responsive and have tons of books. There's a reason you can't find much info about writing GUI apps in C - people don't do it.
For plain C, cross platform, native look, simple, scriptable UI, I suggest to have a look at IUP: http://www.tecgraf.puc-rio.br/iup/
If you really have to use C then you can use GTK+. Otherwise, I'd suggest a C++ library like QT or wxWidgets. However, that being said I still think it would be preferable to build a .NET (Windows Forms or WPF) solution. They should provide a better UI experience than Java/Swing.
If you really want to do it in C, you could use the Win32 API. But it's hell working with it. The Object Oriented variant isn't much better either, but it takes away a bit of the pain (MFC).
I strongly recommend you to use C++ with the Qt library, which is both cross-platform and open-source (LGPL). C++ Qt GUI applications are as fast as native Win32 applications, although they take more memory. And you can't even start comparing the productivity gains - Qt is a great library, terrifically designed for GUI programming with tons of other useful tools.
Most GUI toolkits are written in C++, so restricting yourself to C will limit your options somewhat. One option that is cross platform and written in C is GTK; it's originally for X, but runs on Windows as well.
edit: Of course, you could always just program directly against the Windows API (formerly know as Win32) itself. For simple GUIs, it's not too bad.
GUI components map very well into Object oriented paradigm. Using C for GUI applications is a bad idea, I've been there and it's much more confortable to do it in an propper OO fashion with C++. Of course you can sort of do OO with C but it's ugly to say the least.
In my opinion, more than the GUI frameworks you need to really work on the design of the application you building.
For a normal GUI in C/C++ Win32 provides enough of controls for a decent looking application with good response time.
What you should really focus on is how to make it multi-thread based upon the time your modules take for execution.
Consider this small example: You have a DataBase connection monitoring in your GUI which is probed every second. Another module may be sending some big files to other applications. Now if an application is single threaded, your GUI is bound to have response problem. If you database connection is very slow due to some network/db issue your app will hang irrespective of the GUI frameworks or hardware chosen, if it was a single threaded app.
But if you write a good design and dedicate a separate thread for GUI handling and other threads for handing background tasks, you will have a really good GUI response. That way you can perform other tasks in background and GUI gets updated when notification is obtained. Remember, it wont happen magically and you need to sync you threads and update GUI.
Also, avoid creating threads for each and every task. You need to check things which can take more time like sending big files or faster tasks like checking/reading if config file exists or not.
By using third party GUI frameworks you are increasing your dependencies in your application and you would require to ship additional dlls etc with you main application. With win32 things are pretty neat.

Resources