#include "stdafx.h" #include "stdio.h" #include "windows.h" // Win32API Header File #define Red RGB (255,0,0) // definicia vlastnych farieb (Red+Green+Blue) #define Lime RGB (255,255,40) #define Blue RGB (0,0,255) #define White RGB (255,255,255) #define Green RGB (0,255,0) // nasleduje deklaracia troch funkcii, ktore // budeme pouzivat, definica na konci programu int BCX_Line (HWND,int,int,int,int,int,HDC); // kresli ciaru int BCX_Circle (HWND,int,int,int,int,int,HDC); // kresli kruznicu HWND GetConsoleWndHandle (void); // ziska handle na okno int main(int argc, char *argv[]) { static HWND hConWnd; hConWnd = GetConsoleWndHandle(); // tu zacina priestor pre vasu tvorivost: BCX_Circle(hConWnd, 350, 150, 100, Lime,0,0); BCX_Circle(hConWnd, 425, 150, 25, Blue,1,0); BCX_Circle(hConWnd, 275, 150, 25, Blue,1,0); BCX_Circle(hConWnd, 350, 225, 25, Red,1,0); BCX_Circle(hConWnd, 350, 75, 25, Red,1,0); BCX_Circle(hConWnd, 350, 150, 30, Lime,1,0); BCX_Line(hConWnd, 20, 290, 180, 290, White,0); BCX_Line(hConWnd, 20, 290, 20, 150, White,0); BCX_Line(hConWnd, 12, 150, 188, 150, Red,0); BCX_Line(hConWnd, 180, 150, 180, 290, White,0); BCX_Line(hConWnd, 12, 150, 100, 80, Red,0); BCX_Line(hConWnd, 100, 80, 188, 150, Red,0); BCX_Line(hConWnd, 70, 150, 100, 80, Red,0); BCX_Line(hConWnd, 40, 150, 100, 80, Red,0); BCX_Line(hConWnd, 100, 150, 100, 80, Red,0); BCX_Line(hConWnd, 130, 150, 100, 80, Red,0); BCX_Line(hConWnd, 160, 150, 100, 80, Red,0); BCX_Line(hConWnd, 40, 205, 40, 170, White,0); BCX_Line(hConWnd, 90, 205, 90, 170, White,0); BCX_Line(hConWnd, 110, 205, 110, 170, White,0); BCX_Line(hConWnd, 160, 205, 160, 170, White,0); BCX_Line(hConWnd, 40, 205, 90, 205, White,0); BCX_Line(hConWnd, 110, 205, 160, 205, White,0); BCX_Line(hConWnd, 40, 170, 90, 170, White,0); BCX_Line(hConWnd, 110, 170, 160, 170, White,0); scanf("?"); return 0; } /* ************************************************************************** */ /* */ /* Nasleduju definicie funkcii, nepredpoklada sa, ze by ste tu cokolvek */ /* menili, ale nie je to zakazane, mozete tak docielit mnohe zaujimave */ /* efekty... */ /* */ /* ************************************************************************** */ /* ************************************************************************** */ /* */ /* Funkcia BCX_Line */ /* */ /* HWND Wnd : handle okna */ /* int x1, y1 : suradnice pociatocneho bodu */ /* int x2, y2 : suradnice koncoveho bodu */ /* int Pen : farba */ /* HDC DrawHDC : kontext zariadenia */ /* */ /* Funkcia nakresli ciaru z bodu [x1,y1] do bodu [x2,y2] farbou Pen. */ /* */ /* ************************************************************************** */ int BCX_Line (HWND Wnd,int x1,int y1,int x2,int y2,int Pen,HDC DrawHDC) { int a,b=0; HPEN hOPen; HPEN hNPen = CreatePen(PS_SOLID, 2, Pen); // penstyle, width, color if (!DrawHDC) DrawHDC = GetDC(Wnd), b = 1; hOPen = (HPEN)SelectObject(DrawHDC, hNPen); MoveToEx(DrawHDC, x1, y1, NULL); // starting point of line a = LineTo(DrawHDC, x2, y2); // ending point of line DeleteObject(SelectObject(DrawHDC,hOPen)); if (b) ReleaseDC(Wnd, DrawHDC); return a; } /* ************************************************************************** */ /* */ /* Funkcia BCX_Circle */ /* */ /* HWND Wnd : handle okna */ /* int X, Y : suradnice stredu kruznice */ /* int R : polomer */ /* int Pen : farba */ /* int Fill : vypln */ /* HDC DrawHDC : kontext zariadenia */ /* */ /* Funkcia nakresli kruznicu so stredom [X,Y], polomerom R farbou Pen. */ /* */ /* Kruznicu kresli pomocou WinApi funkcie na kreslenie elipsy */ /* zadanej ohranicujucim obdlznikom so suradnicami laveho horneho */ /* a praveho dolneho rohu. /* */ /* ************************************************************************** */ int BCX_Circle(HWND Wnd,int X,int Y,int R,int Pen,int Fill,HDC DrawHDC) { int a, b = 0; if (!DrawHDC) DrawHDC = GetDC(Wnd), b = 1; HPEN hNPen = CreatePen(PS_SOLID, 2, Pen); // penstyle, width, color HPEN hOPen = (HPEN)SelectObject(DrawHDC, hNPen); HBRUSH hOldBrush; HBRUSH hNewBrush; if (Fill) // if true will fill circle with pencolor { hNewBrush = CreateSolidBrush(Pen); hOldBrush = (HBRUSH)SelectObject(DrawHDC, hNewBrush); } else // else just draw circle { hNewBrush = (HBRUSH)GetStockObject(NULL_BRUSH); hOldBrush = (HBRUSH)SelectObject(DrawHDC, hNewBrush); } a = Ellipse(DrawHDC, X-R, Y+R, X+R, Y-R); DeleteObject(SelectObject(DrawHDC, hOPen)); DeleteObject(SelectObject(DrawHDC, hOldBrush)); if (b) ReleaseDC(Wnd, DrawHDC); return a; } /* ************************************************************************** */ /* */ /* Funkcia GetConsoleWndHandle(void) */ /* */ /* ************************************************************************** */ // the hoop ... HWND GetConsoleWndHandle(void) { HWND hConWnd; OSVERSIONINFO os; char szTempTitle[64], szClassName[128], szOriginalTitle[1024]; os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); GetVersionEx( &os ); // may not work on WIN9x if ( os.dwPlatformId == VER_PLATFORM_WIN32s ) return 0; GetConsoleTitle( szOriginalTitle, sizeof( szOriginalTitle ) ); sprintf( szTempTitle,"%u - %u", GetTickCount(), GetCurrentProcessId() ); SetConsoleTitle( szTempTitle ); Sleep( 40 ); // handle for NT hConWnd = FindWindow( NULL, szTempTitle ); SetConsoleTitle( szOriginalTitle ); // may not work on WIN9x if ( os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) { hConWnd = GetWindow( hConWnd, GW_CHILD ); if ( hConWnd == NULL ) return 0; GetClassName( hConWnd, szClassName, sizeof ( szClassName ) ); while ( strcmp( szClassName, "ttyGrab" ) != 0 ) { hConWnd = GetNextWindow( hConWnd, GW_HWNDNEXT ); if ( hConWnd == NULL ) return 0; GetClassName( hConWnd, szClassName, sizeof( szClassName ) ); } } return hConWnd; }