home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / cecko / install / devcpp4920.exe / Templates / WinApp_cpp.txt < prev   
Encoding:
Text File  |  2002-03-14  |  3.4 KB  |  77 lines

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