Code:
/*------------------------------------------------------------
sia k feb 17 2002
------------------------------------------------------------*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ID_TIMER 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("sia0008") ;
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(30)) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH) ;
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon (hInstance, MAKEINTRESOURCE(30));
RegisterClassEx (&wndclass);
hwnd = CreateWindow (szAppName,
TEXT ("sia0008 sara Loves Chocolate"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
void listdatetime(HWND hwnd, int cyclient, char *t){
SYSTEMTIME st;
HDC hdc;
static char a2[70], a3[30], a4[70];
hdc = GetDC(hwnd);
GetLocalTime(&st);
GetDateFormat(LOCALE_SYSTEM_DEFAULT, DATE_LONGDATE, &st, NULL, a2, sizeof(a2));
SetBkColor(hdc, RGB(0, 0, 0));
TextOut(hdc, 0, cyclient - 120, a4, wsprintf(a4, "%s", a2)); // display time date
TextOut(hdc, 0, cyclient - 100, a3, wsprintf(a3, "%s %2d:%2d:%2d", t, //function
st.wHour, st.wMinute, st.wSecond));
ReleaseDC(hwnd, hdc);
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HDC hdc ;
PAINTSTRUCT ps ;
static RECT rect, rc1, rc2;
static HBRUSH hbrush;
static HPEN hpen;
char *t = "Time is";
static char array[50];
static int x, y, n, m, i, j = 0, p = 20, s = 0, g = 0, a = 0, q, r = 0, v = 70, w = 80;
static int a1[8] = {45, 10, 35, 35, 15, 40, 3, 9};
static BOOL flip = FALSE, flop = FALSE;
static int cxclient, cyclient;
COLORREF c;
static POINT point[10] = {35, 50, 30, 30, 20, 50, 15, 30, 0, 30, 5, 0, 10, 20, 35, 15, 60, 30,
40, 30};
static HRGN hrgn, ergn, frgn ;
switch (message)
{
case WM_CREATE:
// PlaySound (TEXT ("sia0008.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
hdc = GetDC(hwnd);
SetTimer(hwnd, 1, 100, NULL);
ReleaseDC(hwnd, hdc);
return 0 ;
case WM_TIMER:
flip = !flip;
GetClientRect(hwnd, &rc2);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_SIZE:
cxclient = LOWORD (lParam) ;
cyclient = HIWORD (lParam) ;
return 0;
case WM_PAINT:
BeginPaint (hwnd, &ps) ;
srand(time(NULL));
frgn = CreateRectRgn(0, 0, cxclient, 70);
SelectObject(hdc, frgn);
DeleteObject(frgn);
for(g = 0; g < 800; g++){ //first region the stars
x = 0 + rand() % cxclient;
y = 0 + rand() % 70;
SetPixel(hdc, x, y, RGB(0 + rand() % 255, 255, 255));
}
hpen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100));
SelectObject(hdc, hpen);
hbrush = CreateSolidBrush(RGB(136, 136, 136));
SelectObject(hdc, hbrush);
//GetStockObject(BS_HOLLOW);
SetPolyFillMode(hdc, WINDING);
Polygon(hdc, point, 10);
DeleteObject(hbrush);
DeleteObject(hpen);
MoveToEx(hdc, a1[1], 20, NULL);
LineTo(hdc, a1[0], 20);
MoveToEx(hdc, a1[2], 15, NULL);
LineTo(hdc, a1[3], 20);
hbrush = CreateSolidBrush(RGB(250,250, 0));
SelectObject(hdc, hbrush);
Ellipse(hdc, a1[4], 20, a1[5], 30);
SetRect(&rc1, a1[4], 20, a1[5], 30);
SetBkColor(hdc, RGB(250, 250, 0));
DrawText(hdc, "sara", -1, &rc1, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
DeleteObject(hbrush);
if(flip == FALSE){
hbrush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hdc, hbrush);
Ellipse(hdc, a1[6], 5, a1[7], 10); //beamming light on plane
DeleteObject(hbrush);
}
if(a <= 160){
for(q = 0; q <=7; q++) //line&image incremented on plane
a1[q] += 5;
for(q = 0; q < 10; q++)
point[q].x = point[q].x + 5;
}
else{
for(q = 0; q < 10; q++){
point[q].x = point[q].x - a * 5;
}
for(q = 0;q <= 7;q++)
a1[q] = a1[q] - a * 5; //line&image to orig loc on plane window
a = 0;
}
a++;
ergn = CreateEllipticRgn(cxclient - 80, 30, cxclient - 30, 80); //moon
SetRect(&rc1, cxclient - 80, 30, cxclient - 30, 80);
hbrush = CreateSolidBrush(RGB(255, 255, 255));
SelectObject(hdc, ergn);
FillRgn(hdc, ergn, hbrush);
SetBkColor(hdc, RGB(255, 255, 255));
SetTextColor(hdc, RGB(210, 210, 210));
DrawText(hdc,TEXT( "@*&*"), -1, &rc1, DT_SINGLELINE | DT_CENTER | DT_VCENTER); //2nd dark region moon
DrawText(hdc, TEXT("**"), -1, &rc1, DT_SINGLELINE | DT_CENTER);
DeleteObject(ergn);
for(i = 0; i < 750; i++){
x = cxclient - 80 + rand() % 50;
y = 30 + rand() % 50;
SetPixel(hdc, x, y, RGB(200, 200, 200));
}
hbrush = CreateSolidBrush(RGB(186, 130, 67));
SelectObject(hdc, hbrush);
Ellipse(hdc,cxclient - w, 55,cxclient - v, 65); //satelite
DeleteObject(hbrush);
if(w > 20 && v > 20){
v--;w--;
}else{
v = 70;w = 80;
}
hrgn = CreateRectRgn(0, 0,cxclient, cyclient); //make the senior region
SelectObject(hdc, hrgn);
DeleteObject(hrgn);
hpen = CreatePen(PS_SOLID, 2, RGB(130,130 , 130));
SelectObject(hdc, hpen);
MoveToEx(hdc, cxclient / 4 + 23, cyclient / 4 - 18, NULL);
LineTo(hdc, cxclient / 4 + 23, cyclient / 4);
SetRect(&rc1, 0, cyclient / 4 - 18, cxclient / 4 + 20, cyclient / 4);
hbrush = CreateSolidBrush(RGB(100, 100, 100));
FillRect(hdc, &rc1, hbrush);
Ellipse(hdc, cxclient / 4, cyclient / 4 - 8, cxclient / 4 + 15, cyclient / 4 + 8);
SetTextColor(hdc, RGB(250, 0, 0));
SetRect(&rc1, cxclient / 6, cyclient / 4 + 60, cxclient / 3 + 20, cyclient - 60); //fill tank
FillRect(hdc, &rc1, hbrush);;
hbrush = CreateSolidBrush(RGB(100,100, 100));
SelectObject(hdc, hbrush);
Ellipse(hdc, cxclient / 6, cyclient / 4 + 65, cxclient / 3 + 20, cyclient / 4 + 55);
DeleteObject(hbrush);
SetBkColor(hdc, RGB(100, 100, 100));
DrawText(hdc, TEXT("THE FILLING TANK"), -1, &rc1, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
DeleteObject(hbrush);
SetRect(&rect, cxclient / 4, cyclient / 4 - 5, cxclient / 4 + 15, cyclient / 4 + 60);
listdatetime(hwnd, cyclient, t); ////////
hbrush = CreateSolidBrush(RGB(0, 0, 0));
SelectObject(hdc, hbrush);
FillRect(hdc, &rect, hbrush);
SetBkMode(hdc, OPAQUE);
c = RGB(201, 201, 201);
for(i = 0; i <= p; i++){
x = cxclient / 4 + rand() % 15;
y = cyclient / 4 - 5 + rand() % 65;
SetPixel(hdc, x, y, c);
}
DeleteObject(hbrush);
SetRect(&rc1,30, cyclient / 4- 18, 60, cyclient / 4);
Ellipse(hdc, 30, cyclient / 4 - 18, 60, cyclient / 4);
SetBkColor(hdc, RGB(0, 0, 0));
DrawText(hdc, "vol+", -1, &rc1, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
SetRect(&rc1, 80, cyclient / 4 - 18, 110, cyclient / 4);
Ellipse(hdc, 80, cyclient / 4 - 18, 110, cyclient / 4);
DrawText(hdc, "vol-", -1, &rc1, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
hbrush = CreateSolidBrush(RGB(0, 0, 230));
SetRect(&rc1, cxclient / 6, cyclient - 60, cxclient / 3 + 20, (cyclient - 60) - j );//red fill up
FillRect(hdc, &rc1, hbrush);
DeleteObject(hpen);
DeleteObject(hbrush);
j++;
if(j == 280){
j = 0;
hbrush = CreateSolidBrush(RGB(100, 100, 100));
FillRect(hdc, &rc1, hbrush);
DeleteObject(hbrush);
}
SetBkColor(hdc, RGB(0, 0, 0));
wsprintf(array, "The Volume In Tank is %d", p);
TextOut(hdc,s , cyclient - 18, array, lstrlen(array));
if(s < 250)
s++;
hpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 250));
SelectObject(hdc, hpen);
for(q = 0; q < 450; q++){
MoveToEx(hdc, 0 + rand() % cxclient, (cyclient - 60) + rand() % 60, NULL);
LineTo(hdc, 0 + rand() % cxclient + 10, q % 10 == 0 ?(cyclient - 60) : (cyclient - 80) + rand() % 60);
DeleteObject(hpen);
}
DeleteObject(hpen);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_LBUTTONDOWN:
n = LOWORD (lParam);
m = HIWORD (lParam);
if(n < 60 && n > 30)
p += 5;
if(n < 110 && n > 80) //volume for liquide
p -= 5;
if(p == 0){
KillTimer(hwnd, 1);
InvalidateRect(hwnd, NULL, TRUE);
}
return 0;
case WM_DESTROY:
KillTimer(hwnd, 1);
DeleteObject(hpen);
DeleteObject(hbrush);
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}