home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / cwin / c.exe / $INSTDIR / Examples / Simpwin / Main.c next >
Encoding:
C/C++ Source or Header  |  2003-12-15  |  3.5 KB  |  95 lines

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