SHARE
TWEET

Untitled

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