Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2010
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.34 KB | None | 0 0
  1. //////////////////////////////////////////
  2. //                                      //
  3. // SIMPLEST WINDOWS PROGRAM             //
  4. //                                      //
  5. // You found this at bobobobo's weblog, //
  6. // http://bobobobo.wordpress.com        //
  7. //                                      //
  8. // Creation date:  Jan 31/08            //
  9. // Last modified:  Feb 9/08             //
  10. //                                      //
  11. //////////////////////////////////////////
  12.  
  13. #include <windows.h>
  14.  
  15. // Function prototypes.
  16. LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
  17. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow );
  18.  
  19. ////////////////////////////
  20. // Introduction:
  21. // Basic Windows Program!
  22. //
  23. // This package demonstrates how to build a very basic Windows application
  24. // on a Win O/S system from Windows 3.1 to Windows XP using C++ code.
  25. //
  26. // * Prerequisites to understanding this program:
  27. //     - Already understand how to create Console applications in C++.
  28. //     - Full understanding of C FUNCTIONS, FUNCTION PARAMETERS/ARGUMENTS.
  29. //
  30. // If you don't know what those are, go learn what
  31. // they are before going on reading this!
  32. //
  33.  
  34. ///////////////////
  35. // OVERVIEW:
  36. // Windows applications in C++ are easy!
  37. // To understand them, you must first see the big
  38. // picture.  Then you can get your hands dirty
  39. // and get right into the code.
  40.  
  41. ///////////////////
  42. // Big picture.
  43. //
  44. // Windows apps are much different than console apps.
  45. // A console app, (which you probably are used to)
  46. // has just a single "main" function called main().
  47.  
  48. // Every Windows app has __2__ functions that are very
  49. // important to it.
  50.  
  51. // These 2 functions are WinMain and WndProc.  WinMain
  52. // and WndProc really form the Windows' app's heart and soul.
  53. //
  54. //    A.  WinMain:  Application STARTING POINT.  REPLACES
  55. //                  main() function that you might be used to
  56. //                  from regular C/C++ programs.
  57. //
  58. //    B.  WndProc:  A function that PROCESSES MESSAGES from
  59. //                  the Windows O/S as they come in.
  60. //
  61.  
  62. ///////////////////
  63. // BUT what's a MESSAGE???
  64. //
  65. // The idea of "messages" takes some getting used
  66. // to, but it is really a simple concept.
  67. //
  68. // The Windows Operating system is like a GOVERNMENT.
  69. //
  70. // All of the little windows that live inside
  71. // (the Firefox window, the MSWord window,
  72. // and YOUR PROGRAM's window!) are people owned
  73. // by the Windows GOVERNMENT.
  74. //
  75. // So, whenever the user attempts to interact
  76. // with ANY program window inside that Windows Government,
  77. // either by clicking on your window, or by pressing a key
  78. // while your program has the "input focus" (when
  79. // your window is "selected"),
  80. // the Windows O/S INTERCEPTS that communication FIRST.
  81. //
  82. // THEN, a fraction of a second later, (almost
  83. // instantly), the Windows O/S SENDS A a "MESSAGE"
  84. // to YOUR Window program that "HEY! THE USER
  85. // CLICKED ON YOU AT LOCATION (22, 405), USING
  86. // THE RIGHT MOUSE BUTTON."  or "HEY!  THE
  87. // USER PRESSED THE 'A' KEY, AND HE WAS ALSO HOLDING
  88. // DOWN SHIFT WHILE HE PRESSED IT."
  89.  
  90. // THAT is what a MESSAGE is.  Its a notification
  91. // from the Windows O/S that the user has
  92. // done something to your program's window.
  93.  
  94. // ONCE your program receives this
  95. // "MESSAGE", your program can THEN execute some code
  96. // in response to that particular MESSAGE.
  97.  
  98. // The WndProc function will contain ALL of
  99. // your "MESSAGE HANDLING CODE" -- that is,
  100. // the code pieces that you want executed
  101. // when certain window events happen.
  102.  
  103. // This is called EVENT DRIVEN PROGRAMMING.
  104. // And in most standard Windows applications, this is
  105. // how things happen.
  106.  
  107. // Most of a basic, standard Windows application's
  108. // time is spent WAITING for events.
  109.  
  110. // And that is what a message is!
  111.  
  112. //////////////////////////////
  113. // OF INSTANCES AND HANDLES.
  114. //
  115. // There are 2 concepts you must understand intuitively first
  116. // before diving into Windows programming.
  117.  
  118. // Those concepts are the concept of an INSTANCE,
  119. // and the concept of a HANDLE.
  120.  
  121. ///////////////
  122. // INSTANCES:
  123. // The first concept is the concept of an INSTANCE of a program.
  124.  
  125. // What's an INSTANCE?
  126.  
  127. // An INSTANCE of an application is just one running OCCURRENCE of it.
  128. // If you open up 3 different NOTEPAD.exe windows, then you have
  129. // created __3__ different, separate INSTANCE of the NOTEPAD program
  130. // inside your Windows Kernel.
  131.  
  132. // If you're familiar with OOP, an easy explanation is this:
  133.     // PROGRAM CODE >> like a C++ class definition.
  134.     // ACTUALLY RUNNING PROGRAM CODE >> like an "instance" of the class, this is an INSTANCE of the program.
  135.  
  136. ///////////////
  137. // HANDLES:
  138. // HANDLES pop up EVERYWHERE in Windows programming (and all other
  139. // types of programming as well!)  So I'm hoping to explain the idea
  140. // behind a HANDLE intuitively, so that you have something to "hold onto"
  141. // whenever you see use of HANDLES in program code.
  142.  
  143. // Think about a POT of boiling water.  Inside that pot is
  144. // some corn on the cob being cooked.
  145.  
  146. // Now, say you want to ACCESS the pot, so you can dump its
  147. // contents out into the sink and drain the corn.
  148.  
  149. // How do you do that?  Do you GRAB THE POT DIRECTLY??? NO!!
  150. // That would be stupid.  Instead, you grab the HANDLE TO THE POT.
  151. // Using the HANDLE to the pot, you manipulate the pot, slowly
  152. // dumping out the water and leaving the corn behind.  Then you
  153. // eat the corn and it is delicious.
  154.  
  155. // Now, in programming, the idea of a HANDLE is much the same.
  156. // A HANDLE to a WINDOW is __NOT__ the window itself in an application
  157. // variable.  Instead, it is a POINTER TO, A REFERENCE TO the
  158. // window itself.
  159.  
  160. // A HANDLE TO AN INSTANCE in an application variable is NOT
  161. // the application INSTANCE itself.  Rather, it is a POINTER TO
  162. // that application instance.  The application instance exists
  163. // somewhere in the Windows O/S's program memory.  You use the
  164. // programmatic HANDLE that you have as YOUR MEANS TO MANIPULATE
  165. // AND DEAL WITH that application instance.
  166.  
  167. // The benefits of HANDLES are many!  You'll see as we go on.
  168. // Onto WinMain()!
  169.  
  170. ////////////////////////////
  171. // In a C++ Windows app, the starting point is WinMain().
  172. int WINAPI WinMain( HINSTANCE hInstance,    // HANDLE TO AN INSTANCE.  This is the "handle" to YOUR PROGRAM ITSELF.  More in the GLOSSARY at the bottom.
  173.                     HINSTANCE hPrevInstance,// USELESS on modern windows (totally ignore hPrevInstance)
  174.                     LPSTR szCmdLine,        // Command line arguments.  Explained near BOTTOM of this file.
  175.                     int iCmdShow )          // Start window maximized, minimized, etc.
  176. {
  177.     // As we said before, WinMain is the application starting point.
  178.  
  179.     // A:  WinMain does 2 main things:
  180.     //    1.  STARTUP STUFF:  CREATE THE WINDOW ITSELF, AND LOAD IT UP
  181.     //        SO IT APPEARS ON THE SCREEN.
  182.     //
  183.     //    2.  KEEP CHECKING WITH WINDOWS O/S TO SEE IF THE USER
  184.     //        HAS INTERACTED WITH THE APPLICATION ("MESSAGE LOOP")
  185.     //        If the user has clicked on anything, or pressed any keys while
  186.     //        our window is ACTIVE (our window has the "input focus")
  187.     //        then we are to DISPATCH a MESSAGE to WndProc (make
  188.     //        a function call to WndProc) that tells
  189.     //        WndProc EXACTLY what the user did to our window (clicked?
  190.     //        key pressed?), when it happened, etc.  WndProc then
  191.     //        has the opportunity to EXECUTE SOME CODE in response
  192.     //        to that particular user interaction.
  193.  
  194.     #pragma region part 1 - STARTUP STUFF
  195.     // A.  Create <a href="http://msdn2.microsoft.com/en-us/library/ms633576(VS.85).aspx">WNDCLASS structure</a> and initialize it
  196.     // The WNDCLASS structure tells Windows WHAT KIND OF
  197.     // WINDOW we dream of creating.
  198.  
  199.     // A note:  Use the TEXT() macro whenever you have a
  200.     // string value that gets passed to a Windows
  201.     // function.  Its good and makes life easier.
  202.     WNDCLASS wc;
  203.     wc.cbClsExtra = 0;  // ignore for now
  204.     wc.cbWndExtra = 0;  // ignore for now
  205.     wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );   // I want the window to have a white background
  206.     wc.hCursor = <a href="http://msdn2.microsoft.com/en-us/library/ms648391(VS.85).aspx">LoadCursor</a>( NULL, IDC_ARROW );            // I want it to have an arrow for a cursor
  207.     wc.hIcon = <a href="http://msdn2.microsoft.com/en-us/library/ms648072.aspx">LoadIcon</a>( NULL, IDI_APPLICATION );        // I want it to have that envelope like icon
  208.     wc.hInstance = hInstance;           // INSTANCE HANDLE -- see the GLOSSARY PART of this file for an explanation of what HINSTANCE is
  209.     wc.lpfnWndProc = WndProc;           // Give name of WndProc function here.
  210.     wc.lpszClassName = TEXT("Philip");  // I have named it Philip.
  211.                                         // You could name it anything
  212.                                         // you want, but you have to
  213.                                         // remember the name for when
  214.                                         // you call CreateWindow().
  215.     wc.lpszMenuName = 0;    // no menu - ignore
  216.     wc.style = CS_HREDRAW | CS_VREDRAW; // Redraw the window
  217.     // on BOTH horizontal resizes (CS_HREDRAW) and
  218.     // vertical resizes (CS_VREDRAW).  There are
  219.     // <a href="http://msdn2.microsoft.com/en-us/library/ms633574(VS.85).aspx#class_styles">many more</a> window class styles!
  220.  
  221.     // B.  Register the WNDCLASS with Windows, THEN
  222.     //     create the window.
  223.     RegisterClass( &amp;wc );   // This kind of "plants" the information
  224.                             // about the Window we "dream"
  225.                             // of creating somewhere inside the Windows O/S...
  226.  
  227.     // NOW, at this next stage, WE ACTUALLY CREATE
  228.     // the window.  The previous lines of code
  229.     // until this point have only been PREPARATION.
  230.  
  231.     // When we call the CreateWindow() function, we will
  232.     // make a reference to this WNDCLASS structure (BY ITS
  233.     // NAME -- "Philip"), and the Windows government
  234.     // will grant us our wish and a REAL LIVE WINDOW,
  235.     // with the properties that we specified in the
  236.     // WNDCLASS structure!
  237.  
  238.     // NOTICE that the value that is returned from
  239.     // CreateWindow is a variable of type HWND.
  240.  
  241.     // HWND is a "handle to a window" - its a programmatic
  242.     // reference variable to the Window.
  243.     // The HWND is OUR MEANS BY WHICH to manipulate
  244.     // our Window.
  245.  
  246.     // Read the schpeal near the top of this file if
  247.     // not sure about HANDLES.
  248.  
  249.     // Most of the time, you would want to save
  250.     // this HWND into a global variable,
  251.     // so you wouldn't lose it later.
  252.     HWND hwnd = <a href="http://msdn2.microsoft.com/en-us/library/ms632679.aspx">CreateWindow</a>(
  253.         TEXT("Philip"),         // THIS IS THE LINK
  254.                                 // to the WNDCLASS structure that
  255.                                 // we created earlier.
  256.  
  257.         TEXT("window's title!"),// appears in title of window
  258.  
  259.         <a href="http://msdn2.microsoft.com/en-us/library/ms632600.aspx">WS_OVERLAPPEDWINDOW</a>,    // STYLE of window.  WS_OVERLAPPEDWINDOW just means
  260.                                 // the window we create should have a few common features
  261.                                 // like a minimize box, a maximize box, and it should
  262.                                 // be resizeable by dragging the "thick frame" around
  263.                                 // the window. There are other styles
  264.                                 // and they all start with WS_.  Check it out in the
  265.                                 // autocomplete by typing WS_ THEN PRESSING CTRL+SPACE
  266.                                 // to make the autocomplete window come up.
  267.         10, 10,                 // x, y start coordinates of window
  268.         200, 200,               // width, height of window
  269.         NULL, NULL,             // nothing and nothing (ignore to start out)
  270.         hInstance, NULL );      // hInstance -- (see glossary), nothing
  271.  
  272.     // Next, SHOW and PAINT the window!
  273.     // You won't see the window if you DO NOT
  274.     // call ShowWindow();
  275.     <a href="http://msdn2.microsoft.com/en-us/library/ms633548(VS.85).aspx">ShowWindow</a>(hwnd, iCmdShow );
  276.     UpdateWindow(hwnd);
  277.     #pragma endregion
  278.  
  279.     #pragma region part 2 - ENTER A LOOP TO CONTINUALLY KEEP CHECKING WITH WIN O/S FOR USER INTERACTION
  280.     // first, we create the MSG structure.
  281.     MSG msg;
  282.     // But WTF IS A MESSAGE???
  283.     // A MESSAGE is something that the Windows O/S
  284.     // SENDS your application program when
  285.     // SOMETHING HAPPENS TO YOUR WINDOW.
  286.  
  287.     // Messages can be anything from "the user
  288.     // has moved your window", to "the user
  289.     // has clicked at pixel location (20, 20)" or,
  290.     // "you need to paint yourself", or,
  291.     // "you have been maximized".
  292.  
  293.     // YOUR CHANCE to handle those "messages"
  294.     // that get passed to your window comes
  295.     // IN WNDPROC.
  296.     while( GetMessage( &amp;msg, NULL, 0, 0 ) )
  297.     {
  298.         // GetMessage is a function that will not
  299.         // return until the Windows O/S HAS A message
  300.         // for our program.
  301.  
  302.         // Since the GetMessage() function call is
  303.         // INSIDE the bracket for the while Loop,
  304.         // this means that our program is essentially
  305.         // "put on hold" or halted until the GetMessage function
  306.         // returns.
  307.  
  308.         // If and when the user interacts with our
  309.         // application's window, then the GetMessage()
  310.         // function WILL return and the variable
  311.         // msg will be filled with interesting details
  312.         // about exactly what the user did to the window.
  313.  
  314.         TranslateMessage( &amp;msg );   // translates
  315.         // the message so WndProc can process it
  316.         // more easily.
  317.  
  318.         // Next we 'dispatch' the message, or
  319.         // send it off to WndProc for processing.
  320.  
  321.         // Notice that there is NO EXPLICIT function
  322.         // call to WndProc, but somehow in the bowels
  323.         // of the Windows O/S, calling DispatchMessage
  324.         // WILL result in a call to your WndProc function,
  325.         // WITH the appropriate msg struct passed in
  326.         // as well.
  327.  
  328.         DispatchMessage( &amp;msg );    // this line RESULTS IN
  329.         // a call to WndProc(), passing the message and
  330.         // the HWND.
  331.  
  332.     }
  333.     #pragma endregion
  334.  
  335.     return msg.wParam;    // return from WinMain
  336. }
  337.  
  338. LRESULT CALLBACK WndProc(   HWND hwnd,      // "handle" to the window that this message is for
  339.                             UINT message,   // TYPE of message (e.g. WM_PAINT is a message asking to paint the window)
  340.                             WPARAM wparam,  // information about the actual message
  341.                             LPARAM lparam ) // MORE info about the message
  342. {
  343.     // If WinMain was the heart of the Windows application, then
  344.     // WndProc is the soul.
  345.  
  346.     // WndProc does just 1 thing:
  347.     //    - Execute some bit of code in response
  348.     //      to user interactions with our windows
  349.     //      application.  
  350.  
  351.     // The tricky bit about WndProc is that NOWHERE IN THIS APP'S
  352.     // CODE DO YOU EVER SEE ANY EXPLICIT FUNCTION CALLS
  353.     // TO WndProc!!!  Does that mean WndProc never
  354.     // gets used???
  355.  
  356.     // NO!!!  Take a look again, around where
  357.     // we create the WNDCLASS.
  358.  
  359.     // Notice, how the WNDCLASS has lpfnWndProc = WndProc??
  360.     // THAT is the reference to this function.
  361.  
  362.     // The WINDOWS O/S PERFORMS the function call to
  363.     // WndProc when we call DispatchMessage().
  364.  
  365.     switch( message )
  366.     {
  367.     case WM_CREATE:
  368.         // upon creation, let the speaker beep at 50Hz, for 10ms.
  369.         Beep( 50, 10 );
  370.         return 0;
  371.         break;
  372.  
  373.     case WM_PAINT:
  374.         {
  375.             // we would place our Windows painting code here.
  376.             HDC hdc;
  377.             PAINTSTRUCT ps;
  378.             hdc = BeginPaint( hwnd, &amp;ps );
  379.  
  380.             // draw a circle and a 2 squares
  381.             Ellipse( hdc, 20, 20, 160, 160 );
  382.             Rectangle( hdc, 50, 50, 90, 90 );
  383.             Rectangle( hdc, 100, 50, 140, 90 );
  384.  
  385.             EndPaint( hwnd, &amp;ps );
  386.         }
  387.         return 0;
  388.         break;
  389.  
  390.     case WM_DESTROY:
  391.         PostQuitMessage( 0 ) ;
  392.         return 0;
  393.         break;
  394.  
  395.     }
  396.  
  397.     // Now, try going into Visual Studio and
  398.     // press WM_ then press CTRL + SPACE.
  399.  
  400.     // Or go to
  401.     // http://msdn2.microsoft.com/en-us/library/ms632595.aspx
  402.  
  403.     // See that huge listing?  Those are ALL THE EVENTS
  404.     // that Windows could possibly throw at our application.
  405.     // WOW!  That's a lot of events.  WE don't want to
  406.     // have to write code for every single one of them!
  407.     // But our WndProc gets called whenever ANY event
  408.     // happens to our application.  What do we do with
  409.     // the events we don't want to handle?
  410.  
  411.     // Simple.  We will pass the events we DON'T want
  412.     // to handle to DefWindowProc().  DefWindowProc()
  413.     // knows what to do with the events we don't want
  414.     // to handle so that our application remains stable
  415.     // and good.
  416.     return DefWindowProc( hwnd, message, wparam, lparam );
  417. }
  418.  
  419. /// GLOSSARY ///
  420. // HINSTANCE:  "Handle" to an instance.  Every running INSTANCE
  421. // of an application has a handle to it that is YOUR MEANS
  422. // by which to manipulate, talk about, or refer to that specific
  423. // application instance as it exists inside the Windows O/S.
  424.  
  425. // What's an instance again?  If you have 2 copies of the same programming running
  426. // at the same time, then you are running 2 INSTANCES
  427. // of the same program (2 copies of Microsoft Word, for example).
  428. // Each INSTANCE of a program has its own INSTANCE HANDLE and
  429. // hence its PID (ProcessID - unique integer identifier
  430. // for each program that is currently running in the Windows O/S)
  431. // and its own entry in the Window task manager.
  432.  
  433. // TRY THIS:  Press CTRL+ALT+DEL to bring up the Windows
  434. // Task Manager.
  435.     // Now switch to the PROCESSES tab.
  436.     // Click the "IMAGE NAME" column, so that everything gets organized by name of the process.
  437.     // Now, open NOTEPAD, 3 times.  You should have 3 Notepad windows open.
  438.     // NOW, LOOK AT the Windows Task Manager.  Try to locate __3__ entries
  439.     // that say NOTEPAD.EXE.  Open a fourth notepad.  Open a fifth notepad.
  440.     // every instance of notepad you open gets its own entry in that table.
  441.  
  442. // Now HINSTANCE is exactly what it sounds like . . its a "handle"
  443. // (a means by which to access or control) the INSTANCE of your
  444. // program.
  445. //
  446. // The actual INSTANCE of your application lives inside the Windows O/S.
  447. // But you have a HANDLE TO IT, and your HANDLE to it is your means
  448. // by which to manipulate it, refer to it, change it, or delete it.
  449.  
  450. // HWND:  HANDLE TO A WINDOW.  This is exactly the same in CONCEPT as
  451. //        the INSTANCE HANDLE, but now, this is a handle TO THE WINDOW ITSELF.
  452. //        The HANDLE TO THE WINDOW is your means by which to change
  453. //        manipulate, or refer to the window that belongs to your program.
  454. //        A single INSTANCE of an application can have MULTIPLE window
  455. //        handles associated with it.  THAT IS WHY when you CREATE A WINDOW,
  456. //        using the CreateWindow() function, you MUST PASS the hInstance
  457. //        parameter.  That is so that Windows knows which application
  458. //        INSTANCE is attached to which WINDOW.
  459. //
  460. // HDC:  HANDLE TO A DEVICE CONTEXT.  Hmm.  I'm not going to explain this
  461. //       in detail here, because we're not really using the HDC much
  462. //       in this example.  Perhaps at a later time.
  463.  
  464. ///////////////////////////
  465. // THERE, ALL DONE - CLOSING NOTES.
  466. // Everyone knows starting Windows Programming can be a bit hard.
  467. // There are a few things I'd like to highlight here.
  468. //
  469. // Now you might be wondering, "ok, if WinMain is the application
  470. // starting point, WHERE / WHEN / HOW does WinMain accept
  471. // PARAMETERS?"
  472. //
  473. // To understand this, you must start to see your "Windows program"
  474. // as really just a FUNCTION that Windows will call, when it is
  475. // time to start up your application.
  476. //
  477. // So where do the values of hInstance, hPrevInstance, szCmdLine
  478. // and iCmdShow come from?
  479. // These parameters are PASSED BY the Windows O/S AT APPLICATION START TIME.
  480. // So all of hInstance, hPrevInstance (which is always passed as NULL)
  481. // szCmdLine and iCmdShow are passed by the Windows O/S
  482. // to your application.
  483.  
  484. ////////////////////
  485. // Understanding what szCmdLine is and does:
  486. //
  487. // Do me a favor.
  488. // Open the Windows command prompt (go to START-&gt;Run,
  489. // then type "cmd" in the box that appears there.)
  490. //
  491. // You should see a black console window, like the one that your basic console C++
  492. // apps run in.  In the black window, type in:
  493. //          explorer
  494. // then press enter.
  495.  
  496. // What should happen is your windows file explorer should pop up.
  497.  
  498. // Now go back to the command prompt and type in
  499. //          explorer "C:\Program Files"
  500.  
  501. // Notice now that the Windows disk explorer now opens in the folder "C:\Program Files"
  502. // In the above example, "C:\Program Files" is a command line argument that modifies
  503. // the behaviour of the disk explorer upon its launch.
  504.  
  505. // So the explorer.exe program is a Windows program.
  506. // And szCmdLine WOULD BE WHERE YOU TAKE that extra string
  507. // that is passed to the program at the time the program is
  508. // launched.
  509.  
  510. // You won't necessarily use this at all in your programming!
  511. // But, it is good to know.
  512.  
  513. // REFERENCES:
  514. // If you want to know more about Windows Programming
  515. // in this CLASSIC C++ way, then you should pick
  516. // up a copy of Charles Petzold's "Programming Windows,
  517. // 5th Edition"
  518. // http://www.charlespetzold.com/pw5/
  519. // On Amazon:  http://www.amazon.com/exec/obidos/ISBN=157231995X
  520.  
  521. // "The Petzold" is THE reference that all the game
  522. // books out there (some of which are pretty good!)
  523. // draw on when they write their Win32 chapter (its
  524. // obvious from the way they've written them!)
  525.  
  526. // What's annoying is, a lot of the people who write
  527. // those books though, never acknowledge Petzold or
  528. // mention where they derived their Win32 understanding
  529. // from.
  530.  
  531. // So, the Petzold is where I got my initial understanding
  532. // anyway, and its really good.  Check it out
  533. // from your library if you haven't the $.
  534.  
  535. // More refs:
  536. // MSDN:  "About messages and message queues"
  537. // http://msdn2.microsoft.com/en-us/library/ms644927(VS.85).aspx
  538.  
  539. ////////////////
  540. // MORE Closing notes:
  541. // This is sometimes called "EVENT DRIVEN
  542. // PROGRAMMING" -- the idea is that your
  543. // program is entirely driven by EVENTS.
  544. // If there are no events, then your
  545. // Windows program DOES NOTHING.
  546.  
  547. // Note that this is NOT the case with GAMES!
  548. // GAMES CAN'T WAIT!  Games must be fast.
  549. // For games, you would use DirectInput,
  550. // and things like that, and you WOULD NOT
  551. // be WAITING for messages.  Instead,
  552. // you want to be DIRECTLY listening
  553. // at the keyboard and mouse for user
  554. // interaction with those DEVICES.
  555.  
  556. ///////////////////
  557. // You MIGHT HAVE been wondering about
  558. // the apparent RETURN TYPE of WinMain and
  559. // WndProc.
  560.  
  561. // Looking at those function prototypes, we have:
  562.  
  563. /*
  564.  
  565. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow );
  566. LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
  567.  
  568. */
  569.  
  570. // For example, a question you might have might be:
  571. // WHY is the return type of WinMain "int WINAPI"?
  572. // That is so weird.
  573.  
  574. // The short answer, is ITS NOT!!
  575.  
  576. // The return type of WinMain is just INT.
  577. // "WINAPI" IS NOT PART OF THE RETURN TYPE
  578. // OF THE WinMain FUNCTION!
  579.  
  580. // The second word after the return type
  581. // (WINAPI) is called the CALLING CONVENTION of
  582. // the function.
  583.  
  584. // In case you're still interested, check out
  585. // these links:
  586. // http://support.microsoft.com/kb/100832
  587. // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_calling_conventions_topics.asp
  588. // http://www.devnewz.com/devnewz-3-20050125UsingWin32CallingConventions.html
  589.  
  590. // A MSDN basic window example:
  591. // http://msdn2.microsoft.com/en-us/library/aa383668(VS.85).aspx
  592.  
  593. // MSDN root page for a lot of windows stuff
  594. // http://msdn2.microsoft.com/en-us/library/ms632586(VS.85).aspx
  595.  
  596. /*
  597.      ____   __   __      __   __  ___
  598.     / _  \ /  / /  /    /  /  \ \/  /
  599.    / _/ / /  / /  /    /  /    \   /
  600.   / _/ \ /  / /  /__  /  /__   /  /
  601.  /_____//__/ /______//______/ /__/
  602.  
  603. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement