Results 1 to 4 of 4
  1. #1
    Credzis's Avatar
    Join Date
    May 2007
    Gender
    male
    Posts
    180
    Reputation
    11
    Thanks
    555
    My Mood
    Stressed

    Cool Starting in C++/OpenGL 2

    WinMain() and the Windows Procedure

    Every Windows programming needs a main entry point. That being said, you may be wondering what this entry point is. The main entry point for any Windows program is called WinMain. The function prototype for WinMain is a little confusing at first, but as we continue to work with it you'll notice it becomes much easier to understand. Well. we've told you what it is; now were going to show you! Here's the prototype for WinMain:
    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
    As you may have already noticed, the return type for WinMain is, and always will be, int. All 32-bit Windows operating system uses the calling convention WINAPI. This calling convention MUST be used to distinguish the function as the entry point. Now for the parameters. As you can see, WinMain uses four parameters when the program starts. Lets have a look at them, shall we?
    Code:
    hInstance - is a handle to your applications instance, where an instance 
    can be considered to be a single run of your application. The instance 
    is used by windows as a reference to your application for event handling,
    message processing, and various other duties.
    hPrevInstance - is always NULL. 
    lpCmdLine - is a pointer string that is used to hold any command-line
    arguments that may have been specified when the application began.  
    For example, if the user opened the Run application and typed myapp.exe
    myparameter 1, then lpCmdLine would be myparameter 1.
    nShowCMD - is the parameter that determines how your application's window
    will be displayed once it begins executing.
    Pretty simple, right? Don't worry if it's confusing, it will make sense soon enough! The Windows program you create is going to need some way to handle the messages that Windows will send to it. A few examples of these messages are: WM_CREATE, WM_SIZE, and WM_MOVE. There are TONS of these messages, and we'll show you how to handle a large number of them. To allow Windows to communicate with your application, we'll create a dandy little function called a Windows procedure. This most common name for this function is WndProc. This function MUST be created and used to determine how your application will respond to various events. The Windows procedure may also be called the event handler because, well, it responds to Windows events! So lets have a quick look at the prototype:
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    This function is declared with a return type of LRESULT CALLBACK. The LRESULT type is used by Windows to declare a long integer, and CALLBACK is a calling convention used with functions that are called by Windows. The Windows Procedure is a function pointer, which allows you to call it whatever you want because the function's address will be assigned as a function pointer upon creation of the window class.
    Code:
    hwnd - Only important if you have several windows of the same class open
    at one time. This is used to determine which window hwnd pointed to before 
    deciding on an action.
    message - The actual message identifier that WndProc will be handling.
    wParam and lParam - Extensions of the message parameter. Used to give 
    more information and point to specifics that message cannot on its own.

    More comming soon

    It's more tutorial so please just read, if u dont understand wait for my next topics, if u still dont understand it, then u can ask a question

  2. #2
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    =/ This isn't an openGL tutorial. Its an introduction to extreamly basic Win32 API programming.



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  3. #3
    pbsucks's Avatar
    Join Date
    Sep 2007
    Location
    univers
    Posts
    65
    Reputation
    10
    Thanks
    4
    Come on, that's nothing...

    Look here:

    Winmain tutorials

  4. #4
    Threadstarter
    Advanced Member
    Credzis's Avatar
    Join Date
    May 2007
    Gender
    male
    Posts
    180
    Reputation
    11
    Thanks
    555
    My Mood
    Stressed
    Read my first thread -_-