S
Knuddel, shau mal uf 'usermode aero' für XP (ohne blur):
#include <windows.h>
#pragma comment(lib, "msimg32.lib")
int width(RECT *rc) {return rc->right - rc->left;}
int height(RECT *rc) {return rc->bottom - rc->top;}
void DrawMe(HWND hwnd, HDC hdcOrigin, HDC hdcTemp)
{
RECT rc;
BLENDFUNCTION bf;
int w, h;
HDC hdcDesktop = GetDC(0);
HDC hdcWindow = GetWindowDC(hwnd);
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.AlphaFormat = AC_SRC_ALPHA;
bf.SourceConstantAlpha = 255;
GetWindowRect(hwnd, &rc);
w = width(&rc);
h = height(&rc);
// copy from desktop bitmap to temporary bitmap
BitBlt(hdcTemp, 0, 0, w, h, hdcDesktop, rc.left, rc.top, SRCCOPY);
// blend the original window bitmap onto temporary bitmap
AlphaBlend(hdcTemp, 0, 0, w, h, hdcOrigin, 0, 0, w, h, bf);
// show the result
BitBlt(hdcWindow, 0, 0, w, h, hdcTemp, 0, 0, SRCCOPY);
ReleaseDC(hwnd, hdcWindow);
ReleaseDC(0, hdcDesktop);
}
BOOL __stdcall MyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HDC _hdcOrigin; // window bitmap with alpha pixels
static HDC _hdcTemp;
switch (uMsg)
{
case WM_WINDOWPOSCHANGED: {
WINDOWPOS *pos = (WINDOWPOS*)lParam;
if ((pos->flags & SWP_SHOWWINDOW) && !_hdcOrigin)
{
WINDOWINFO wi;
BITMAPINFOHEADER bh;
RGBQUAD *pixels;
POINT pt;
int left, top;
HDC hdc = GetWindowDC(hwnd);
wi.cbSize = sizeof(wi);
GetWindowInfo(hwnd, &wi);
ZeroMemory(&bh, sizeof(bh));
bh.biSize = sizeof(bh);
bh.biWidth = width(&wi.rcWindow);
bh.biHeight = height(&wi.rcWindow);
bh.biPlanes = 1;
bh.biBitCount = 32;
// create window bitmap
_hdcOrigin = CreateCompatibleDC(hdc);
DeleteObject(SelectObject(_hdcOrigin, CreateDIBSection(
hdc, (BITMAPINFO*)&bh, DIB_RGB_COLORS, (void**)&pixels, 0, 0)));
BitBlt(_hdcOrigin, 0, 0, width(&wi.rcWindow), height(&wi.rcWindow), hdc, 0, 0, SRCCOPY);
// temporary bitmap for drawing
_hdcTemp = CreateCompatibleDC(hdc);
DeleteObject(SelectObject(_hdcTemp, CreateCompatibleBitmap(
hdc, width(&wi.rcWindow), height(&wi.rcWindow))));
ReleaseDC(0, hdc);
// initialize alpha pixels
// client area: 255
// nonclient area: 128
left = wi.rcClient.left - wi.rcWindow.left;
top = wi.rcClient.top - wi.rcWindow.top;
SetRect(&wi.rcClient, left, top, left+width(&wi.rcClient), top+height(&wi.rcClient));
for (pt.y=0; pt.y<bh.biHeight; pt.y++)
{
int y = bh.biHeight - pt.y - 1;
RGBQUAD *lineptr = &pixels[y * bh.biWidth];
for (pt.x=0; pt.x<bh.biWidth; pt.x++)
{
lineptr[pt.x].rgbReserved = PtInRect(&wi.rcClient, pt) ? 255 : 128;
}
}
}
DrawMe(hwnd, _hdcOrigin, _hdcTemp);
break;
}
case WM_CLOSE: {
DestroyWindow(hwnd);
break;
}
case WM_DESTROY: {
if (_hdcOrigin) {
DeleteDC(_hdcOrigin);
DeleteDC(_hdcTemp);
}
PostQuitMessage(0);
break;
}
case WM_MOVE:
case WM_NCACTIVATE:
case WM_ACTIVATE:
case WM_ACTIVATEAPP:
case WM_MOUSEACTIVATE:
case WM_NCLBUTTONDOWN:
case 0x02A2:
case WM_SIZING:
DrawMe(hwnd, _hdcOrigin, _hdcTemp);
}
return FALSE;
}
int main(void)
{
MSG msg;
HWND hwnd = CreateWindowEx(WS_EX_LAYERED, WC_DIALOG, TEXT("Transparent Caption"), WS_CAPTION|WS_SYSMENU|WS_BORDER,0,0,0,0,0,0,0,0);
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
SetWindowLong(hwnd, DWL_DLGPROC, (LONG)MyWndProc);
SetWindowPos(hwnd,0,200,200,400,300,SWP_NOZORDER|SWP_SHOWWINDOW);
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}