|
-
May 26th, 2004, 11:42 AM
#1
gradually changing opacity
API function SetLayeredWindowAttributes sets the opacity for a window. Is it possible (and how) to make the window opacity level gradually change from the centre to the borders. For instance, can i set the opacity 95 percent for the centre and make it go down to 10% to the borders?
Thanks!
-
May 28th, 2004, 08:18 AM
#2
I dont know if there's a function like that. How about imitate it by making ur own 'alpha-blitting' function? There're alot of 'alpha-blitting' algorithms on Google.
Trust urself!
-
May 28th, 2004, 08:30 AM
#3
Originally posted by sephiroth2m
I dont know if there's a function like that. How about imitate it by making ur own 'alpha-blitting' function? There're alot of 'alpha-blitting' algorithms on Google.
Hi sephiroth2m,
Can you please post some URLs, I tired alpha-belneding on google it but it didnt return anything useful.
Thanks in advance,
Regards,
Usman.
Last edited by usman999_1; May 28th, 2004 at 12:38 PM.
-
May 28th, 2004, 12:36 PM
#4
How would you imitate it?
I mean, that can't possible work always correctly.
What happens when the window in the back is changed? You should somehow capture that and re-blit your window?
Or am I missing something?
-
May 29th, 2004, 12:15 AM
#5
Thanks for your replies. I go the solution (with some help )
Have a look:
Code:
#define _WIN32_WINNT 0x0500
#define UNICODE
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
const INT iWidth=400,iHeight=700;
HBITMAP hBitmap;
VOID OnPaint(HDC hdc){
HDC hDC_BMP=CreateCompatibleDC(hdc);
SelectObject(hDC_BMP,hBitmap);
BitBlt(hdc,0,0,iWidth,iHeight,hDC_BMP,0,0,SRCCOPY);
DeleteObject(hDC_BMP);
}
VOID CreateTrBitmap(HDC hdc){
HDC hDC_BMP=CreateCompatibleDC(hdc);
Bitmap *bmp=new Bitmap(iWidth,iHeight);
Graphics gr(bmp);
gr.Clear(Color(0,255,255,255));
GraphicsPath path;
path.AddEllipse(0, 0, iWidth, iHeight);
PathGradientBrush pthGrBrush(&path);
pthGrBrush.SetCenterColor(Color(0, 0, 0, 255));
Color colors[] = {Color(255, 100,100,0)};
int count = 1;
pthGrBrush.SetSurroundColors(colors, &count);
gr.FillEllipse(&pthGrBrush, 0, 0, iWidth, iHeight);
bmp->GetHBITMAP(Color(0,0,0,0),&hBitmap);
delete bmp;
DeleteObject(hDC_BMP);
}
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
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(NULL_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = TEXT("GettingStarted");
RegisterClass(&wndClass);
hWnd = CreateWindowEx(
WS_EX_LAYERED,
TEXT("GettingStarted"), // window class name
TEXT("Getting Started"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
iWidth, // initial x size
iHeight, // 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);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
} // WinMain
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc=NULL;
PAINTSTRUCT ps;
BLENDFUNCTION blend;
POINT ptSrc={0,0};HDC hDC_BMP;
SIZE szDefault;
szDefault.cx=iWidth;
szDefault.cy=iHeight;
switch(message)
{
case WM_CREATE:
CreateTrBitmap(GetDC(hWnd));
hDC_BMP=CreateCompatibleDC(hdc);
SelectObject(hDC_BMP,hBitmap);
blend.BlendOp=AC_SRC_OVER;
blend.BlendFlags=0;
blend.SourceConstantAlpha=255;
blend.AlphaFormat=AC_SRC_ALPHA;
if( UpdateLayeredWindow(hWnd,
NULL,&ptSrc,&szDefault,hDC_BMP,&ptSrc,NULL,&blend,
ULW_ALPHA)==0)
MessageBox(NULL,TEXT("Update failed!"),TEXT(""),MB_OK);
DeleteObject(hDC_BMP);
break;
/*****************************************
WM_PAINT NEVER GETS CALLED
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
OnPaint(hdc);
EndPaint(hWnd, &ps);
return 0;
************************/
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
} // WndProc
-
May 29th, 2004, 02:35 AM
#6
Yes, UpdateLayeredWindow is a solution, but it makes it a lot more difficult to display standard windows objects etc...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|