Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <windows.h>
- #pragma hdrstop
- //---------------------------------------------------------------------------
- #define MAXF 20
- typedef enum {kwadrat, kolo, prostokat, trojkat, tekst, linia, elipsa} typ_figury;
- struct punkt {
- int x,y;
- };
- struct kwadrat {
- struct punkt w1;
- int bok;
- };
- struct prostokat {
- struct punkt w1, w2;
- };
- struct tekst {
- struct punkt w1;
- char *txt;
- };
- struct linia {
- struct punkt w1, w2;
- };
- struct elipsa {
- struct punkt w1, w2;
- };
- struct figura {
- typ_figury figura;
- union {
- struct kwadrat kwadrat;
- struct prostokat prostokat;
- struct tekst tekst;
- struct linia linia;
- struct elipsa elipsa;
- } ;
- };
- struct figura figury[MAXF];
- int last;
- void dodaj_kwadrat( int x, int y, int b) {
- figury[last].figura = kwadrat;
- figury[last].kwadrat.w1.x=x;
- figury[last].kwadrat.w1.y=y;
- figury[last].kwadrat.bok=b;
- last++;
- }
- void dodaj_tekst( int x, int y, char *txt) {
- figury[last].figura = tekst;
- figury[last].tekst.w1.x=x;
- figury[last].tekst.w1.y=y;
- figury[last].tekst.txt = txt;
- last++;
- }
- void dodaj_linia( int x, int y, int x1, int y1) {
- figury[last].figura = linia;
- figury[last].linia.w1.x=x;
- figury[last].linia.w1.y=y;
- figury[last].linia.w2.x=x1;
- figury[last].linia.w2.x=y1;
- last++;
- }
- void dodaj_elipsa( int x, int y, int x1, int y1) {
- figury[last].figura = elipsa;
- figury[last].elipsa.w1.x=x;
- figury[last].elipsa.w1.y=y;
- figury[last].elipsa.w2.x=x1;
- figury[last].elipsa.w2.x=y1;
- last++;
- }
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
- PAINTSTRUCT ps;
- int i;
- HDC hdc;
- RECT rt;
- int x, y, n;
- switch(Msg) {
- case WM_CREATE:
- dodaj_kwadrat(10,10, 10);
- //dodaj_kwadrat(50,50, 60);
- dodaj_tekst(200,200, "Tekst");
- dodaj_linia (500,10, 550,100);
- dodaj_elipsa (200,100, 100,20);
- // itd
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- for(i=0;i<last;i++)
- switch (figury[i].figura) {
- case kwadrat: {
- RECT rect;
- rect.left=figury[i].kwadrat.w1.x;
- rect.top=figury[i].kwadrat.w1.y;
- rect.right=figury[i].kwadrat.w1.x+figury[i].kwadrat.bok;
- rect.bottom=figury[i].kwadrat.w1.y+figury[i].kwadrat.bok;
- FillRect(hdc, &rect, (HBRUSH) (COLOR_BTNFACE+1) );
- break;
- }
- case tekst: {
- TextOut(hdc, figury[i].tekst.w1.x, figury[i].tekst.w1.y, figury[i].tekst.txt, strlen(figury[i].tekst.txt));
- break;
- }
- case linia: {
- MoveToEx(hdc, figury[i].linia.w1.x, figury[i].linia.w1.y, (LPPOINT) NULL);
- LineTo(hdc, figury[i].linia.w2.x, figury[i].linia.w2.y);
- break;
- }
- case elipsa: {
- Ellipse(hdc, figury[i].elipsa.w1.x, figury[i].elipsa.w1.y, figury[i].linia.w2.x, figury[i].linia.w2.y);
- }
- }
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- default:
- break;
- }
- return DefWindowProc(hWnd, Msg, wParam, lParam);
- }
- //---------------------------------------------------------------------------
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- // The variable that will define the window
- WNDCLASS WndCls;
- // The window's name
- static char szAppName[] = "EdytorC3";
- MSG Msg;
- // Filling out the structure that builds the window
- WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
- WndCls.lpfnWndProc = WindowProc;
- WndCls.cbClsExtra = 0;
- WndCls.cbWndExtra = 0;
- WndCls.hInstance = hInstance;
- WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
- WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- WndCls.lpszMenuName = NULL;
- WndCls.lpszClassName = szAppName;
- RegisterClass(&WndCls);
- CreateWindow( szAppName,
- "Ćwiczenie C3 i C4",
- WS_OVERLAPPEDWINDOW | WS_VISIBLE,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- while( GetMessage(&Msg, NULL, 0, 0) ) {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement