Pushok icon

Graph constructor

Pushok | PRO | 03/07/11 07:10:41 PM UTC | 0 ⭐ | 422 👁️ | Never ⏰ | []
C++ |

2.24 KB

|

None

|

0 👍

/

0 👎

#include "windows.h"
#include "cmath"
#include "windowsx.h"
#include "tchar.h"
#include "iostream"
 
 
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
#define defwidth 640
#define defheight 480
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE Hst,LPSTR str,int mode)
{
    TCHAR* szClassName = _T("MyWindClass");
    TCHAR* szWinName = _T("Math");
    MSG msg;
    WNDCLASS wnc;
    ZeroMemory(&wnc,sizeof wnc);
    wnc.lpfnWndProc = WndProc;
    wnc.hInstance = hInst;
    wnc.lpszClassName = szClassName;
    wnc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wnc.hCursor = LoadCursor(NULL,IDC_ARROW);
    wnc.hbrBackground = CreateSolidBrush(RGB(255,255,255));
    RegisterClass(&wnc);
    HWND hwnd = CreateWindow(
        szClassName,
        szWinName,
        WS_SYSMENU,
        10,
        10,
        defwidth,
        defheight,
        HWND_DESKTOP,
        NULL,
        hInst,
        NULL
        );
    ShowWindow(hwnd,SW_SHOWDEFAULT);
    while(GetMessage(&msg,NULL,0,0))
        DispatchMessage(&msg);
}
 
void OnDestroy(HWND);
void OnPaint(HWND);
BOOL OnCreate(HWND,LPCREATESTRUCT);
 
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    switch(msg)
    {
        HANDLE_MSG(hwnd,WM_DESTROY,OnDestroy);
        HANDLE_MSG(hwnd,WM_PAINT,OnPaint);
        HANDLE_MSG(hwnd,WM_CREATE,OnCreate);
    default:
        return DefWindowProc(hwnd,msg,wParam,lParam);
    }
}
 
void _stdcall TiMe(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
    InvalidateRect(hwnd,NULL,true);
}
 
BOOL OnCreate(HWND hw,LPCREATESTRUCT)
{
    return true;
}
 
void OnDestroy(HWND)
{
    PostQuitMessage(1);
}
 
#define LN2 0.69314718055994530942;
#define PI 3.141592653589793;
 
inline double getFuncY(long double x)
{
    if(x < -3)
        return 3*x + 7;
    else if(x >= -3 && x <= 3)
        return -2;
    else if(x > 3)
        return 3*x-11;
}
 
void OnPaint(HWND hw)
{
    PAINTSTRUCT ps;
    RECT rect;
    GetClientRect(hw,&rect);
    int xaxis = rect.right/2,yaxis = rect.bottom/2;
    HDC hdc = BeginPaint(hw,&ps);
    SelectBrush(hdc,CreateSolidBrush(RGB(0,0,0)));
    MoveToEx(hdc,0,yaxis,NULL);
    LineTo(hdc,rect.right,yaxis);
    MoveToEx(hdc,xaxis,0,NULL);
    LineTo(hdc,xaxis,rect.bottom);
    MoveToEx(hdc,0,0,NULL);
    for(register double x = -100.0,y=0;x < 100.0;x+=0.01){
        y = -(getFuncY(x));
        int mn = 51;
        SetPixel(hdc,xaxis+x*mn,yaxis+y*mn,RGB(0,0,0));
    }
    EndPaint(hw,&ps);
}

Comments