Cheating Network
 
 

Go Back   Cheating Network > General Computing > Programming > Tutorials / Releases
Reload this Page [C/++] How to make a GUI



Tutorials / Releases

This is a discussion about [C/++] How to make a GUI within the Tutorials / Releases section, where you will Any tutorials or releases should be posted here.



Reply
 
LinkBack Thread Tools Display Modes
Old 04-09-2008, 05:02 AM   #1 (permalink)
CN Owner
 
Chewy's Avatar
 
Join Date: Dec 2007
Location: The deep end of CN
Posts: 2,512
Reputation: 61
Chewy will become famous soon enough
Send a message via AIM to Chewy
Default [C/++] How to make a GUI

There are many API's for making GUI applications.
Here are some.

1. WinAPI: (C based)(MFC is C++ based)
Its a great API and the best solution if you are windows programmer. First code will look a bit difficult, but later (after making few apps.) you will see its not so rusty. I like it, because you can do almost everything with it (in windows). The only bad thing is, that you cannot make applications for Linux with it.
Tutorial:
http://www.winprog.org/tutorial/index.html
2. Qt4 / Qt3 (C++ based)
This is a nice API, for making GUI applications. It works under Linux, Windows and Mac OS X. Its really easy to learn and use. But, until you dont buy licenced version, you will need to add tons of -dll s, to run your application. Qt compiler doesnt work in Vista. And, Qt4 API has a bit complicated way, to get buttons to work, if button holds some more complicated operations(actually you have to make your own SLOT's).
Tutorial:
http://sector.ynet.sk/qt4-tutorial/
http://doc.trolltech.com/4.2/examples.html
3.GTK+ (C based)
Sorry, but I never tryed it, so Google might help you.
Tutorial:
http://www.gtk.org/tutorial/


Some examples:

WinAPI
Simple message box:

Code:
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow)
{
    MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
    return 0;
}
Simple window:

Code:
#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "The title of my window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}
QT4
Simple Message Box:


Code:
#include <QApplication>
 #include <QPushButton>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QPushButto *hello = new QPushButton("This is a simple button");
     hello.resize(100, 30);

     hello.show();
     return app.exec();
 }
Note: Use MsgBox for making message boxes


Simple Window:

Code:
#include <QApplication>
 #include <QLabel>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QLabel *hello = new QLabel("This is a simple window");
     hello.resize(100, 30);

     hello.show();
     return app.exec();
 }
GTK+

Simple window:

Code:
#include <gtk/gtk.h>

/* This is a callback function. The data arguments are ignored
 * in this example. More on callbacks below. */
static void hello( GtkWidget *widget,
                   gpointer   data )
{
    g_print ("Hello World\n");
}

static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    /* If you return FALSE in the "delete_event" signal handler,
     * GTK will emit the "destroy" signal. Returning TRUE means
     * you don't want the window to be destroyed.
     * This is useful for popping up 'are you sure you want to quit?'
     * type dialogs. */

    g_print ("delete event occurred\n");

    /* Change TRUE to FALSE and the main window will be destroyed with
     * a "delete_event". */

    return TRUE;
}

/* Another callback */
static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{
    /* GtkWidget is the storage type for widgets */
    GtkWidget *window;
    GtkWidget *button;
    
    /* This is called in all GTK applications. Arguments are parsed
     * from the command line and are returned to the application. */
    gtk_init (&argc, &argv);
    
    /* create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
    /* When the window is given the "delete_event" signal (this is given
     * by the window manager, usually by the "close" option, or on the
     * titlebar), we ask it to call the delete_event () function
     * as defined above. The data passed to the callback
     * function is NULL and is ignored in the callback function. */
    g_signal_connect (G_OBJECT (window), "delete_event",
              G_CALLBACK (delete_event), NULL);
    
    /* Here we connect the "destroy" event to a signal handler.  
     * This event occurs when we call gtk_widget_destroy() on the window,
     * or if we return FALSE in the "delete_event" callback. */
    g_signal_connect (G_OBJECT (window), "destroy",
              G_CALLBACK (destroy), NULL);
    
    /* Sets the border width of the window. */
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
    /* Creates a new button with the label "Hello World". */
    button = gtk_button_new_with_label ("Hello World");
    
    /* When the button receives the "clicked" signal, it will call the
     * function hello() passing it NULL as its argument.  The hello()
     * function is defined above. */
    g_signal_connect (G_OBJECT (button), "clicked",
              G_CALLBACK (hello), NULL);
    
    /* This will cause the window to be destroyed by calling
     * gtk_widget_destroy(window) when "clicked".  Again, the destroy
     * signal could come from here, or the window manager. */
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
                  G_CALLBACK (gtk_widget_destroy),
                              G_OBJECT (window));
    
    /* This packs the button into the window (a gtk container). */
    gtk_container_add (GTK_CONTAINER (window), button);
    
    /* The final step is to display this newly created widget. */
    gtk_widget_show (button);
    
    /* and the window */
    gtk_widget_show (window);
    
    /* All GTK applications must have a gtk_main(). Control ends here
     * and waits for an event to occur (like a key press or
     * mouse event). */
    gtk_main ();
    
    return 0;
}
__________________
Want to donate to Cheating Network? Click here to do so, or just click the button below!


Chewy is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-09-2008, 05:07 AM   #2 (permalink)
Senior Member
 
Join Date: Dec 2007
Posts: 383
Reputation: 1
emi_mockingbird is an unknown quantity at this point
Default

thanks! thesee stuff will revive CN, hopefully
emi_mockingbird is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-09-2008, 05:11 AM   #3 (permalink)
CN Owner
 
Chewy's Avatar
 
Join Date: Dec 2007
Location: The deep end of CN
Posts: 2,512
Reputation: 61
Chewy will become famous soon enough
Send a message via AIM to Chewy
Default

hopefully lol

im starting to learn so hopefully I can help as well =]

i know a little of everything so
__________________
Want to donate to Cheating Network? Click here to do so, or just click the button below!


Chewy is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-09-2008, 08:42 AM   #4 (permalink)
Senior Member
 
krackhead's Avatar
 
Join Date: Dec 2007
Location: is this heaven?
Posts: 4,622
Reputation: 67
krackhead will become famous soon enough
Send a message via AIM to krackhead Send a message via MSN to krackhead
Default

i will be able to learn everything during the summer hopefully.
__________________
Who says you can't trust a krackhead?
Seller Feedback
Buyer/Trader Feedback
krackhead is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-09-2008, 08:45 AM   #5 (permalink)
CN Owner
 
Chewy's Avatar
 
Join Date: Dec 2007
Location: The deep end of CN
Posts: 2,512
Reputation: 61
Chewy will become famous soon enough
Send a message via AIM to Chewy
Default

i can learn all this probably by tomorrow night lol

i take C++ next year though
__________________
Want to donate to Cheating Network? Click here to do so, or just click the button below!


Chewy is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
c or, gui, make


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Make $25!!!! SteveJobs Referral For Cash Trades 3 03-21-2008 02:18 PM
How Much Did You Make? Santram General Discussion of Networks/Survey Sites 26 03-03-2008 07:24 PM
[NEW]we can make nuke again!! de77 Club Live 118 02-28-2008 08:33 PM
How to make BIG FIRES!! ImMoRtaL Helpful Guides and FAQ's 17 02-04-2008 08:36 PM


Powered by vBulletin
Copyright © 2000-2008 Jelsoft Enterprises Limited.
Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.