Thread: When to switch from console apps??

  1. #1
    Registered User jimtuv's Avatar
    Join Date
    May 2010
    Location
    Sylvania, Ohio
    Posts
    94

    When to switch from console apps??

    I have written quite a number of console programs now and wondered at what point in learning C is it beneficial to begin to learn to make a GUI.

    So far I have studied
    Algorithms
    Variables
    Arithmetic Expressions
    Input and Output
    Program style
    Conditionals
    Functions
    Function Parameters
    Iteration
    Loop Development / Program Schemes
    Complex Conditionals
    Functional / Data Decomposition
    Function Design
    Switch
    Structures / Unions
    Pointer Parameters
    Arrays
    Searching
    Sorting
    Multi-Dimensional Arrays
    Strings
    Nested Data Structures
    Recursion
    I am just beginning Memory management, Dynamic arrays etc..

    Wow I didn't realize how big the list was.

    Is it too soon to try this?? If not what would be the best course of action?? I am on Ubuntu and will most likely start with Glade Interface Designer (just cause it's already installed). I also have Window XP but almost never use it. Does anyone knows how to design for both?? I could use a heads up on what software works best.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,608
    In C? Um...never. In C++.....maybe a bit more often. I personally do not use C or C++ for GUIs since C# came into the picture.

    But if you want to try to do some small GUI apps in C or C++ then have at it. Coding GUI apps has more to do with design than actual graphics or implementation anyways so I think you could try it. Design is very important in a GUI library b/c if it's wrong from the beginning you will be chasing your tail as you attempt to create new GUI widgets. On a personal note I rather detest GUI programming but it is a necessary evil.

  3. #3
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Look into wxWidgets; I have used it to make GUI apps on Linux that also ran on Mac, Winders and a few others. It is C++ though. If you want C and want cross-platform, I think GTK is going to be your only choice.

    Now as to *when* to switch to GUI apps, you have two choices:
    1. Go the Windows route (not the platform; the mind-set) where the GUI is welded to the app. If that is the case, know that GUI apps is all you will ever do. You can still do console apps on Windows but they are forever second-class citizens.
    2. Go the UNIX route where good command line or console apps are paired with 1-n GUI wrappers. MPlayer is a good example where the command line app is distinct from any GUI front-end so you can have the front-end or GUI that you like. This is forever denied to you with option 1; you take what the author chooses and like it. Or not. GDB is another example; a solid command line app with many different front-end GUIs ranging from DDD to Insight to Kdbg to many others.

    At the end of the day you have a choice to make: choice or no choice. It's up to you.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  4. #4
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    C++ is much better for GUI than C.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,608
    Is the old Turbo C++ GUI available as a library? I remember somewhere reading about it being available but didn't look into it. If so you could look into that windowing system. A lot of the old text games and even DOS 4,5 and 6(?) used console GUI to with good success. There is a non-C route to with the old version of Visual Basic that runs in DOS or a DOS shell and is still available on the internet. I'm not recommending it but the GUI concepts presented in it may help you either with a C library and the concepts in it or in designing your own.

    I recommend that either route you take you spend some time messing around with GUIs and looking into various libraries. Most of them operate on similar principles.

    It is possible to code your own but on a Windows platform I think you will need ncurses or whatever it's called to do any type of console mode graphics. I'm not very familiar with Unix or Linux so I would heed the advice of jeffcobb for those platforms.

    If you want to use C++ and you are on a Windows platform there are lots of libs out there for this but as always I recommend MFC since it is readily available if you have at least the standard edition of MSVC. It's not as bad as people claim it is. If you choose Windows and MFC then I recommend you post your issues in the Windows forum as we have a resident expert on MFC who frequents there.
    Last edited by VirtualAce; 06-19-2010 at 05:41 PM.

  6. #6
    Registered User jimtuv's Avatar
    Join Date
    May 2010
    Location
    Sylvania, Ohio
    Posts
    94
    I kinda figured C++ may come in here soon so I already picked up a book from the library. I also am exploring Ruby and Python as well. It's funny a few weeks ago I didn't have a clue about any programming language. Any time I saw code it just looked like gobbledygook. But know it seems so easy to understand what is going on and the other languages don't seem all that difficult. It's been a blast learning so far and I am excited to explore all the possibilities.

    Gtk is where I have been poking around but I will make sure to check out wxWidgets too. I have Code::Blocks and it seems pretty well suited to do both GTK and wxWidgets.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,219
    I would also check out Qt. Another cross platform open source GUI (and many other things) framework. The system (signals and slots) feels very "natural" to me compared to other GUI toolkits (with callbacks). But of course YMMV.

  8. #8
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Another alternative is to separate your interface code from the rest of your application by trying to stick to a "model view controller" model as closely as possible. Then redo the interface for a new platform, if you use graphical interface tools.

  9. #9
    Registered User jimtuv's Avatar
    Join Date
    May 2010
    Location
    Sylvania, Ohio
    Posts
    94
    I will definitely research "model view controller". From the quick scan I did at Wikipedia it sounds like a very good idea indeed.

    I made my first pop up window. What I learned from it is; always use a interface designer because looking up and typing the code to set up the windows and event handling is a real pain in the butt. Took me a couple hours to find all the necessary bits to get it working. Then I redid the same window in Glade and it only took 5 min to accomplish the same task.

    Code:
    #include <stdlib.h>
    #include <gtk/gtk.h>
    
    static void hello(GtkWidget *widget, gpointer data){
        g_print("Hello World it's Jim\n");
    }
    
    static gboolean delete_event(GtkWidget *widget,
                                 GdkEvent *event,
                                 gpointer data){
    
        g_print("delete event occured\n");
    
        return TRUE;
    }
    
    static void destroy(GtkWidget *widget, gpointer data){
    
        gtk_main_quit();
    }
    
    int main(int argc, char *argv[]){
    
        GtkWidget *window;
        GtkWidget *button;
    
        gtk_init(&argc,&argv);
    
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    
        g_signal_connect(window, "delete event",
                         G_CALLBACK(delete_event),NULL);
        g_signal_connect(window, "destroy",
                         G_CALLBACK(destroy),NULL);
        gtk_container_set_border_width(GTK_CONTAINER(window),10);
    
        button = gtk_button_new_with_label("Hello World");
    
        g_signal_connect(button, "clicked",
                         G_CALLBACK(hello),NULL);
    
        g_signal_connect_swapped(button, "clicked",
                                 G_CALLBACK(gtk_widget_destroy),window);
    
        gtk_container_add(GTK_CONTAINER(window),button);
    
        gtk_widget_show(button);
    
        gtk_main();
    
    
        return 0;
    }

  10. #10
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    BTW I would like to share one way that console apps can be better than GUI versions of the same thing. As noted in another thread I am in the process of restoring some 5 years of ripped DVDs to a server that lost its mind the other day (PEBKAC on my part). I have currently four machines on my network all working on the re-rip/transcoding process and since the app I wrote to do this is non-GUI, it makes for a very natural way to connect to the boxes from the comfort of my laptop and drive everything from there (in Vegas it was triple-digits hot this weekend and the server room is an oven at points). I just opened four terminals and connected each one to a different server and went from there. Doing this with four GUI-based apps/desktops would be really awkward plus the control of these apps has a very minimal impact on the bandwidth of my network so its like the apps are all running on my local desktop. Not saying this is the right answer for everything but right now, on this exact mission/job I am delighted to have console apps at my beck and call. I anticipate slaving two more machines in on the task today which would be even worse if each one had a GUI...http://jbcobb.net/images/my_slaves.png
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    There are fewer pure C GUI libraries than C++ ones, but I would not bother to learn C++ just to do GUI's.* I've done tons of stuff in C with gtk, including stuff now distributed by debian. WinAPI is vanilla C too, I believe. Most of the linux desktop is C/gtk -- it ain't C++, this is a lot of whining. WRT to gtk, the results are the same, just the C++ libs (gtkmm) use 200-300% more memory (but your codebase will be smaller).

    Quote Originally Posted by jimtuv View Post
    most likely start with Glade Interface Designer (just cause it's already installed).
    Glade is like a scripting tool for use with Gtk. Skip it. You might as well just focus your energy on Gtk itself:

    GTK+ 2.0 Tutorial -- what I started from
    GTK+ Programming -- very helpful forum, mostly C but C++ welcome too
    GTK+ Reference Manual -- the API reference proper. Very tough at first!

    Quote Originally Posted by jimtuv View Post
    Then I redid the same window in Glade and it only took 5 min to accomplish the same task.
    Which implies something doesn't it? If you bite the bullet and learn the API, you won't have to depend on glade, and in the end you'll have a better understanding of what you're doing and how you can exploit it. Learning to use complex libraries is tough, yes, you must sometimes spend hours tinkering with new parts to get the hang of them. But most complex programming libraries do not have an "easy out" like glade. Dealing with documentation, frustration, problem solving, these are all skills you can develop. Or, you can take the easy out and learn less, and in the future you'll be avoiding parallel issues because you're intimidated by them. I've spent full time months working with gtk, but in the end it is a very worthwhile pursuit. Gives you a perspective on the nuts and bolts of how a big C application fits together.

    Just an opinion

    * if you were going to learn a language just to do GUI's, I'd skip straight to python or perl, etc.
    Last edited by MK27; 06-20-2010 at 02:01 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #12
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by MK27 View Post
    There are fewer pure C GUI libraries than C++ ones, but I would not bother to learn C++ just to do GUI's.* I've done tons of stuff in C with gtk, including stuff now distributed by debian. WinAPI is vanilla C too, I believe. Most of the linux desktop is C/gtk -- it ain't C++, this is a lot of whining. WRT to gtk, the results are the same, just the C++ libs (gtkmm) use 200-300% more memory (but your codebase will be smaller).



    Glade is like a scripting tool for use with Gtk. Skip it. You might as well just focus your energy on Gtk itself:

    GTK+ 2.0 Tutorial -- what I started from
    GTK+ Programming -- very helpful forum, mostly C but C++ welcome too
    GTK+ Reference Manual -- the API reference proper. Very tough at first!



    Which implies something doesn't it? If you bite the bullet and learn the API, you won't have to depend on glade, and in the end you'll have a better understanding of what you're doing and how you can exploit it.

    * if you were going to learn a language just to do GUI's, I'd skip straight to python or perl, etc.
    Actually in the interest of accuracy, the "linux desktop" is a misnomer; it would be fairer to say the GNOME desktop is C/GTK; KDE and others are all C++ oriented and that is not whining, just the truth. As for Glade, it is a design tool but there is nothing wrong with a design tool. Like any other, it is meant to be used as a part of the overall process but it will not do the whole thing for you. It does give you an advantage in speed if you are working out a GUI design and want to do numerous "what-if" scenarios quickly whereas having to code them all from scratch just to see what they look like would be a short road to insanity, not to mention a missed deadline. I know you really hate C++ MK but it does have advantages that C does not in certain situations. Is it the right answer every time? Probably not but to discard it as you have done would seem to mean you have fewer tools in your toolbox for getting a job done which leads to the old addage of "if all you have is a hammer, everything looks like a nail"...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  13. #13
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by jeffcobb View Post
    I know you really hate C++ MK but it does have advantages that C does not in certain situations.
    I don't hate C++ Jeff, I think it's great. Mostly. What I hate is the perspective of people who, AFAICT, are "single language dependent" -- they only ever program in C++, so WRT to any non-trivial task the response is "Oh no, I have to use C++ here, any other choice would be silly".

    That's a self-fulfilling prophecy, I'm providing an alternate perspective. Obviously, I would not advise you or Bubba to use C for a GUI. I'll even be honest and say I plan to stick with gtkmm (despite the memory bloat issues)! Actually, I think the best approach to gtk might be to use C++, but write your own class wrappers on the base C lib, which would give you a bit more low level control. That implies you should learn the C API and then C++, not C++ and then the C++ API. That is going to give you the best set of options in the end.

    My main point is it's stupid to recommend another language to someone just for this purpose, especially considering there are lots and lots of great examples of very serious GUI apps written in pure C/gtk. It's not the only option, but it is not at all a bad one.

    Maybe I'm being a little snobbish about glade tho. $0.02. I have seen people do very nice things with it,* but you can't produce stand alone executables that way, which seems like a drag.

    * eg http://code.google.com/p/picksel/
    Last edited by MK27; 06-20-2010 at 02:30 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  14. #14
    Registered User jimtuv's Avatar
    Join Date
    May 2010
    Location
    Sylvania, Ohio
    Posts
    94
    I do definitely understand that Linux has many desktop environments. Gnome, KDE, Xterm and many more even one for kids Sugar. I think If I were to develop apps for KDE I would most likely go either Python or Ruby. I have been playing around with both this last week and Ruby is a blast. It's enjoyable to work with and I have actually started using it for a quick way to test algorithms before coding in C. I know it's probably silly to use one program language to help code another but I find it quite helpful. I like C's speed and it's freedom so I plan on using it mostly.

    I have seen some examples of using Python for the GUI and C for the kernel. Blender is using this method now in their newest release 2.5. This is the program that kicked off my desire to learn to program. I have been using Blender for 2 years now and find it very powerful and capable of anything I need it to do.

    Here is an example of some of my design work in blender.

    James Tuvell

    I like the ideas they have for splitting things up. You can easily add buttons and functions to the GUI by Python scripting. They have a great mix of low level power. (you can use command line arguments to render projects ) and high level User interface that is easy to use.

    As for GTK I will learn to code it without Glade. However I have no trouble in using a tool to speed up development as long as I understand how the tool works and how to code a solution without it. I don't think that is being lazy I think it's being efficient. I have a lot of projects and little time so I hate wasting time on unnecessary work.

  15. #15
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,608
    Obviously, I would not advise you or Bubba to use C for a GUI.
    Hey don't throw me in the 'C++ only' category. I actually suggested the OP use C#. Personally I would never use C or C++ for GUI but I'm being open minded here in the spirit of this forum and the board in saying it is perfectly valid. For me with respect to GUI programming it's C# or nothing. I could, on the rare occasion, use VB but I would never mention that here b/c I would lose a lot of C/C++ nerd points.
    Last edited by VirtualAce; 06-20-2010 at 06:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  2. switch - continue
    By DavidP in forum C Programming
    Replies: 2
    Last Post: 06-24-2004, 10:09 AM
  3. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM
  4. Getting output from console apps
    By PsychoBrat in forum Windows Programming
    Replies: 3
    Last Post: 10-16-2002, 03:16 AM