Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 31.00 KB | None | 0 0
  1. // Gl_template.c
  2. //Wyłšczanie błędów przed "fopen"
  3. #define  _CRT_SECURE_NO_WARNINGS
  4.  
  5.  
  6.  
  7. // Ładowanie bibliotek:
  8.  
  9. #ifdef _MSC_VER                         // Check if MS Visual C compiler
  10. #  pragma comment(lib, "opengl32.lib")  // Compiler-specific directive to avoid manually configuration
  11. #  pragma comment(lib, "glu32.lib")     // Link libraries
  12. #endif
  13.  
  14.  
  15.  
  16.  
  17. // Ustalanie trybu tekstowego:
  18. #ifdef _MSC_VER        // Check if MS Visual C compiler
  19. #   ifndef _MBCS
  20. #      define _MBCS    // Uses Multi-byte character set
  21. #   endif
  22. #   ifdef _UNICODE     // Not using Unicode character set
  23. #      undef _UNICODE
  24. #   endif
  25. #   ifdef UNICODE
  26. #      undef UNICODE
  27. #   endif
  28. #endif
  29. #include <windows.h>            // Window defines
  30. #include <gl\gl.h>              // OpenGL
  31. #include <gl\glu.h>             // GLU library
  32. #include <math.h>               // Define for sqrt
  33. #include <stdio.h>
  34. #include "resource.h"           // About box resource identifiers.
  35.  
  36. #define glRGB(x, y, z)  glColor3ub((GLubyte)x, (GLubyte)y, (GLubyte)z)
  37. #define BITMAP_ID 0x4D42        // identyfikator formatu BMP
  38. #define GL_PI 3.14159
  39.  
  40. // Color Palette handle
  41. HPALETTE hPalette = NULL;
  42.  
  43. // Application name and instance storeage
  44. static LPCTSTR lpszAppName = "GL Template";
  45. static HINSTANCE hInstance;
  46.  
  47. // Rotation amounts
  48. static GLfloat xRot = 0.0f;
  49. static GLfloat yRot = 0.0f;
  50. static GLfloat zRot = 0.0f;
  51.  
  52.  
  53. static GLsizei lastHeight;
  54. static GLsizei lastWidth;
  55.  
  56. // Opis tekstury
  57. BITMAPINFOHEADER    bitmapInfoHeader;   // nagłówek obrazu
  58. unsigned char*      bitmapData;         // dane tekstury
  59. unsigned int        texture[2];         // obiekt tekstury
  60.  
  61.  
  62. // Declaration for Window procedure
  63. LRESULT CALLBACK WndProc(   HWND    hWnd,
  64.                             UINT    message,
  65.                             WPARAM  wParam,
  66.                             LPARAM  lParam);
  67.  
  68. // Dialog procedure for about box
  69. BOOL APIENTRY AboutDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam);
  70.  
  71. // Set Pixel Format function - forward declaration
  72. void SetDCPixelFormat(HDC hDC);
  73.  
  74.  
  75.  
  76.  
  77. // Reduces a normal vector specified as a set of three coordinates,
  78. // to a unit normal vector of length one.
  79. void ReduceToUnit(float vector[3])
  80.     {
  81.     float length;
  82.    
  83.     // Calculate the length of the vector      
  84.     length = (float)sqrt((vector[0]*vector[0]) +
  85.                         (vector[1]*vector[1]) +
  86.                         (vector[2]*vector[2]));
  87.  
  88.     // Keep the program from blowing up by providing an exceptable
  89.     // value for vectors that may calculated too close to zero.
  90.     if(length == 0.0f)
  91.         length = 1.0f;
  92.  
  93.     // Dividing each element by the length will result in a
  94.     // unit normal vector.
  95.     vector[0] /= length;
  96.     vector[1] /= length;
  97.     vector[2] /= length;
  98.     }
  99.  
  100.  
  101. // Points p1, p2, & p3 specified in counter clock-wise order
  102. void calcNormal(float v[3][3], float out[3])
  103.     {
  104.     float v1[3],v2[3];
  105.     static const int x = 0;
  106.     static const int y = 1;
  107.     static const int z = 2;
  108.  
  109.     // Calculate two vectors from the three points
  110.     v1[x] = v[0][x] - v[1][x];
  111.     v1[y] = v[0][y] - v[1][y];
  112.     v1[z] = v[0][z] - v[1][z];
  113.  
  114.     v2[x] = v[1][x] - v[2][x];
  115.     v2[y] = v[1][y] - v[2][y];
  116.     v2[z] = v[1][z] - v[2][z];
  117.  
  118.     // Take the cross product of the two vectors to get
  119.     // the normal vector which will be stored in out
  120.     out[x] = v1[y]*v2[z] - v1[z]*v2[y];
  121.     out[y] = v1[z]*v2[x] - v1[x]*v2[z];
  122.     out[z] = v1[x]*v2[y] - v1[y]*v2[x];
  123.  
  124.     // Normalize the vector (shorten length to one)
  125.     ReduceToUnit(out);
  126.     }
  127.  
  128.  
  129.  
  130. // Change viewing volume and viewport.  Called when window is resized
  131. void ChangeSize(GLsizei w, GLsizei h)
  132.     {
  133.     GLfloat nRange = 100.0f;
  134.     GLfloat fAspect;
  135.     // Prevent a divide by zero
  136.     if(h == 0)
  137.         h = 1;
  138.  
  139.     lastWidth = w;
  140.     lastHeight = h;
  141.        
  142.     fAspect=(GLfloat)w/(GLfloat)h;
  143.     // Set Viewport to window dimensions
  144.     glViewport(0, 0, w, h);
  145.  
  146.     // Reset coordinate system
  147.     glMatrixMode(GL_PROJECTION);
  148.     glLoadIdentity();
  149.  
  150.     // Establish clipping volume (left, right, bottom, top, near, far)
  151.     if (w <= h)
  152.         glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
  153.     else
  154.         glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
  155.  
  156.     // Establish perspective:
  157.     /*
  158.     gluPerspective(60.0f,fAspect,1.0,400);
  159.     */
  160.  
  161.     glMatrixMode(GL_MODELVIEW);
  162.     glLoadIdentity();
  163.     }
  164.  
  165.  
  166.  
  167. // This function does any needed initialization on the rendering
  168. // context.  Here it sets up and initializes the lighting for
  169. // the scene.
  170. void SetupRC()
  171.     {
  172.     // Light values and coordinates
  173.     GLfloat  ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
  174.     GLfloat  diffuseLight[] = { 0.7f, 0.7f, 0.7f, 2.0f };
  175.     GLfloat  specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
  176.     GLfloat  lightPos[] = { 50.0f, 50.0f, 50.0f, 1.0f };
  177.     GLfloat  specref[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
  178.  
  179.  
  180.     glEnable(GL_DEPTH_TEST);    // Hidden surface removal
  181.     glFrontFace(GL_CCW);        // Counter clock-wise polygons face out
  182.     //glEnable(GL_CULL_FACE);       // Do not calculate inside of jet
  183.  
  184.     // Enable lighting
  185.     glEnable(GL_LIGHTING);
  186.  
  187.     // Setup and enable light 0
  188.     glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
  189.     glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
  190.     glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
  191.     glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
  192.     glEnable(GL_LIGHT0);
  193.  
  194.     // Enable color tracking
  195.     glEnable(GL_COLOR_MATERIAL);
  196.    
  197.     // Set Material properties to follow glColor values
  198.     glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  199.  
  200.     // All materials hereafter have full specular reflectivity
  201.     // with a high shine
  202.     glMaterialfv(GL_FRONT, GL_SPECULAR,specref);
  203.     glMateriali(GL_FRONT,GL_SHININESS,64);
  204.  
  205.  
  206.     // White background
  207.     glClearColor(0.9f, 0.9f, 0.9f, 1.0f );
  208.     // Black brush
  209.     glColor3f(0.0,0.0,0.0);
  210.     }
  211.  
  212. void skrzynka(void)
  213. {
  214.     glColor3d(0.8,0.7,0.3);
  215.    
  216.    
  217.     glEnable(GL_TEXTURE_2D); // Włącz teksturowanie
  218.  
  219.     glBindTexture(GL_TEXTURE_2D,texture[0]);
  220.     glBegin(GL_QUADS);
  221.         glNormal3d(0,0,1);
  222.         glTexCoord2d(1.0,1.0); glVertex3d(25,25,25);
  223.         glTexCoord2d(0.0,1.0); glVertex3d(-25,25,25);
  224.         glTexCoord2d(0.0,0.0); glVertex3d(-25,-25,25);
  225.         glTexCoord2d(1.0,0.0); glVertex3d(25,-25,25);
  226.     glEnd();
  227.     glBindTexture(GL_TEXTURE_2D,texture[1]);
  228.     glBegin(GL_QUADS);
  229.         glNormal3d(1,0,0);
  230.         glTexCoord2d(1.0,1.0); glVertex3d(25,25,25);
  231.         glTexCoord2d(0.0,1.0); glVertex3d(25,-25,25);
  232.         glTexCoord2d(0.0,0.0); glVertex3d(25,-25,-25);
  233.         glTexCoord2d(1.0,0.0); glVertex3d(25,25,-25);
  234.     glEnd();
  235.  
  236.     glDisable(GL_TEXTURE_2D); // Wyłącz teksturowanie
  237.  
  238.  
  239.  
  240.     glBegin(GL_QUADS);
  241.         glNormal3d(0,0,-1);
  242.         glVertex3d(25,25,-25);
  243.         glVertex3d(25,-25,-25);
  244.         glVertex3d(-25,-25,-25);
  245.         glVertex3d(-25,25,-25);
  246.  
  247.         glNormal3d(-1,0,0);
  248.         glVertex3d(-25,25,-25);
  249.         glVertex3d(-25,-25,-25);
  250.         glVertex3d(-25,-25,25);
  251.         glVertex3d(-25,25,25);
  252.  
  253.         glNormal3d(0,1,0);
  254.         glVertex3d(25,25,25);
  255.         glVertex3d(25,25,-25);
  256.         glVertex3d(-25,25,-25);
  257.         glVertex3d(-25,25,25);
  258.  
  259.         glNormal3d(0,-1,0);
  260.         glVertex3d(25,-25,25);
  261.         glVertex3d(-25,-25,25);
  262.         glVertex3d(-25,-25,-25);
  263.         glVertex3d(25,-25,-25);
  264.     glEnd();
  265. }
  266.  
  267. void walec01(void)
  268. {
  269. GLUquadricObj*obj;
  270. obj=gluNewQuadric();
  271. gluQuadricNormals(obj,GLU_SMOOTH);
  272. glColor3d(1,0,0);
  273. glPushMatrix();
  274. gluCylinder(obj,20,20,30,15,7);
  275. gluCylinder(obj,0,20,0,15,7);
  276. glTranslated(0,0,60);
  277. glRotated(180.0,0,1,0);
  278. gluCylinder(obj,0,20,30,15,7);
  279. glPopMatrix();
  280. }
  281.  
  282. void kula(void)
  283. {   GLUquadricObj*obj;
  284.     obj=gluNewQuadric();
  285.     gluQuadricTexture(obj,GL_TRUE);
  286.     glBindTexture(GL_TEXTURE_2D,texture[0]);
  287.     glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
  288.     glColor3d(1.0,0.8,0.8);
  289.     glEnable(GL_TEXTURE_2D);
  290.     gluSphere(obj,40,15,7);
  291.     glDisable(GL_TEXTURE_2D);
  292. }
  293.  
  294.  
  295.  
  296.  
  297. // LoadBitmapFile
  298. // opis: ładuje mapę bitową z pliku i zwraca jej adres.
  299. //       Wypełnia strukturę nagłówka.
  300. //   Nie obsługuje map 8-bitowych.
  301. unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
  302. {
  303.     FILE *filePtr;                          // wskaźnik pozycji pliku
  304.     BITMAPFILEHEADER    bitmapFileHeader;       // nagłówek pliku
  305.     unsigned char       *bitmapImage;           // dane obrazu
  306.     int                 imageIdx = 0;       // licznik pikseli
  307.     unsigned char       tempRGB;                // zmienna zamiany składowych
  308.  
  309.     // otwiera plik w trybie "read binary"
  310.     filePtr = fopen(filename, "rb");
  311.     if (filePtr == NULL)
  312.         return NULL;
  313.  
  314.     // wczytuje nagłówek pliku
  315.     fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
  316.    
  317.     // sprawdza, czy jest to plik formatu BMP
  318.     if (bitmapFileHeader.bfType != BITMAP_ID)
  319.     {
  320.         fclose(filePtr);
  321.         return NULL;
  322.     }
  323.  
  324.     // wczytuje nagłówek obrazu
  325.     fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
  326.  
  327.     // ustawia wskaźnik pozycji pliku na początku danych obrazu
  328.     fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
  329.  
  330.     // przydziela pamięć buforowi obrazu
  331.     bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
  332.  
  333.     // sprawdza, czy udało się przydzielić pamięć
  334.     if (!bitmapImage)
  335.     {
  336.         free(bitmapImage);
  337.         fclose(filePtr);
  338.         return NULL;
  339.     }
  340.  
  341.     // wczytuje dane obrazu
  342.     fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
  343.  
  344.     // sprawdza, czy dane zostały wczytane
  345.     if (bitmapImage == NULL)
  346.     {
  347.         fclose(filePtr);
  348.         return NULL;
  349.     }
  350.  
  351.     // zamienia miejscami składowe R i B
  352.     for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
  353.     {
  354.         tempRGB = bitmapImage[imageIdx];
  355.         bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
  356.         bitmapImage[imageIdx + 2] = tempRGB;
  357.     }
  358.  
  359.     // zamyka plik i zwraca wskaźnik bufora zawierającego wczytany obraz
  360.     fclose(filePtr);
  361.     return bitmapImage;
  362. }
  363.  
  364. void ramie(double r1, double r2, double h, double d)
  365. {
  366.     double PI = 3.14, alpha, x, y;
  367.     glBegin(GL_TRIANGLE_FAN);
  368.         glColor3d(0.8, 0.0, 0);
  369.         glVertex3d(0, 0, 0);
  370.         for (alpha = PI; alpha <= 2 * PI; alpha += PI / 8.0)
  371.         {
  372.             x = r1*sin(alpha);
  373.             y = r1*cos(alpha);
  374.             glVertex3d(x, y, 0);
  375.         }
  376.     glEnd();
  377.  
  378.     glBegin(GL_QUAD_STRIP);
  379.         for (alpha = 0; alpha >= -PI; alpha -= PI / 8.0)
  380.         {
  381.             x = r1*sin(alpha);
  382.             y = r1* cos(alpha);
  383.             glVertex3d(x, y, h);
  384.             glVertex3d(x, y, 0);
  385.         }
  386.     glEnd();
  387.  
  388.     glBegin(GL_TRIANGLE_FAN);
  389.         glVertex3d(0, 0, h);
  390.         for (alpha = 0; alpha >= -PI; alpha -= PI / 8.0)
  391.         {
  392.             x = r1*sin(alpha);
  393.             y = r1*cos(alpha);
  394.             glVertex3d(x, y, h);
  395.         }
  396.     glEnd();
  397.  
  398.     glBegin(GL_TRIANGLE_FAN);
  399.         glColor3d(0.8, 0.0, 0);
  400.         //glVertex3d(d,r2,0);
  401.         //glVertex3d(d, r2, h);
  402.         for (alpha = 0; alpha <= PI; alpha += PI / 8.0)
  403.         {
  404.             x = d + r2 * sin(alpha);
  405.             y = d + r2 * cos(alpha);
  406.             glVertex3d(x, y, 0);
  407.         }
  408.     glEnd();
  409.  
  410.     glBegin(GL_QUAD_STRIP);
  411.         //glVertex3d(d, r2, 0);
  412.         for (alpha = 0; alpha <= PI; alpha += PI / 8.0)
  413.         {
  414.             x = d+ r2*sin(alpha);
  415.             y = d +r2* cos(alpha);
  416.             glVertex3d(x, y, h);
  417.             glVertex3d(x, y, 0);
  418.         }
  419.     glEnd();
  420.  
  421.     glBegin(GL_TRIANGLE_FAN);
  422.         //glVertex3d(d, r2, h);
  423.         for (alpha = 0; alpha <= PI; alpha += PI / 8.0)
  424.         {
  425.             x = d +r2*sin(alpha);
  426.             y = d +r2*cos(alpha);
  427.             glVertex3d(x, y, h);
  428.         }
  429.     glEnd();
  430. }
  431.  
  432. void wheel(GLfloat point[3], double radius, double width)
  433. {
  434.     double x = point[0], y = point[1], z = point[2];
  435.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  436.     {
  437.         double x2, y2, z2, alpha;
  438.  
  439.         glBegin(GL_TRIANGLE_FAN);
  440.         glColor3d(0.8, 0.0, 0);
  441.         glVertex3d(x-width / 2, y, z);
  442.         for (alpha = 0; alpha < 2 * GL_PI; alpha += GL_PI / 16.0)
  443.         {
  444.             y2 = y + radius * sin(alpha);
  445.             z2 = z + radius * cos(alpha);
  446.             glVertex3d(x - width / 2, y2, z2);
  447.         }
  448.         y2 = y + radius * sin(0);
  449.         z2 = z + radius * cos(0);
  450.         glVertex3d(x - width / 2, y2, z2);
  451.         glEnd();
  452.  
  453.         glBegin(GL_TRIANGLE_STRIP);
  454.         glColor3d(0.0, 0.8, 0);
  455.         for (alpha = 0.0; alpha < 2 * GL_PI; alpha += GL_PI / 16.0)
  456.         {
  457.             y2 = radius * sin(alpha);
  458.             z2 = radius * cos(alpha);
  459.             glVertex3d(x - width / 2, y2 + y, z2 + z);
  460.             glVertex3d(x + width / 2, y2 + y, z2 + z);
  461.         }
  462.         y2 = radius * sin(0);
  463.         z2 = radius * cos(0);
  464.         glVertex3d(x - width / 2, y2 + y, z2 + z);
  465.         glVertex3d(x + width / 2, y2 + y, z2 + z);
  466.         glEnd();
  467.  
  468.         glBegin(GL_TRIANGLE_FAN);
  469.         glColor3d(0.8, 0.0, 0);
  470.         glVertex3d(x + width / 2, y, z);
  471.         for (alpha = 0; alpha < 2 * GL_PI; alpha += GL_PI / 16.0)
  472.         {
  473.             y2 = y + radius * sin(alpha);
  474.             z2 = z + radius * cos(alpha);
  475.             glVertex3d(x + width / 2, y2, z2);
  476.         }
  477.         y2 = y + radius * sin(0);
  478.         z2 = z + radius * cos(0);
  479.         glVertex3d(x + width / 2, y2, z2);
  480.         glEnd();
  481.     };
  482. }
  483.  
  484. void suspensionArm(GLfloat point[3], GLfloat point2[3], double w)
  485. {
  486.     double x = point[0], y = point[1], z = point[2];
  487.     double x2 = point2[0], y2 = point2[1], z2 = point2[2];
  488.     GLfloat p1[3] = { x - w / 2,y - w / 2,z };
  489.     GLfloat p2[3] = { x - w / 2,y + w / 2,z };
  490.     GLfloat p3[3] = { x + w / 2,y - w / 2,z };
  491.     GLfloat p4[3] = { x + w / 2,y + w / 2,z };
  492.  
  493.     GLfloat p5[3] = { x2 - w / 2,y2 - w / 2,z2 };
  494.     GLfloat p6[3] = { x2 - w / 2,y2 + w / 2,z2 };
  495.     GLfloat p7[3] = { x2 + w / 2,y2 - w / 2,z2 };
  496.     GLfloat p8[3] = { x2 + w / 2,y2 + w / 2,z2 };
  497.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  498.     {
  499.         glBegin(GL_TRIANGLE_STRIP);
  500.         glColor3d(0.5, 0.5, 0.5);
  501.         glVertex3fv(p1);
  502.         glVertex3fv(p2);
  503.         glVertex3fv(p3);
  504.         glVertex3fv(p4);
  505.         glEnd();
  506.  
  507.         glBegin(GL_TRIANGLE_STRIP);
  508.         glColor3d(0.5, 0.5, 0.5);
  509.         glVertex3fv(p1);
  510.         glVertex3fv(p5);
  511.         glVertex3fv(p3);
  512.         glVertex3fv(p7);
  513.         glVertex3fv(p4);
  514.         glVertex3fv(p8);
  515.         glVertex3fv(p2);
  516.         glVertex3fv(p6);
  517.         glVertex3fv(p1);
  518.         glVertex3fv(p5);
  519.         glEnd();
  520.  
  521.         glBegin(GL_TRIANGLE_STRIP);
  522.         glColor3d(0.5, 0.5, 0.5);
  523.         glVertex3fv(p5);
  524.         glVertex3fv(p6);
  525.         glVertex3fv(p7);
  526.         glVertex3fv(p8);
  527.         glEnd();
  528.  
  529.     };
  530. }
  531.  
  532. void box(GLfloat point[3], double width, double length, double height)
  533. {
  534.     double x = point[0], y = point[1], z = point[2];
  535.     double x2, y2;
  536.     double i,k;
  537.     int n = 4;
  538.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  539.     {
  540.         glBegin(GL_TRIANGLE_STRIP);
  541.         glColor3d(0.0, 0.8, 0.8);
  542.         y2 = length / 2;
  543.         x2 = -width / 2;
  544.         for (i = 0; i <= length / n; i++)
  545.         {
  546.             glVertex3d(x2, y2, z + height / 2);
  547.             glVertex3d(x2, y2, z - height / 2);
  548.             y2 -= n;
  549.         }
  550.  
  551.         for (i = 0; i < width / n; i++)
  552.         {
  553.             glVertex3d(x2, y2, z + height / 2);
  554.             glVertex3d(x2, y2, z - height / 2);
  555.             x2 += n;
  556.         }
  557.  
  558.         for (i = 0; i <= length / n; i++)
  559.         {
  560.             glVertex3d(x2, y2, z + height / 2);
  561.             glVertex3d(x2, y2, z - height / 2);
  562.             y2 += n;
  563.         }
  564.  
  565.         for (i = 0; i <= width / n; i++)
  566.         {
  567.             glVertex3d(x2, y2, z + height / 2);
  568.             glVertex3d(x2, y2, z - height / 2);
  569.             x2 -= n;
  570.         }
  571.         glEnd();
  572.        
  573.         x2 = -width / 2;
  574.         y2 = length / 2;
  575.  
  576.         for (k = 0; k < width /n; k++)
  577.         {
  578.             glBegin(GL_TRIANGLE_STRIP);
  579.             glColor3d(0.0, 0.6, 0.6);
  580.             for (i = 0; i <= (length / n) +1; i++)
  581.             {
  582.                 glVertex3d(x2, y2, z + height / 2);
  583.                 glVertex3d(x2 + n, y2, z + height / 2);
  584.                 y2 -= n;
  585.             }
  586.             x2 += n;
  587.             y2 = length / 2;
  588.             glEnd();
  589.         }
  590.  
  591.         x2 = -width / 2;
  592.         y2 = length / 2;
  593.  
  594.         for (k = 0; k < width / n; k++)
  595.         {
  596.             glBegin(GL_TRIANGLE_STRIP);
  597.             glColor3d(0.0, 0.6, 0.6);
  598.             for (i = 0; i <= (length / n) + 1; i++)
  599.             {
  600.                 glVertex3d(x2, y2, z - height / 2);
  601.                 glVertex3d(x2 + n, y2, z - height / 2);
  602.                 y2 -= n;
  603.             }
  604.             x2 += n;
  605.             y2 = length / 2;
  606.             glEnd();
  607.         }
  608.     };
  609.  
  610. }
  611.  
  612. void rover(double x, double y, double z)
  613. {
  614.     double width = 20;
  615.     double length = 30;
  616.     double height = 5;
  617.     double wheelArmWidth = 1;
  618.     double rideHeigth = 12;
  619.     double wheelRadius = 5;
  620.     double wheelWidth = 2;
  621.     double suspensionShaft = wheelArmWidth * 1.3;
  622.  
  623.     GLfloat body[3] = { x,y,z+rideHeigth+height/2 };
  624.  
  625.  
  626.     GLfloat wlf[3] = { -width / 2 - wheelArmWidth - wheelWidth / 2 ,length / 2,wheelRadius / 2 }; // wheel left front
  627.     GLfloat wlc[3] = { -width / 2 - wheelArmWidth - wheelWidth / 2 ,0,wheelRadius / 2 };
  628.     GLfloat wlb[3] = { -width / 2 - wheelArmWidth - wheelWidth / 2 ,-length / 2,wheelRadius / 2 };
  629.     GLfloat wrf[3] = { width / 2 + wheelArmWidth + wheelWidth / 2 ,length / 2,wheelRadius / 2 };
  630.     GLfloat wrc[3] = { width / 2 + wheelArmWidth + wheelWidth / 2 ,0,wheelRadius / 2 };
  631.     GLfloat wrb[3] = { width / 2 + wheelArmWidth + wheelWidth / 2 ,-length / 2,wheelRadius / 2 };
  632.  
  633.     wheel(wlf, wheelRadius, wheelWidth);
  634.     wheel(wlc, wheelRadius, wheelWidth);
  635.     wheel(wlb, wheelRadius, wheelWidth);
  636.     wheel(wrf, wheelRadius, wheelWidth);
  637.     wheel(wrc, wheelRadius, wheelWidth);
  638.     wheel(wrb, wheelRadius, wheelWidth);
  639.  
  640.  
  641.     GLfloat bslf[3] = { -width / 2 - wheelArmWidth / 2,length / 3,rideHeigth + height / 2}; // body suspension left front
  642.     GLfloat bslb[3] = { -width / 2 - wheelArmWidth / 2,-length / 4,rideHeigth + height / 2 };
  643.     GLfloat bsrf[3] = { width / 2 + wheelArmWidth / 2,length / 3,rideHeigth + height / 2 };
  644.     GLfloat bsrb[3] = { width / 2 + wheelArmWidth / 2,-length / 4,rideHeigth + height / 2 };
  645.  
  646.     GLfloat wslf[3] = { -width / 2 - wheelArmWidth / 2 ,length / 2,wheelRadius / 2 }; // wheel suspension left front
  647.     GLfloat wslc[3] = { -width / 2 - wheelArmWidth / 2 ,0,wheelRadius / 2 };
  648.     GLfloat wslb[3] = { -width / 2 - wheelArmWidth / 2 ,-length / 2,wheelRadius / 2 };
  649.     GLfloat wsrf[3] = { width / 2 + wheelArmWidth / 2 ,length / 2,wheelRadius / 2 };
  650.     GLfloat wsrc[3] = { width / 2 + wheelArmWidth / 2 ,0,wheelRadius / 2 };
  651.     GLfloat wsrb[3] = { width / 2 + wheelArmWidth / 2 ,-length / 2,wheelRadius / 2 };
  652.  
  653.  
  654.     suspensionArm(wslf, bslf, wheelArmWidth);
  655.     suspensionArm(wslc, bslb, wheelArmWidth);
  656.     suspensionArm(wslb, bslb, wheelArmWidth);
  657.     suspensionArm(wsrf, bsrf, wheelArmWidth);
  658.     suspensionArm(wsrc, bsrb, wheelArmWidth);
  659.     suspensionArm(wsrb, bsrb, wheelArmWidth);
  660.  
  661.     wheel(wslf, suspensionShaft, suspensionShaft);
  662.     wheel(wslc, suspensionShaft, suspensionShaft);
  663.     wheel(wslb, suspensionShaft, suspensionShaft);
  664.     wheel(wsrf, suspensionShaft, suspensionShaft);
  665.     wheel(wsrc, suspensionShaft, suspensionShaft);
  666.     wheel(wsrb, suspensionShaft, suspensionShaft);
  667.  
  668.     wheel(bslf, suspensionShaft, suspensionShaft);
  669.     wheel(bslb, suspensionShaft, suspensionShaft);
  670.     wheel(bsrf, suspensionShaft, suspensionShaft);
  671.     wheel(bsrb, suspensionShaft, suspensionShaft);
  672.  
  673.     box(body,width,length,height);
  674.  
  675.  
  676.  
  677. }
  678. // Called to draw scene
  679. void RenderScene(void)
  680.     {
  681.     //float normal[3];  // Storeage for calculated surface normal
  682.  
  683.     // Clear the window with current clearing color
  684.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  685.  
  686.     // Save the matrix state and do the rotations
  687.     glPushMatrix();
  688.     glRotatef(xRot, 1.0f, 0.0f, 0.0f);
  689.     glRotatef(yRot, 0.0f, 1.0f, 0.0f);
  690.     glRotatef(zRot, 0.0f, 0.0f, 1.0f);
  691.  
  692.     /////////////////////////////////////////////////////////////////
  693.     // MIEJSCE NA KOD OPENGL DO TWORZENIA WLASNYCH SCEN:           //
  694.     /////////////////////////////////////////////////////////////////
  695.    
  696.     //Sposób na odróźnienie "przedniej" i "tylniej" ściany wielokąta:
  697.     //glPolygonMode(GL_BACK,GL_LINE);
  698.  
  699.     //Uzyskanie siatki:
  700.     //glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  701.  
  702.     rover(0,0,0);
  703.  
  704.  
  705.     /////////////////////////////////////////////////////////////////
  706.     /////////////////////////////////////////////////////////////////
  707.     /////////////////////////////////////////////////////////////////
  708.     glPopMatrix();
  709.     glMatrixMode(GL_MODELVIEW);
  710.  
  711.     // Flush drawing commands
  712.     glFlush();
  713.     }
  714.  
  715.  
  716. // Select the pixel format for a given device context
  717. void SetDCPixelFormat(HDC hDC)
  718.     {
  719.     int nPixelFormat;
  720.  
  721.     static PIXELFORMATDESCRIPTOR pfd = {
  722.         sizeof(PIXELFORMATDESCRIPTOR),  // Size of this structure
  723.         1,                                                              // Version of this structure    
  724.         PFD_DRAW_TO_WINDOW |                    // Draw to Window (not to bitmap)
  725.         PFD_SUPPORT_OPENGL |                    // Support OpenGL calls in window
  726.         PFD_DOUBLEBUFFER,                       // Double buffered
  727.         PFD_TYPE_RGBA,                          // RGBA Color mode
  728.         24,                                     // Want 24bit color
  729.         0,0,0,0,0,0,                            // Not used to select mode
  730.         0,0,                                    // Not used to select mode
  731.         0,0,0,0,0,                              // Not used to select mode
  732.         32,                                     // Size of depth buffer
  733.         0,                                      // Not used to select mode
  734.         0,                                      // Not used to select mode
  735.         PFD_MAIN_PLANE,                         // Draw in main plane
  736.         0,                                      // Not used to select mode
  737.         0,0,0 };                                // Not used to select mode
  738.  
  739.     // Choose a pixel format that best matches that described in pfd
  740.     nPixelFormat = ChoosePixelFormat(hDC, &pfd);
  741.  
  742.     // Set the pixel format for the device context
  743.     SetPixelFormat(hDC, nPixelFormat, &pfd);
  744.     }
  745.  
  746.  
  747.  
  748. // If necessary, creates a 3-3-2 palette for the device context listed.
  749. HPALETTE GetOpenGLPalette(HDC hDC)
  750.     {
  751.     HPALETTE hRetPal = NULL;    // Handle to palette to be created
  752.     PIXELFORMATDESCRIPTOR pfd;  // Pixel Format Descriptor
  753.     LOGPALETTE *pPal;           // Pointer to memory for logical palette
  754.     int nPixelFormat;           // Pixel format index
  755.     int nColors;                // Number of entries in palette
  756.     int i;                      // Counting variable
  757.     BYTE RedRange,GreenRange,BlueRange;
  758.                                 // Range for each color entry (7,7,and 3)
  759.  
  760.  
  761.     // Get the pixel format index and retrieve the pixel format description
  762.     nPixelFormat = GetPixelFormat(hDC);
  763.     DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  764.  
  765.     // Does this pixel format require a palette?  If not, do not create a
  766.     // palette and just return NULL
  767.     if(!(pfd.dwFlags & PFD_NEED_PALETTE))
  768.         return NULL;
  769.  
  770.     // Number of entries in palette.  8 bits yeilds 256 entries
  771.     nColors = 1 << pfd.cColorBits; 
  772.  
  773.     // Allocate space for a logical palette structure plus all the palette entries
  774.     pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) +nColors*sizeof(PALETTEENTRY));
  775.  
  776.     // Fill in palette header
  777.     pPal->palVersion = 0x300;       // Windows 3.0
  778.     pPal->palNumEntries = nColors; // table size
  779.  
  780.     // Build mask of all 1's.  This creates a number represented by having
  781.     // the low order x bits set, where x = pfd.cRedBits, pfd.cGreenBits, and
  782.     // pfd.cBlueBits.  
  783.     RedRange = (1 << pfd.cRedBits) -1;
  784.     GreenRange = (1 << pfd.cGreenBits) - 1;
  785.     BlueRange = (1 << pfd.cBlueBits) -1;
  786.  
  787.     // Loop through all the palette entries
  788.     for(i = 0; i < nColors; i++)
  789.         {
  790.         // Fill in the 8-bit equivalents for each component
  791.         pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
  792.         pPal->palPalEntry[i].peRed = (unsigned char)(
  793.             (double) pPal->palPalEntry[i].peRed * 255.0 / RedRange);
  794.  
  795.         pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
  796.         pPal->palPalEntry[i].peGreen = (unsigned char)(
  797.             (double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
  798.  
  799.         pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
  800.         pPal->palPalEntry[i].peBlue = (unsigned char)(
  801.             (double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
  802.  
  803.         pPal->palPalEntry[i].peFlags = (unsigned char) NULL;
  804.         }
  805.        
  806.  
  807.     // Create the palette
  808.     hRetPal = CreatePalette(pPal);
  809.  
  810.     // Go ahead and select and realize the palette for this device context
  811.     SelectPalette(hDC,hRetPal,FALSE);
  812.     RealizePalette(hDC);
  813.  
  814.     // Free the memory used for the logical palette structure
  815.     free(pPal);
  816.  
  817.     // Return the handle to the new palette
  818.     return hRetPal;
  819.     }
  820.  
  821.  
  822. // Entry point of all Windows programs
  823. int APIENTRY WinMain(   HINSTANCE       hInst,
  824.                         HINSTANCE       hPrevInstance,
  825.                         LPSTR           lpCmdLine,
  826.                         int                     nCmdShow)
  827.     {
  828.     MSG                     msg;            // Windows message structure
  829.     WNDCLASS        wc;                     // Windows class structure
  830.     HWND            hWnd;           // Storeage for window handle
  831.  
  832.     hInstance = hInst;
  833.  
  834.     // Register Window style
  835.     wc.style                        = CS_HREDRAW | CS_VREDRAW;
  836.     wc.lpfnWndProc          = (WNDPROC) WndProc;
  837.     wc.cbClsExtra           = 0;
  838.     wc.cbWndExtra           = 0;
  839.     wc.hInstance            = hInstance;
  840.     wc.hIcon                        = NULL;
  841.     wc.hCursor                      = LoadCursor(NULL, IDC_ARROW);
  842.    
  843.     // No need for background brush for OpenGL window
  844.     wc.hbrBackground        = NULL;        
  845.    
  846.     wc.lpszMenuName         = MAKEINTRESOURCE(IDR_MENU);
  847.     wc.lpszClassName        = lpszAppName;
  848.  
  849.     // Register the window class
  850.     if(RegisterClass(&wc) == 0)
  851.         return FALSE;
  852.  
  853.  
  854.     // Create the main application window
  855.     hWnd = CreateWindow(
  856.                 lpszAppName,
  857.                 lpszAppName,
  858.                
  859.                 // OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS
  860.                 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  861.    
  862.                 // Window position and size
  863.                 448, 156,
  864.                 1024, 768,
  865.                 NULL,
  866.                 NULL,
  867.                 hInstance,
  868.                 NULL);
  869.  
  870.     // If window was not created, quit
  871.     if(hWnd == NULL)
  872.         return FALSE;
  873.  
  874.  
  875.     // Display the window
  876.     ShowWindow(hWnd,SW_SHOW);
  877.     UpdateWindow(hWnd);
  878.  
  879.     // Process application messages until the application closes
  880.     while( GetMessage(&msg, NULL, 0, 0))
  881.         {
  882.         TranslateMessage(&msg);
  883.         DispatchMessage(&msg);
  884.         }
  885.  
  886.     return msg.wParam;
  887.     }
  888.  
  889.  
  890.  
  891.  
  892. // Window procedure, handles all messages for this program
  893. LRESULT CALLBACK WndProc(       HWND    hWnd,
  894.                             UINT    message,
  895.                             WPARAM  wParam,
  896.                             LPARAM  lParam)
  897.     {
  898.     static HGLRC hRC;               // Permenant Rendering context
  899.     static HDC hDC;                 // Private GDI Device context
  900.  
  901.     switch (message)
  902.         {
  903.         // Window creation, setup for OpenGL
  904.         case WM_CREATE:
  905.             // Store the device context
  906.             hDC = GetDC(hWnd);              
  907.  
  908.             // Select the pixel format
  909.             SetDCPixelFormat(hDC);          
  910.  
  911.             // Create palette if needed
  912.             hPalette = GetOpenGLPalette(hDC);
  913.  
  914.             // Create the rendering context and make it current
  915.             hRC = wglCreateContext(hDC);
  916.             wglMakeCurrent(hDC, hRC);
  917.             SetupRC();
  918.             glGenTextures(2, &texture[0]);                  // tworzy obiekt tekstury          
  919.            
  920.             // ładuje pierwszy obraz tekstury:
  921.             bitmapData = LoadBitmapFile("Bitmapy\\checker.bmp", &bitmapInfoHeader);
  922.            
  923.             glBindTexture(GL_TEXTURE_2D, texture[0]);       // aktywuje obiekt tekstury
  924.  
  925.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  926.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  927.  
  928.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  929.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
  930.  
  931.             // tworzy obraz tekstury
  932.             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth,
  933.                          bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
  934.            
  935.             if(bitmapData)
  936.             free(bitmapData);
  937.  
  938.             // ładuje drugi obraz tekstury:
  939.             bitmapData = LoadBitmapFile("Bitmapy\\crate.bmp", &bitmapInfoHeader);
  940.             glBindTexture(GL_TEXTURE_2D, texture[1]);       // aktywuje obiekt tekstury
  941.  
  942.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  943.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  944.  
  945.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  946.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
  947.  
  948.             // tworzy obraz tekstury
  949.             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth,
  950.                          bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
  951.            
  952.             if(bitmapData)
  953.             free(bitmapData);
  954.  
  955.             // ustalenie sposobu mieszania tekstury z tłem
  956.             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);
  957.             break;
  958.  
  959.         // Window is being destroyed, cleanup
  960.         case WM_DESTROY:
  961.             // Deselect the current rendering context and delete it
  962.             wglMakeCurrent(hDC,NULL);
  963.             wglDeleteContext(hRC);
  964.  
  965.             // Delete the palette if it was created
  966.             if(hPalette != NULL)
  967.                 DeleteObject(hPalette);
  968.  
  969.             // Tell the application to terminate after the window
  970.             // is gone.
  971.             PostQuitMessage(0);
  972.             break;
  973.  
  974.         // Window is resized.
  975.         case WM_SIZE:
  976.             // Call our function which modifies the clipping
  977.             // volume and viewport
  978.             ChangeSize(LOWORD(lParam), HIWORD(lParam));
  979.             break;
  980.  
  981.  
  982.         // The painting function.  This message sent by Windows
  983.         // whenever the screen needs updating.
  984.         case WM_PAINT:
  985.             {
  986.             // Call OpenGL drawing code
  987.             RenderScene();
  988.  
  989.             SwapBuffers(hDC);
  990.  
  991.             // Validate the newly painted client area
  992.             ValidateRect(hWnd,NULL);
  993.             }
  994.             break;
  995.  
  996.         // Windows is telling the application that it may modify
  997.         // the system palette.  This message in essance asks the
  998.         // application for a new palette.
  999.         case WM_QUERYNEWPALETTE:
  1000.             // If the palette was created.
  1001.             if(hPalette)
  1002.                 {
  1003.                 int nRet;
  1004.  
  1005.                 // Selects the palette into the current device context
  1006.                 SelectPalette(hDC, hPalette, FALSE);
  1007.  
  1008.                 // Map entries from the currently selected palette to
  1009.                 // the system palette.  The return value is the number
  1010.                 // of palette entries modified.
  1011.                 nRet = RealizePalette(hDC);
  1012.  
  1013.                 // Repaint, forces remap of palette in current window
  1014.                 InvalidateRect(hWnd,NULL,FALSE);
  1015.  
  1016.                 return nRet;
  1017.                 }
  1018.             break;
  1019.  
  1020.    
  1021.         // This window may set the palette, even though it is not the
  1022.         // currently active window.
  1023.         case WM_PALETTECHANGED:
  1024.             // Don't do anything if the palette does not exist, or if
  1025.             // this is the window that changed the palette.
  1026.             if((hPalette != NULL) && ((HWND)wParam != hWnd))
  1027.                 {
  1028.                 // Select the palette into the device context
  1029.                 SelectPalette(hDC,hPalette,FALSE);
  1030.  
  1031.                 // Map entries to system palette
  1032.                 RealizePalette(hDC);
  1033.                
  1034.                 // Remap the current colors to the newly realized palette
  1035.                 UpdateColors(hDC);
  1036.                 return 0;
  1037.                 }
  1038.             break;
  1039.  
  1040.         // Key press, check for arrow keys to do cube rotation.
  1041.         case WM_KEYDOWN:
  1042.         {
  1043.             if(wParam == 'W')
  1044.                 xRot-= 5.0f;
  1045.  
  1046.             if(wParam == 'S')
  1047.                 xRot += 5.0f;
  1048.  
  1049.             if(wParam == 'A')
  1050.                 yRot -= 5.0f;
  1051.  
  1052.             if(wParam == 'D')
  1053.                 yRot += 5.0f;          
  1054.            
  1055.             if(wParam == 'Q')
  1056.                 zRot -= 5.0f;
  1057.  
  1058.             if(wParam == 'E')
  1059.                 zRot += 5.0f;
  1060.  
  1061.             xRot = (const int)xRot % 360;
  1062.             yRot = (const int)yRot % 360;
  1063.             zRot = (const int)zRot % 360;
  1064.  
  1065.             InvalidateRect(hWnd,NULL,FALSE);
  1066.             }
  1067.             break;
  1068.  
  1069.         // A menu command
  1070.         case WM_COMMAND:
  1071.             {
  1072.             switch(LOWORD(wParam))
  1073.                 {
  1074.                 // Exit the program
  1075.                 case ID_FILE_EXIT:
  1076.                     DestroyWindow(hWnd);
  1077.                     break;
  1078.  
  1079.                 // Display the about box
  1080.                 case ID_HELP_ABOUT:
  1081.                     DialogBox (hInstance,
  1082.                         MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
  1083.                         hWnd,
  1084.                         AboutDlgProc);
  1085.                     break;
  1086.                 }
  1087.             }
  1088.             break;
  1089.  
  1090.  
  1091.     default:   // Passes it on if unproccessed
  1092.         return (DefWindowProc(hWnd, message, wParam, lParam));
  1093.  
  1094.     }
  1095.  
  1096.     return (0L);
  1097.     }
  1098.  
  1099.  
  1100.  
  1101.  
  1102. // Dialog procedure.
  1103. BOOL APIENTRY AboutDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
  1104.     {
  1105.    
  1106.     switch (message)
  1107.     {
  1108.         // Initialize the dialog box
  1109.         case WM_INITDIALOG:
  1110.             {
  1111.             int i;
  1112.             GLenum glError;
  1113.  
  1114.             // glGetString demo
  1115.             SetDlgItemText(hDlg,IDC_OPENGL_VENDOR,glGetString(GL_VENDOR));
  1116.             SetDlgItemText(hDlg,IDC_OPENGL_RENDERER,glGetString(GL_RENDERER));
  1117.             SetDlgItemText(hDlg,IDC_OPENGL_VERSION,glGetString(GL_VERSION));
  1118.             SetDlgItemText(hDlg,IDC_OPENGL_EXTENSIONS,glGetString(GL_EXTENSIONS));
  1119.  
  1120.             // gluGetString demo
  1121.             SetDlgItemText(hDlg,IDC_GLU_VERSION,gluGetString(GLU_VERSION));
  1122.             SetDlgItemText(hDlg,IDC_GLU_EXTENSIONS,gluGetString(GLU_EXTENSIONS));
  1123.  
  1124.  
  1125.             // Display any recent error messages
  1126.             i = 0;
  1127.             do {
  1128.                 glError = glGetError();
  1129.                 SetDlgItemText(hDlg,IDC_ERROR1+i,gluErrorString(glError));
  1130.                 i++;
  1131.                 }
  1132.             while(i < 6 && glError != GL_NO_ERROR);
  1133.  
  1134.  
  1135.             return (TRUE);
  1136.             }
  1137.             break;
  1138.  
  1139.         // Process command messages
  1140.         case WM_COMMAND:      
  1141.             {
  1142.             // Validate and Make the changes
  1143.             if(LOWORD(wParam) == IDOK)
  1144.                 EndDialog(hDlg,TRUE);
  1145.             }
  1146.             break;
  1147.  
  1148.         // Closed from sysbox
  1149.         case WM_CLOSE:
  1150.             EndDialog(hDlg,TRUE);
  1151.             break;
  1152.         }
  1153.  
  1154.     return FALSE;
  1155.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement