bob323
Feb 25th, 2002, 04:33 PM
I am trying to fadeout a line, by applying a gradient when you run the following code it creates a gradient and 'ands' it to the current image, you can see how the line is lightly faded from left to right. When you left click it "should" subtract out the gradient and just leave the line there all by itself in a slightly faded form.
anyone able to get this working? I am sure it is just the matter of one or two lines of code...
!!INCLUDE msimg32.lib in your object /library modules in settings!!
<code>
#include <windows.h>
#include <wingdi.h>
/* function prototypes */
LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
char szAppName[] = "Skeleton";
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 */
/* 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 = 0;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = NULL;
RegisterClassEx (&wndclass);
}
hwnd = CreateWindow (szAppName, "Skeleton Windows Program",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,NULL, NULL, hInstance, NULL);
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
/* event loop */
while (GetMessage (&msg, NULL, 0, 0)) {
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() */
static HDC hdctemp;
static HBITMAP hbtemp;
static HDC hdctemp2;
static HBITMAP hbtemp2;
static PAINTSTRUCT ps; /* not really "used" (yet), but required anyway */
static RECT rect; /* size of client area */
TRIVERTEX vert[2];
GRADIENT_RECT gRect;
static HPEN line;
static BOOL lBUT = FALSE;
line = CreatePen(PS_SOLID,2,RGB(255,0,0));
switch (message) {
case WM_LBUTTONDOWN:
lBUT = TRUE;
InvalidateRect(hwnd,0,FALSE);
return(0);
case WM_PAINT:
BeginPaint (hwnd, &ps);
GetClientRect(hwnd, &rect);
if(!lBUT){
hdctemp2 = CreateCompatibleDC(ps.hdc);
hbtemp2 = CreateCompatibleBitmap(ps.hdc,rect.right,rect.bottom);
SelectObject(hdctemp2,hbtemp2);
vert [0] .x = 0;
vert [0] .y = 0;
vert [0] .Red = 0x0000;
vert [0] .Green = 0x0000;
vert [0] .Blue = 0x0000;
vert [0] .Alpha = 0x0000;
vert [1] .x = rect.right;
vert [1] .y = rect.bottom;
vert [1] .Red = 0xff00;
vert [1] .Green = 0xff00;
vert [1] .Blue = 0xff00;
vert [1] .Alpha = 0x0000;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
SelectObject(ps.hdc,line);
LineTo(ps.hdc,250,250);
GradientFill(hdctemp2,vert,2,&gRect,1,GRADIENT_FILL_RECT_H);
BitBlt(ps.hdc,0,0,rect.right,rect.bottom,hdctemp2,0,0,SRCAND);
}
if(lBUT){
BitBlt(hdctemp2,0,0,rect.right,rect.bottom,hdctemp2,0,0,DSTINVERT);
BitBlt(ps.hdc,0,0,rect.right,rect.bottom,hdctemp2,0,0,SRCAND);
}
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY :
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
<\code>
anyone able to get this working? I am sure it is just the matter of one or two lines of code...
!!INCLUDE msimg32.lib in your object /library modules in settings!!
<code>
#include <windows.h>
#include <wingdi.h>
/* function prototypes */
LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
char szAppName[] = "Skeleton";
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 */
/* 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 = 0;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = NULL;
RegisterClassEx (&wndclass);
}
hwnd = CreateWindow (szAppName, "Skeleton Windows Program",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,NULL, NULL, hInstance, NULL);
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
/* event loop */
while (GetMessage (&msg, NULL, 0, 0)) {
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() */
static HDC hdctemp;
static HBITMAP hbtemp;
static HDC hdctemp2;
static HBITMAP hbtemp2;
static PAINTSTRUCT ps; /* not really "used" (yet), but required anyway */
static RECT rect; /* size of client area */
TRIVERTEX vert[2];
GRADIENT_RECT gRect;
static HPEN line;
static BOOL lBUT = FALSE;
line = CreatePen(PS_SOLID,2,RGB(255,0,0));
switch (message) {
case WM_LBUTTONDOWN:
lBUT = TRUE;
InvalidateRect(hwnd,0,FALSE);
return(0);
case WM_PAINT:
BeginPaint (hwnd, &ps);
GetClientRect(hwnd, &rect);
if(!lBUT){
hdctemp2 = CreateCompatibleDC(ps.hdc);
hbtemp2 = CreateCompatibleBitmap(ps.hdc,rect.right,rect.bottom);
SelectObject(hdctemp2,hbtemp2);
vert [0] .x = 0;
vert [0] .y = 0;
vert [0] .Red = 0x0000;
vert [0] .Green = 0x0000;
vert [0] .Blue = 0x0000;
vert [0] .Alpha = 0x0000;
vert [1] .x = rect.right;
vert [1] .y = rect.bottom;
vert [1] .Red = 0xff00;
vert [1] .Green = 0xff00;
vert [1] .Blue = 0xff00;
vert [1] .Alpha = 0x0000;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
SelectObject(ps.hdc,line);
LineTo(ps.hdc,250,250);
GradientFill(hdctemp2,vert,2,&gRect,1,GRADIENT_FILL_RECT_H);
BitBlt(ps.hdc,0,0,rect.right,rect.bottom,hdctemp2,0,0,SRCAND);
}
if(lBUT){
BitBlt(hdctemp2,0,0,rect.right,rect.bottom,hdctemp2,0,0,DSTINVERT);
BitBlt(ps.hdc,0,0,rect.right,rect.bottom,hdctemp2,0,0,SRCAND);
}
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY :
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
<\code>