GTK+: calculator

This is a discussion on GTK+: calculator within the C Programming forums, part of the General Programming Boards category; i am developing a calculator in C using GTK+, this code activates when 3 is pressed i was wondering if ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    7

    GTK+: calculator

    i am developing a calculator in C using GTK+, this code activates when 3 is pressed i was wondering if it is possible to make it generic for all of my number buttons. So as the line gchar str2[] = "3"; could read whatever button was pressed in stead of just "3". I have a feeling it has something to do with accessing the label using info from the following line, could some please help me out
    Code:
     BTN_3 = gtk_button_new_with_mnemonic (_("3"));
    Code:
    void
    on_BTN_3_clicked                       (GtkButton       *button,
                                            gpointer         user_data)
    {
    	GtkWidget *resultfld;
    	gchar str2[] = "3";
    	resultfld = GTK_ENTRY(lookup_widge(button, "entry1"));
    	strcat(str, str2);
    	gtk_entry_set_text(resultfld, str);
    
    }

  2. #2
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Create one callback function, connect that to the every numeric button,
    while installing callback func to the button, use last parameter for passing
    string, integer or whatever you want to the callback function. (user_data).
    ....you can also set any data (gpointer) to the button using g_object_set_data, and get it whenever you need it.
    or maybe you wanna read label from button to get button numeric string representation.
    And again replace that strcat ...

    http://www-106.ibm.com/developerwork...ry/l-glib.html
    http://developer.gnome.org/doc/API/2.0/glib/
    http://developer.gnome.org/doc/API/2...Functions.html
    -- Add Your Signature Here --

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    7
    thanks that helped me out alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 03:39 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 09:48 AM
  4. Java Calculator
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-12-2002, 07:39 PM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21