Pushok

Graph constructor

Mar 7th, 2011
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #include "windows.h"
  2. #include "cmath"
  3. #include "windowsx.h"
  4. #include "tchar.h"
  5. #include "iostream"
  6.  
  7.  
  8. LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
  9. #define defwidth 640
  10. #define defheight 480
  11. int WINAPI WinMain(HINSTANCE hInst,HINSTANCE Hst,LPSTR str,int mode)
  12. {
  13.     TCHAR* szClassName = _T("MyWindClass");
  14.     TCHAR* szWinName = _T("Math");
  15.     MSG msg;
  16.     WNDCLASS wnc;
  17.     ZeroMemory(&wnc,sizeof wnc);
  18.     wnc.lpfnWndProc = WndProc;
  19.     wnc.hInstance = hInst;
  20.     wnc.lpszClassName = szClassName;
  21.     wnc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  22.     wnc.hCursor = LoadCursor(NULL,IDC_ARROW);
  23.     wnc.hbrBackground = CreateSolidBrush(RGB(255,255,255));
  24.     RegisterClass(&wnc);
  25.     HWND hwnd = CreateWindow(
  26.         szClassName,
  27.         szWinName,
  28.         WS_SYSMENU,
  29.         10,
  30.         10,
  31.         defwidth,
  32.         defheight,
  33.         HWND_DESKTOP,
  34.         NULL,
  35.         hInst,
  36.         NULL
  37.         );
  38.     ShowWindow(hwnd,SW_SHOWDEFAULT);
  39.     while(GetMessage(&msg,NULL,0,0))
  40.         DispatchMessage(&msg);
  41. }
  42.  
  43. void OnDestroy(HWND);
  44. void OnPaint(HWND);
  45. BOOL OnCreate(HWND,LPCREATESTRUCT);
  46.  
  47. LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  48. {
  49.     switch(msg)
  50.     {
  51.         HANDLE_MSG(hwnd,WM_DESTROY,OnDestroy);
  52.         HANDLE_MSG(hwnd,WM_PAINT,OnPaint);
  53.         HANDLE_MSG(hwnd,WM_CREATE,OnCreate);
  54.     default:
  55.         return DefWindowProc(hwnd,msg,wParam,lParam);
  56.     }
  57. }
  58.  
  59. void _stdcall TiMe(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  60. {
  61.     InvalidateRect(hwnd,NULL,true);
  62. }
  63.  
  64. BOOL OnCreate(HWND hw,LPCREATESTRUCT)
  65. {
  66.     return true;
  67. }
  68.  
  69. void OnDestroy(HWND)
  70. {
  71.     PostQuitMessage(1);
  72. }
  73.  
  74. #define LN2 0.69314718055994530942;
  75. #define PI 3.141592653589793;
  76.  
  77. inline double getFuncY(long double x)
  78. {
  79.     if(x < -3)
  80.         return 3*x + 7;
  81.     else if(x >= -3 && x <= 3)
  82.         return -2;
  83.     else if(x > 3)
  84.         return 3*x-11;
  85. }
  86.  
  87. void OnPaint(HWND hw)
  88. {
  89.     PAINTSTRUCT ps;
  90.     RECT rect;
  91.     GetClientRect(hw,&rect);
  92.     int xaxis = rect.right/2,yaxis = rect.bottom/2;
  93.     HDC hdc = BeginPaint(hw,&ps);
  94.     SelectBrush(hdc,CreateSolidBrush(RGB(0,0,0)));
  95.     MoveToEx(hdc,0,yaxis,NULL);
  96.     LineTo(hdc,rect.right,yaxis);
  97.     MoveToEx(hdc,xaxis,0,NULL);
  98.     LineTo(hdc,xaxis,rect.bottom);
  99.     MoveToEx(hdc,0,0,NULL);
  100.     for(register double x = -100.0,y=0;x < 100.0;x+=0.01){
  101.         y = -(getFuncY(x));
  102.         int mn = 51;
  103.         SetPixel(hdc,xaxis+x*mn,yaxis+y*mn,RGB(0,0,0));
  104.     }
  105.     EndPaint(hw,&ps);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment