Code:
*------------------------------------------------------------
Sia k
------------------------------------------------------------*/
#include <windows.h>
#include <stdio.h>
#define ID_TIMER 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = TEXT ("Hello Lovely Sara") ;
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wndclass);
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The, Hello Lovely Sara"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
BOOL b = TRUE;
static HDC hdc;
PAINTSTRUCT ps ;
static HBRUSH hbrush;
static int cxchar, cychar, cxclient, cyclient, i, j = 0, p = 0, n = 255, m = 25, f = 50, d = 50, s = 130,
cxs, cys;
//HINSTANCE hInstance;
TEXTMETRIC tm;
static RECT rect;
static HRGN ergn; //not utilized yet
switch (message)
{
case WM_CREATE:
// SetTimer(hwnd, ID_TIMER, 500, NULL); //not utilized yet
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxchar = tm.tmAveCharWidth;
cychar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hwnd, hdc);
return 0;
case WM_SIZE:
cxclient = LOWORD(lParam);
cyclient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
for(i = 0; i < 130 ; i++){
rect.left = i * cxclient / 255 ;
rect.top = i * cyclient / 255 ;
rect.right = cxclient - i * cxclient / 255 ;
rect.bottom = cyclient - i * cyclient / 255 ;
hbrush = CreateSolidBrush(RGB(255 - p, 255 - p, 255 - p));
p += 2;
FillRect(hdc, &rect, hbrush);
}
hbrush = CreateSolidBrush(RGB(245, 245, 245));
SelectObject(hdc, hbrush);
Rectangle(hdc,s * cxclient / 255 ,s * cyclient / 255,
cxclient - s * cxclient / 255, cyclient - s * cyclient / 255);
DeleteObject(hbrush);
hbrush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hdc, hbrush);
Ellipse(hdc, (cxclient / 2)- 5 ,cyclient - m, cxclient / 2 + f, (cyclient - m) + d);
DeleteObject(hbrush);
// }
p = 0;
EndPaint (hwnd, &ps) ;
return 0 ;
// case WM_TIMER:
// b = !b; //not utilized yet
// return 0;
case WM_KEYDOWN:
switch(wParam){
case VK_UP:
if(m < (cyclient / 2) && f > 0 && d > 0){
m += 15;
f -=2;
d -=2;
}
s--;
break;
case VK_DOWN:
if(m < (cyclient / 2) && m >= 25 && f > 0 && d > 0){
m -= 15;
f +=2;
d +=2;
}
s++;
break;
}
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_DESTROY:
//KillTimer(hwnd, ID_TIMER);
DeleteObject(hbrush);
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}