Thread: Starting a Program, use C or C++?

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

    Starting a Program, use C or C++?

    I am trying to make a circuit drawing program that will be more user friendly that the freewares 1's out there today. I have plenty of ideas on how to go about doing this but not sure whether to use C or C++.

    Also, I can't seem to get resources to work on this program. Got the window and everything to display perfectly but when I start adding files it doesn't seem to work. Got a menu to fianlly appear w/o using resources but I think resources are the way to go with so much stuff on the toolbar. Any ideas on how to get a toolbar to work? Will post what I have done shortly once I can decide C or C++...thx l8er

    -fire

  2. #2
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    Well since C++ is a superset of C and you can use C code IN C++, I'd say go with that. And then if you need a C function in your cpp program, add the appropriate header and voila
    Registered Linux User #380033. Be counted: http://counter.li.org

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    35
    thx for the input . What I am not sure about now is the appropiate header for .c. I have never been able to get a program with headers to work in C++ before. I will try to post my code this afternoon so mayb this won't be that big of an issue..thx again

    -fire

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    35
    I have started the program and am trying to add a menu and and icon. The icon is a pic that I have saved on comp and not 1 that the compiler provides. Here is the source code I have.
    Code:
    #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 Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    
        /* Register the window class, and if it fails 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 */
               "Circuit Doctor",    /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               500,                 /* The programs width */
               300,                 /* 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;
    }
    I have tried to add a resource for the menu and haven't had any luck with it. What would I go about doing first? I think I should create a header file with all the defines and then an .rc file. Should the menu and icon each have diff.resources? Can anyone give an example on how to make file on the menu with this code? thx l8er

    -fire

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    35
    I was experimenting around some more this afternoon and FINALLY got a menu to work !!!
    I didn't set it up as a windows app. project but just copied and pasted a menu off the web. Then, when I set it up as a windows app. project, it gave me an erroe from the private file.
    I didn't mind that since I finally got a menu up. This brought forth 1 question though...

    When making a Win32 program, should I make the project a Windows app or DLL? Thanks again

    -fire

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I'm not sure exactly where you're at. Your first post suggests that you don't know anything at all about C/C++, but you're diving right into Windows API programming. Do you actually understand what any of the code does, or are you just copying and pasting? If you're copy/pasting, I suggest you go over some C/C++ tutorials and learn more of the language itself in a console-based programming environment before trying to deal with a GUI and all - otherwise, you'll almost certainly run into a brick wall in short order and become frustrated.

    To answer your more immediate question though, you want a Windows app since a DLL just creates (surprise!) a .DLL file.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    35
    i have read through alot of C++ tutorials and have only copied and pasted code after it didn't work the first time. I am going to read through more tutorials now since that might help. Is Dev C++ a reliable compiler, for doing big projects? thx l8er

    -fire

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    From what I hear, it should be reliable. The size of the project shouldn't really matter though, other than organization problems - and to a large extent, that doesn't depend on the IDE at all.

    >>I am going to read through more tutorials now since that might help.
    Good philosophy
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    I use Dev-C++ and i like it a lot. especially more then MSVC++ although M$ makes it easier to create and use .DLL's with VB programs (wow..what a surprise :-P) lol at least in my experience. but you say you've read C++ tutorials, what about C tutorials? you should DEFINITELY check those out and study up on C as its the basis for C++, lol.
    Registered Linux User #380033. Be counted: http://counter.li.org

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Yaaaa, no. The syntax is similar, but the program design is different.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  11. #11
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    what do you mean hunter? what are you comparing?
    Registered Linux User #380033. Be counted: http://counter.li.org

  12. #12
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I'm comparing C and C++.

    There are a few compatibility problems between C and C++, which I can't list at the moment (but others here can). They are, of course, insignificant for the most part. There are different ways of doing things in C and C++ though, and if you get too used to the C way then it can take some time to get used to the C++ way.

    Such as abstraction. Templates, inheritance/virtuals, functors, etc. open up an entirely new area to master, and design patterns such as the Singleton aren't easy to reproduce reliably in C. On a more immediate level, switching from malloc to new and delete/delete[], dynamic arrays to vectors, sscanf() to stringstreams, etc. can take some time to get used to. I don't believe C has references either? Those are useful. Being a C++ person, I only know the perks of C++, but there are ways of achieving the same results using C - and the 'best' C way is often very different from the 'best' C++ way. A good C++ coder isn't necessarily a good C coder, and vice versa.

    In any case, good C++ tutorials will teach any important concepts that carry over from C to C++, which is the reason that I originally objected to your suggestion to read up on C tutorials, as it (in my perception) implies that C tutorials will simply teach the 'basics' of C++ in better detail.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #13
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    i didn't mean it would teach anything "better", just teach more. more ways of doing things gives a person more options, and personally i like options. lol but yea - C++ is supposed to be better at doing things / capable of more as its supposed to be "one better" lol i just think being well rounded is good.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting C++;First Program
    By Caliban in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2009, 01:41 PM
  2. Starting a program
    By mcgeady in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2006, 12:52 PM
  3. starting program
    By Ideswa in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2006, 02:36 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM