SHARE
TWEET

Untitled

a guest Sep 16th, 2019 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <math.h>
  3. void MyGraph(HWND hwnd, HDC hdc);
  4. float f(float x);
  5. int NX(float x);
  6. int NY(float y);
  7. float xmin=0, xmax= 3*M_PI, ymin = -10, ymax=10;
  8. float Nxmin =100, Nxmax =1000, Nymin=100, Nymax=800;
  9. float x,y;
  10. /*  Declare Windows procedure  */
  11. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  12.  
  13. /*  Make the class name into a global variable  */
  14. char szClassName[ ] = "WindowsApp";
  15.  
  16. int WINAPI WinMain (HINSTANCE hThisInstance,
  17.                     HINSTANCE hPrevInstance,
  18.                     LPSTR lpszArgument,
  19.                     int nFunsterStil)
  20.  
  21. {
  22.     HWND hwnd;               /* This is the handle for our window */
  23.     MSG messages;            /* Here messages to the application are saved */
  24.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  25.  
  26.     /* The Window structure */
  27.     wincl.hInstance = hThisInstance;
  28.     wincl.lpszClassName = szClassName;
  29.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  30.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  31.     wincl.cbSize = sizeof (WNDCLASSEX);
  32.  
  33.     /* Use default icon and mouse-pointer */
  34.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  35.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  36.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  37.     wincl.lpszMenuName = NULL;                 /* No menu */
  38.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  39.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  40.     /* Use Windows's default color as the background of the window */
  41.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  42.  
  43.     /* Register the window class, and if it fails quit the program */
  44.     if (!RegisterClassEx (&wincl))
  45.         return 0;
  46.  
  47.     /* The class is registered, let's create the program*/
  48.     hwnd = CreateWindowEx (
  49.            0,                   /* Extended possibilites for variation */
  50.            szClassName,         /* Classname */
  51.            "Windows App",       /* Title Text */
  52.            WS_OVERLAPPEDWINDOW, /* default window */
  53.            CW_USEDEFAULT,       /* Windows decides the position */
  54.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  55.            544,                 /* The programs width */
  56.            375,                 /* and height in pixels */
  57.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  58.            NULL,                /* No menu */
  59.            hThisInstance,       /* Program Instance handler */
  60.            NULL                 /* No Window Creation data */
  61.            );
  62.  
  63.     /* Make the window visible on the screen */
  64.     ShowWindow (hwnd, nFunsterStil);
  65.  
  66.     /* Run the message loop. It will run until GetMessage() returns 0 */
  67.     while (GetMessage (&messages, NULL, 0, 0))
  68.     {
  69.         /* Translate virtual-key messages into character messages */
  70.         TranslateMessage(&messages);
  71.         /* Send message to WindowProcedure */
  72.         DispatchMessage(&messages);
  73.     }
  74.  
  75.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  76.     return messages.wParam;
  77. }
  78.  
  79.  
  80. /*  This function is called by the Windows function DispatchMessage()  */
  81.  
  82. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  83. {
  84.     HDC hdc;
  85.     PAINTSTRUCT ps;
  86.     switch (message)                  /* handle the messages */
  87.     {
  88.         case WM_DESTROY:
  89.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  90.             break;
  91.            
  92.         case WM_PAINT:
  93.              hdc = BeginPaint(hwnd, &ps);
  94.              MyGraph(hwnd, hdc);
  95.              break;
  96.         default:                      /* for messages that we don't deal with */
  97.             return DefWindowProc (hwnd, message, wParam, lParam);
  98.     }
  99.  
  100.     return 0;
  101. }
  102.  
  103.  
  104. //------------------------------------------------------------------------------
  105. void MyGraph(HWND hwnd, HDC hdc)
  106. {
  107.  
  108.     float dx=0.1;
  109.     MoveToEx(hdc,NX(xmin),NY(f(xmin)),NULL);
  110.         for (x=xmin;x<xmax;x+=dx)
  111.         {
  112.           LineTo(hdc,NX(x),NY(f(x)));
  113.         }
  114.     MoveToEx(hdc,NX(0),NY(ymin),NULL);
  115.     LineTo(hdc,NX(0),NY(ymax));
  116.    
  117.     MoveToEx(hdc,NX(xmin),((NX(xmax)-NX(xmin))/2),NULL);
  118.     LineTo(hdc,NX(xmax),((NX(xmax)-NX(xmin))/2));
  119.  
  120. }
  121.    
  122.    
  123.     int NX(float x)
  124.     {
  125.         return (int)(((x-xmin)/(xmax-xmin))*(Nxmax-Nxmin)+Nxmin);
  126.     }
  127.    
  128.     int NY(float y)
  129.     {
  130.         return (int)(((y-ymin)/(ymax-ymin))*(Nymin-Nymax)+Nymax);  
  131.     }
  132.    
  133.     float f(float x)
  134.     {
  135.         float max=1;
  136.         float min=1;
  137.         float m;
  138.       // return sqrt(x)*cos(4*x);
  139.       if (m>y)
  140.       {
  141.             max=m;
  142.       }
  143.       if (m<min)
  144.       {
  145.             min=m;
  146.       }
  147.         m=sqrt(x)*cos(x*10);
  148.          return m  ;          
  149.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top