bob323
Jan 21st, 2002, 02:02 PM
Bit of a big one here, but maybe someone has seen, or written some code that does something like this...
I have a windows application that draws a rectangle, I want the rectangle to fade out over time... any suggestions (or better yet) code?
kedaman
Jan 21st, 2002, 06:20 PM
Set a timer and redraw the rectangle or triangle (or whatever;)) with a COLORREF c
(unsigned char*)&c[0]=(unsigned char*)&a1[0]+time*((unsigned char*)&a2[0]-(unsigned char*)&a1[0])
(unsigned char*)&c[1]=(unsigned char*)&a1[1]+time*((unsigned char*)&a2[1]-*(unsigned char*)&a1[1])
(unsigned char*)&c[2]=(unsigned char*)&a1[2]+time*((unsigned char*)&a2[2]-(unsigned char*)&a1[2])
where a1 is the rectangle orignal colour and a2 is the background colour. the float time should increase from 0 to 1
bob323
Jan 22nd, 2002, 02:29 PM
I was playing around with what you suggested but I don't think I get it yet... here is what I was trying to do...
#include <windows.h>
#include <time.h>
/* function prototypes */
LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
char szAppName[] = "Fade";
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpszCmdLine, int nCmdShow)
{
HWND hwnd; /* handle of client area */
MSG msg; /* messages (i.e., user activity) */
WNDCLASSEX wndclass; /* window class to create */
HACCEL hAccel; /* keyboard accelerators (i.e., hot keys) */
/* register class, unless previously registered */
if (!hPrevInstance) {
wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, szAppName);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject (BLACK_BRUSH);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = NULL;
RegisterClassEx (&wndclass);
}
hwnd = CreateWindow (szAppName, "Fade Program",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
hAccel = LoadAccelerators (hInstance, szAppName);
/* event loop */
while (GetMessage (&msg, NULL, 0, 0)) {
if (!TranslateAccelerator (hwnd, hAccel, &msg)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
return (msg.wParam);
}
/* Window procedure for client area */
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance; /* same as instance in WinMain() */
HDC hDC; /* handle to device context -- allows screen output */
static PAINTSTRUCT ps; /* not really "used" (yet), but required anyway */
static RECT rect; /* size of client area */
COLORREF c,a1,a2;
HPEN GREEN;
switch (message) {
case WM_CREATE:
hDC = GetDC(hwnd);
//SetTimer(hwnd,1,100,NULL);
return (0);
case WM_SIZE:
return(0);
case WM_TIMER:
//(unsigned char*)&c[0]=(unsigned char*)&a1[0]+time*((unsigned char*)&a2[0]-(unsigned char*)&a1[0]);
//(unsigned char*)&c[1]=(unsigned char*)&a1[1]+time*((unsigned char*)&a2[1]-*(unsigned char*)&a1[1]) ;
//(unsigned char*)&c[2]=(unsigned char*)&a1[2]+time*((unsigned char*)&a2[2]-(unsigned char*)&a1[2]) ;
//GREEN =CreatePen(PS_SOLID,1,c);
return (0);
case WM_PAINT:
hDC = BeginPaint(hwnd, &ps);
GREEN =CreatePen(PS_SOLID,1,RGB(0,255,0));
SelectObject(hDC,GREEN);
MoveToEx(hDC,55,100,NULL);
LineTo(hDC,155,100);
EndPaint(hwnd, &ps);
return (0);
case WM_DESTROY:
KillTimer(hwnd,1);
PostQuitMessage (0);
return (0);
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
parksie
Jan 22nd, 2002, 03:14 PM
Quick, unrelated point - use [ code ] [ /code ] tags please :)