Thread: Graphical interface in C ?

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    3

    Graphical interface in C ?

    Hi all. My question is simple : Is there any way to build a graphical interface in C ? (which would look better than the black DOS window). Thanks.

  2. #2
    Sayeh
    Guest
    If you have any graphics capability at all (BGI, or some other engine), why not write your own? All you need is the ability to draw circles, squares, and fills.

    Then, write the following individual managers--

    File Manager
    Window Manager
    Control Manager
    Menu Manager
    Drawing Manager
    Event Manager

    Later, add the following

    Memory Manager
    Communications Manager
    Device Manager
    List Manager

    etcetera.


    ---

    File manager's easy-- it just interfaces to existing O/S file routines, but perhaps has additionals that get around limitations of the O/S (depending on your O/S).

    Windows manager is easy. Really, it is just a manager that manages a linked-list of structures containing information about each window.

    Control Manager is very similar to the window manager, except it is a linked list of controls (defined by structures) that hang off each window structure.

    Menu Manager is very similar to a specialized control manager.

    Drawing Manager-- this can either call routines in BGI, or some other toolbox, OR you could write your own drawing engine. If you can plot a single dot on the screen, you can write a drawing engine.

    Event Manager-- once everything else is down, you can then write an event manager that scans the devices-- keyboard mouse, drive, etc. and creates a circular linked list of 'events' that are parcelled out to your program.

    If you want to have more than one application at a time run and use your GUI, then you need a

    Process Manager

    That creates a world for each application to run in (alas, yet _another_ linked list of structures)...

    Once that is all done, you can provide header files and linkable binaries (libraries) to people who want to write applications using your GUI.

    Voila!-- You are now MICROSOFT or APPLE...

    enjoy.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    10

    Thumbs up Re: Graphical interface in C ?

    Originally posted by Golgot
    Hi all. My question is simple : Is there any way to build a graphical interface in C ? (which would look better than the black DOS window). Thanks.
    If you are programming under windows you can use MFC or ms win API.
    If you are programming under dos you can use TVision
    If you are programinf under UNIX (xwindows) you can use QT (www.trolltech.com), GTK+ (www.gtk.org), Motif...
    If you are programming under unix (console mod) you can use curses/ncurses

    NOTE: qt and gtk+ are ported to windows platform, so you can use them under windows, too.
    #cd pub
    #more beer

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    Thanks for all, i will better try to use win api or some program like this because i do not have the time to make my own !

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    10
    Originally posted by Golgot
    Thanks for all, i will better try to use win api or some program like this because i do not have the time to make my own !
    Win API is not program, it is api (Aplication Programming Interface) or something like that.

    I think that its better for you to you to use qt/gtk/mfc/borlands CLX/ because making graphical interface using win API is hard.
    #cd pub
    #more beer

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    There is what i get whit the dev-c++ environment that i use (by choosing "windows application project" as a new C project). It seems to be Win api.
    Where can i find some tutorials on how to make simple buttons and field... ? :

    ------------------------------------------------------------------------------------
    #include <windows.h>

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
    int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

    {
    HWND hwnd; /* This is the handle for our window */
    MSG messages; /* Here messages to the application are saved */
    WNDCLASSEX wincl; /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
    wincl.style = CS_DBLCLKS; /* Catch double-clicks */
    wincl.cbSize = sizeof(WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL; /* No menu */
    wincl.cbClsExtra = 0; /* No extra bytes after the window class */
    wincl.cbWndExtra = 0; /* structure or the window instance */
    /* Use light-gray as the background of the window */
    wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);

    /* Register the window class, if fail quit the program */
    if(!RegisterClassEx(&wincl)) return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx(
    0, /* Extended possibilites for variation */
    szClassName, /* Classname */
    "Windows App", /* Title Text */
    WS_OVERLAPPEDWINDOW, /* default window */
    CW_USEDEFAULT, /* Windows decides the position */
    CW_USEDEFAULT, /* where the window ends up on the screen */
    544, /* The programs width */
    375, /* and height in pixels */
    HWND_DESKTOP, /* The window is a child-window to desktop */
    NULL, /* No menu */
    hThisInstance, /* Program Instance handler */
    NULL /* No Window Creation data */
    );

    /* Make the window visible on the screen */
    ShowWindow(hwnd, nFunsterStil);
    /* Run the message loop. It will run until GetMessage( ) returns 0 */
    while(GetMessage(&messages, NULL, 0, 0))
    {
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
    return messages.wParam;
    }

    /* This function is called by the Windows function DispatchMessage( ) */
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message) /* handle the messages */
    {
    case WM_DESTROY:
    PostQuitMessage(0); /* send a WM_QUIT to the message queue */
    break;
    default: /* for messages that we don't deal with */
    return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
    }
    ------------------------------------------------------------------------------------

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xuni: a Graphical User Interface Widget Toolkit
    By dwks in forum Projects and Job Recruitment
    Replies: 45
    Last Post: 06-04-2008, 02:35 PM
  2. Graphical user interface not look like windows
    By xkrja in forum Windows Programming
    Replies: 8
    Last Post: 11-04-2006, 06:46 PM
  3. Graphical Interface in C
    By dead-eternity in forum C Programming
    Replies: 7
    Last Post: 03-10-2005, 04:10 PM
  4. Developing graphical interface applications in c
    By deepasurana in forum C Programming
    Replies: 1
    Last Post: 07-25-2002, 03:22 AM
  5. Mandrake + Graphical Interface
    By MethodMan in forum Linux Programming
    Replies: 3
    Last Post: 06-03-2002, 01:42 AM