Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. where's main() ???

where's main() ???

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicstutorialquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave Sweetser
    wrote on last edited by
    #1

    Having just finished up a C++ programming class, I'm making the move to MFC and Windows programming. I expected to find something (at least roughly) equivalent to the main() routine found in console apps. After looking through numerous books, I still don't know where my application code goes. I know how to do initialization (e.g. the OnDraw function) but I don't know where I would put some code to make GDI calls. I don't want to respond to messages (at least yet), I just want to make some GDI calls in my main program. Does someone know where the equivalent of main() is for MFC programs? Thanks. BTW, I'm not using AppWizard. Dave

    R 1 Reply Last reply
    0
    • D Dave Sweetser

      Having just finished up a C++ programming class, I'm making the move to MFC and Windows programming. I expected to find something (at least roughly) equivalent to the main() routine found in console apps. After looking through numerous books, I still don't know where my application code goes. I know how to do initialization (e.g. the OnDraw function) but I don't know where I would put some code to make GDI calls. I don't want to respond to messages (at least yet), I just want to make some GDI calls in my main program. Does someone know where the equivalent of main() is for MFC programs? Thanks. BTW, I'm not using AppWizard. Dave

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      If you're using Win32 calls (instead of MFC), your Windows main() entry point is WinMain(). If you're using MFC, AppWizard will generate the application instance for you. The framework calls methods in your application, allowing you to implement/customize the app's startup. The real main() function is buried in the Windows startup stub that gets linked into your app. >  BTW, I'm not using AppWizard. Aieee! I would strongly advise using the AppWizard. :eek: /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

      D 1 Reply Last reply
      0
      • R Ravi Bhavnani

        If you're using Win32 calls (instead of MFC), your Windows main() entry point is WinMain(). If you're using MFC, AppWizard will generate the application instance for you. The framework calls methods in your application, allowing you to implement/customize the app's startup. The real main() function is buried in the Windows startup stub that gets linked into your app. >  BTW, I'm not using AppWizard. Aieee! I would strongly advise using the AppWizard. :eek: /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

        D Offline
        D Offline
        Dave Sweetser
        wrote on last edited by
        #3

        Ravi, Thanks for your input. Sounds like I should use AppWizard. So I will. But I still don't know where my application code goes. What are the "application instances"? What is the Windows startup stub? Can you help me with the names of the classes that I should be looking at? Are there some methods where I would insert my application code? Thanks again. Dave Dave

        R 1 Reply Last reply
        0
        • D Dave Sweetser

          Ravi, Thanks for your input. Sounds like I should use AppWizard. So I will. But I still don't know where my application code goes. What are the "application instances"? What is the Windows startup stub? Can you help me with the names of the classes that I should be looking at? Are there some methods where I would insert my application code? Thanks again. Dave Dave

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          The class you want to look at is the one AppWizard derives from CWinApp, specifically the InitInstance() method. AppWizard peppers its generated code with comments which are reasonable helpful and will help you learn more about MFC's application framework. I also suggest you look at some books on MFC/Windows programming to help you get started. I think you'll find the ones by Charles Petzold and Jeff Prosise to be a great read. You can likely buy them used for very little on EBay or Amazon. And continue to post your Windows questions at CP! /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

          D 1 Reply Last reply
          0
          • R Ravi Bhavnani

            The class you want to look at is the one AppWizard derives from CWinApp, specifically the InitInstance() method. AppWizard peppers its generated code with comments which are reasonable helpful and will help you learn more about MFC's application framework. I also suggest you look at some books on MFC/Windows programming to help you get started. I think you'll find the ones by Charles Petzold and Jeff Prosise to be a great read. You can likely buy them used for very little on EBay or Amazon. And continue to post your Windows questions at CP! /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

            D Offline
            D Offline
            Dave Sweetser
            wrote on last edited by
            #5

            Ravi, I have 4 books on Visual C++ 6.0 and/or MFC programming but not the ones you mention, which I'll pursue getting. I used AppWizard to create my program and looked at InitInstance() and it seems to be only for initialization. The comment in the code says "Standard initialization". So, I still don't know where my application code goes. As noted above, I'll pursue getting the books but is it possible, in the meantime, to let me know where my "regular application code" goes -- not the initialization code but the code that will run after initialization? My "regular application code" will display graphics on an ongoing and continuous basis, I just don't know where to put it. Can you let me know? Thanks.

            R 1 Reply Last reply
            0
            • D Dave Sweetser

              Ravi, I have 4 books on Visual C++ 6.0 and/or MFC programming but not the ones you mention, which I'll pursue getting. I used AppWizard to create my program and looked at InitInstance() and it seems to be only for initialization. The comment in the code says "Standard initialization". So, I still don't know where my application code goes. As noted above, I'll pursue getting the books but is it possible, in the meantime, to let me know where my "regular application code" goes -- not the initialization code but the code that will run after initialization? My "regular application code" will display graphics on an ongoing and continuous basis, I just don't know where to put it. Can you let me know? Thanks.

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #6

              A Windows app that exposes a user interface requires a main window, and optionally various child windows depending on the type of interface (dialog, SD, MDI, etc.). For your purpose, it seems that a dialog based app will suffice. The graphics will be displayed within the dialog box. When you run AppWizard (to create an MFC Windows Application), select "Dialog Based" at the appropriate step. When you build and run your app, a "main dialog window" will be displayed. If you click Esc (or the little x a the top right corner), the dialog will exit, control will eventually return to your CWinApp derived class, and your app will exit. The actual displaying of graphics will likely occur within a custom control (chart, graph, whatever) you may choose to implement. This control will reside within the dialog. You can create a timer to update the control every "n" units of time. You may also want to add buttons and other widgets on the dialog to allow the user to control the app. Hope this sheds some more light on "the big picture". /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

              D 1 Reply Last reply
              0
              • R Ravi Bhavnani

                A Windows app that exposes a user interface requires a main window, and optionally various child windows depending on the type of interface (dialog, SD, MDI, etc.). For your purpose, it seems that a dialog based app will suffice. The graphics will be displayed within the dialog box. When you run AppWizard (to create an MFC Windows Application), select "Dialog Based" at the appropriate step. When you build and run your app, a "main dialog window" will be displayed. If you click Esc (or the little x a the top right corner), the dialog will exit, control will eventually return to your CWinApp derived class, and your app will exit. The actual displaying of graphics will likely occur within a custom control (chart, graph, whatever) you may choose to implement. This control will reside within the dialog. You can create a timer to update the control every "n" units of time. You may also want to add buttons and other widgets on the dialog to allow the user to control the app. Hope this sheds some more light on "the big picture". /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

                D Offline
                D Offline
                Dave Sweetser
                wrote on last edited by
                #7

                Ravi, Thanks for the further tip. I used AppWizard to create a dialog application. So, now, I have the same question: Where does my application code go? You mention that the displaying of graphics will occur within a "custom control". I don't know that this is -- I think what I'm looking for is a function (method) that gets called to run my code. My goal (for now) is to draw a circle in the dialog window. I want to do this is my main code section, *not* in the initialization InitInstance() method. Can you let me know where I would put this circle code? I presume that my application code goes in a well-defined and well-known location in the dialog window code, I'm just trying to find out what this location is. Can you let me know? Thanks again, sorry for not "getting it" quicker.

                J R 2 Replies Last reply
                0
                • D Dave Sweetser

                  Ravi, Thanks for the further tip. I used AppWizard to create a dialog application. So, now, I have the same question: Where does my application code go? You mention that the displaying of graphics will occur within a "custom control". I don't know that this is -- I think what I'm looking for is a function (method) that gets called to run my code. My goal (for now) is to draw a circle in the dialog window. I want to do this is my main code section, *not* in the initialization InitInstance() method. Can you let me know where I would put this circle code? I presume that my application code goes in a well-defined and well-known location in the dialog window code, I'm just trying to find out what this location is. Can you let me know? Thanks again, sorry for not "getting it" quicker.

                  J Offline
                  J Offline
                  Johnny
                  wrote on last edited by
                  #8

                  For a GUI application you need to think in terms of what you do to react to user input, not the classical main approach. As such, do not think of your dialog application as having a main code section - your application responds to messages from the Windows message system, and it is within the handlers for these messages that your application code is distributed as appropriate. In the case of drawing a circle in the window, then you would put that code within the handler for the WM_PAINT message, for example, which is called whenever the window needs to be redrawn. If you bring up the ClassWizard then it allows you to define a whole host of these functions to respond to most things. To stress, dont think of it in terms of having a main code section - Windows handles all that, you just respond to its messages.

                  1 Reply Last reply
                  0
                  • D Dave Sweetser

                    Ravi, Thanks for the further tip. I used AppWizard to create a dialog application. So, now, I have the same question: Where does my application code go? You mention that the displaying of graphics will occur within a "custom control". I don't know that this is -- I think what I'm looking for is a function (method) that gets called to run my code. My goal (for now) is to draw a circle in the dialog window. I want to do this is my main code section, *not* in the initialization InitInstance() method. Can you let me know where I would put this circle code? I presume that my application code goes in a well-defined and well-known location in the dialog window code, I'm just trying to find out what this location is. Can you let me know? Thanks again, sorry for not "getting it" quicker.

                    R Offline
                    R Offline
                    Ravi Bhavnani
                    wrote on last edited by
                    #9

                    Johnny is exactly right. Windows (like any event driven GUI) requires your application to respond to events. Windows notifies your application when an event occurs by sending messages to its windows. Each message is identified by a WM_something constant. Examples of messages are:

                    • WM_SIZE the user has just resized the dialog
                    • WM_MOVE the user has moved the dialog
                    • WM_QUERYENDSESSION Windows is shutting down and would like to terminate your application
                    • WM_PAINT the user has moved a window, causing (part of) your window to need to be redrawn

                    MFC conveniently provides predefined methods (that you can override) to customize your response to these messages. The one you probably want to handle is the last one. The handler for this message is OnPaint(). My gut tells me you might be better off doing some reading before venturing into building your app. Once you get a better handle (pun intended) on MFC, you can decide where to inject your application's drawing code and perhaps add more bells and whistles to your app. Good luck! /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups