home *** CD-ROM | disk | FTP | other *** search
/ Beginning C++ Through Gam…rogramming (2nd Edition) / BCGP2E.ISO / bloodshed / devcpp-4.9.9.2_setup.exe / Templates / WinApp_c.txt < prev   
Text File  |  2003-02-12  |  4KB  |  88 lines

  1. #include <windows.h>
  2.  
  3. /*  Declare Windows procedure  */
  4. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  5.  
  6. /*  Make the class name into a global variable  */
  7. char szClassName[ ] = "WindowsApp";
  8.  
  9. int WINAPI WinMain (HINSTANCE hThisInstance,
  10.                     HINSTANCE hPrevInstance,
  11.                     LPSTR lpszArgument,
  12.                     int nFunsterStil)
  13.  
  14. {
  15.     HWND hwnd;               /* This is the handle for our window */
  16.     MSG messages;            /* Here messages to the application are saved */
  17.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  18.  
  19.     /* The Window structure */
  20.     wincl.hInstance = hThisInstance;
  21.     wincl.lpszClassName = szClassName;
  22.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  23.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  24.     wincl.cbSize = sizeof (WNDCLASSEX);
  25.  
  26.     /* Use default icon and mouse-pointer */
  27.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  28.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  29.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  30.     wincl.lpszMenuName = NULL;                 /* No menu */
  31.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  32.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  33.     /* Use Windows's default color as the background of the window */
  34.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  35.  
  36.     /* Register the window class, and if it fails quit the program */
  37.     if (!RegisterClassEx (&wincl))
  38.         return 0;
  39.  
  40.     /* The class is registered, let's create the program*/
  41.     hwnd = CreateWindowEx (
  42.            0,                   /* Extended possibilites for variation */
  43.            szClassName,         /* Classname */
  44.            "Windows App",       /* Title Text */
  45.            WS_OVERLAPPEDWINDOW, /* default window */
  46.            CW_USEDEFAULT,       /* Windows decides the position */
  47.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  48.            544,                 /* The programs width */
  49.            375,                 /* and height in pixels */
  50.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  51.            NULL,                /* No menu */
  52.            hThisInstance,       /* Program Instance handler */
  53.            NULL                 /* No Window Creation data */
  54.            );
  55.  
  56.     /* Make the window visible on the screen */
  57.     ShowWindow (hwnd, nFunsterStil);
  58.  
  59.     /* Run the message loop. It will run until GetMessage() returns 0 */
  60.     while (GetMessage (&messages, NULL, 0, 0))
  61.     {
  62.         /* Translate virtual-key messages into character messages */
  63.         TranslateMessage(&messages);
  64.         /* Send message to WindowProcedure */
  65.         DispatchMessage(&messages);
  66.     }
  67.  
  68.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  69.     return messages.wParam;
  70. }
  71.  
  72.  
  73. /*  This function is called by the Windows function DispatchMessage()  */
  74.  
  75. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  76. {
  77.     switch (message)                  /* handle the messages */
  78.     {
  79.         case WM_DESTROY:
  80.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  81.             break;
  82.         default:                      /* for messages that we don't deal with */
  83.             return DefWindowProc (hwnd, message, wParam, lParam);
  84.     }
  85.  
  86.     return 0;
  87. }
  88.