Код:
#include <windows.h>
#include <tchar.h>
#include <math.h>
#define MAXLENTH 100
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
ATOM MyRegisterClass(HINSTANCE hInstance);
TCHAR szAppName[] = _TEXT("Graphic");
TCHAR szTitleMain[MAXLENTH];
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
HWND hWndMain;
MSG msg;
if(!MyRegisterClass(hInstance))
{
//MessageBox(hWnd,_TEXT("Can't register class"),_TEXT("Error..."), MB_OK | MB_ICONINFORMATION);
}
LoadString(hInstance,101,szTitleMain,MAXLENTH);
hWndMain = CreateWindow(szAppName,szTitleMain,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
hInstance,NULL);
ShowWindow(hWndMain, iCmdShow);
UpdateWindow(hWndMain);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.style = CS_VREDRAW | CS_HREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.hInstance = hInstance;
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hIcon = LoadIcon(NULL,IDI_QUESTION);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcex.lpszMenuName = NULL; // Пока не используем
wcex.hIconSm = LoadIcon(NULL,IDI_QUESTION);
wcex.lpszClassName = szAppName;
return RegisterClassEx(&wcex);
}
float fn(float x)
{
return 3*x-cos(x) - 1;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
static int draw_graf;
static int clx,cly,mx=20,my=20;
switch(iMsg)
{
case WM_CREATE:
draw_graf = 1;
return 0;
case WM_SIZE:
clx = LOWORD(lParam);
cly = HIWORD(lParam);
case WM_PAINT:
hDC = BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rect);
if(draw_graf)
{MoveToEx(hDC,0,cly/2,NULL);
LineTo(hDC,clx,cly/2);
LineTo(hDC,clx-5,(cly/2)-5);
MoveToEx(hDC,clx,cly/2,NULL);
LineTo(hDC,clx-5,(cly/2)+5);
MoveToEx(hDC,clx/2,cly,NULL);
LineTo(hDC,clx/2,0);
LineTo(hDC,(clx/2)-5,5);
MoveToEx(hDC,(clx/2)+5-1,5-1,NULL);
LineTo(hDC,clx/2,0);
for(int i=0;i<clx;i++)
SetPixel(hDC,i,(cly/2)-my*fn((float)i/mx),RGB(255,50,9));
}
EndPaint(hWnd,&ps);
return 0;
case WM_LBUTTONDOWN:
if(mx<256)
{
mx*=2;
my=mx;
draw_graf=1;
InvalidateRect(hWnd,NULL,true);
}
return 0;
case WM_RBUTTONDOWN:
if(mx>32)
{
mx/=2;
my=mx;
draw_graf=1;
InvalidateRect(hWnd,NULL,true);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,iMsg,wParam,lParam);
}
Извени вот только не компилировал, должно работать
|