ну, тут мало изменений:
Код | // transparency.cpp : Defines the entry point for the application. // #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <windows.h> #include <stdlib.h> #include <tchar.h> #include <string>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK TransparencyControl(HWND, UINT, WPARAM, LPARAM);
#pragma comment(lib,"Msimg32")
int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow){ MSG msg; WNDCLASSEX wcex; HWND hWnd,hWndChild; // UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = 0; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = ::LoadIcon( NULL, IDI_APPLICATION ); wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = ::CreateSolidBrush( RGB(254,0,0) ); wcex.lpszMenuName = NULL; wcex.lpszClassName = _T("TransparencyControlApplication"); wcex.hIconSm = ::LoadIcon( NULL, IDI_APPLICATION ); if( ::RegisterClassEx(&wcex) ){ hWnd = ::CreateWindowEx( WS_EX_LAYERED, wcex.lpszClassName, _T("пример для флага WS_EX_TRANSPARENT"), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT,0, 350,350,NULL,NULL, hInstance,NULL ); if(!hWnd){ return FALSE; } wcex.style = 0; wcex.lpfnWndProc = TransparencyControl; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = NULL; wcex.hCursor = ::LoadCursor(NULL,IDC_ARROW); wcex.hbrBackground = ::CreateSolidBrush( RGB(254,0,0) ); wcex.lpszMenuName = NULL; wcex.lpszClassName = _T("TransparencyControl"); wcex.hIconSm = NULL; if( ::RegisterClassEx(&wcex) ){ hWndChild = ::CreateWindowEx( 0, wcex.lpszClassName, _T("Иконка IDI_EXCLAMATION на фоне текста с прозрачным фоном\r\nразноцветные прямоугольники рисуются на родителе"), WS_CHILD,50,50,150,150, hWnd,NULL, hInstance,NULL ); if( hWndChild ){ ::ShowWindow(hWndChild, nCmdShow); } } ::SetLayeredWindowAttributes( hWnd, RGB(254,0,0), 128, LWA_COLORKEY ); ::ShowWindow(hWnd, nCmdShow); ::UpdateWindow(hWnd); } while(::GetMessage(&msg, NULL, 0, 0)){ ::TranslateMessage(&msg); ::DispatchMessage(&msg); } return(int)msg.wParam; } LRESULT CALLBACK TransparencyControl(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ switch( message ){ case WM_NCHITTEST:{ return HTCAPTION; } case WM_NCCALCSIZE:{ LPNCCALCSIZE_PARAMS lpParams = (LPNCCALCSIZE_PARAMS)lParam; if( wParam ){ ::DefWindowProc( hWnd, message, wParam, lParam ); ::SetRectEmpty( lpParams->rgrc + 1 ); ::SetRectEmpty( lpParams->rgrc + 2 ); return WVR_VALIDRECTS; } break; } case WM_PRINTCLIENT:{ RECT rc; POINT pt,org; std::wstring text; HDC hdc; HGDIOBJ hBrush,hPen; HICON hIcon; // hdc = (HDC)wParam; ::GetClientRect(hWnd,&rc); // рисуем прозрачный фон org = (POINT&)rc; ::MapWindowPoints(hWnd,::GetAncestor(hWnd,GA_PARENT),&org,1); ::GetWindowOrgEx(hdc,&pt); ::SetWindowOrgEx(hdc,pt.x + org.x,pt.y + org.y,NULL); ::SendMessage(::GetAncestor(hWnd,GA_PARENT),WM_ERASEBKGND,(WPARAM)hdc,0); ::SendMessage(::GetAncestor(hWnd,GA_PARENT),WM_PRINTCLIENT,(WPARAM)hdc,PRF_CLIENT); ::SetWindowOrgEx(hdc,pt.x,pt.y,NULL); // рисуем свое содержимое text.resize( ::GetWindowTextLength(hWnd) ); hBrush = ::SelectObject(hdc,::GetStockObject(NULL_BRUSH)); hPen = ::SelectObject(hdc,::GetStockObject(DC_PEN)); ::SetDCPenColor(hdc,RGB(0,255,0)); ::Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom); if( !text.empty() ){ ::InflateRect(&rc,-1,-1); ::GetWindowTextW(hWnd,&*text.begin(),text.size() + 1); ::SetBkMode(hdc,TRANSPARENT); ::DrawTextW(hdc,text.c_str(),text.size(),&rc, DT_VCENTER | DT_CENTER | DT_WORDBREAK); } hIcon = ::LoadIcon(NULL,IDI_EXCLAMATION); ::DrawIconEx(hdc,0,0,hIcon,0,0,0,NULL,DI_NORMAL); ::DestroyIcon(hIcon); ::SelectObject(hdc,hPen); ::SelectObject(hdc,hBrush); // LPRGBQUAD lpBits; BLENDFUNCTION bf; BITMAPINFO bmi; // memset( &bmi, 0, sizeof(bmi) ); bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); bmi.bmiHeader.biWidth = 255; bmi.bmiHeader.biHeight = 255; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; HGDIOBJ hBitmap = ::CreateDIBSection( NULL, &bmi, DIB_RGB_COLORS, (void**)&lpBits, NULL, 0 ); // for( int z,xx,yy,x, y = 255; y-- ; ){ for( x = 255; x-- ; ){ RGBQUAD&rgb = lpBits[y * 255 + x]; rgb.rgbBlue = 255 - x; rgb.rgbGreen = min(x,y); rgb.rgbRed = max(x,y); xx = x - 128; yy = y - 128; z = xx*xx + yy*yy; if( z < (128*128) ){ rgb.rgbReserved = (BYTE)((z * 255) / (128 * 128)); }else{ rgb.rgbReserved = 0; } } } HDC hMemDC = ::CreateCompatibleDC( hdc ); hBitmap = ::SelectObject( hMemDC, hBitmap ); bf.BlendOp = AC_SRC_OVER; bf.BlendFlags = 0; bf.SourceConstantAlpha = 255; bf.AlphaFormat = AC_SRC_ALPHA; ::AlphaBlend( hdc,10,45,55,55,hMemDC,0,0,255,255,bf); hBitmap = ::SelectObject( hMemDC, hBitmap ); ::DeleteObject( hBitmap ); ::DeleteDC( hMemDC ); break; } case WM_PAINT:{ PAINTSTRUCT ps; HDC hdc; HGDIOBJ hBitmap; int x,y,cx,cy; // ::BeginPaint(hWnd,&ps); x = ps.rcPaint.left; y = ps.rcPaint.top; cx = ps.rcPaint.right - ps.rcPaint.left; cy = ps.rcPaint.bottom - ps.rcPaint.top; hdc = ::CreateCompatibleDC(ps.hdc); hBitmap = ::CreateCompatibleBitmap(ps.hdc,cx,cy); hBitmap = ::SelectObject(hdc,hBitmap); ::SetWindowOrgEx(hdc,x,y,NULL); // ::SendMessage(hWnd,WM_PRINTCLIENT,(WPARAM)hdc,PRF_CLIENT); ::BitBlt(ps.hdc,x,y,cx,cy,hdc,x,y,SRCCOPY); // hBitmap = ::SelectObject(hdc,hBitmap); ::DeleteObject(hBitmap); ::DeleteDC(hdc); ::EndPaint(hWnd,&ps); break; } case WM_ERASEBKGND:{ if( ::WindowFromDC((HDC)wParam) == hWnd ){ return TRUE; } break; } } return::DefWindowProc(hWnd,message,wParam,lParam); } LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam){ switch( message ){ case WM_PRINTCLIENT:{ RECT rc; HGDIOBJ hPen; HDC hdc; // hdc = (HDC)wParam; ::SetRect(&rc,10,10,160,160); hPen = ::SelectObject(hdc,::GetStockObject(DC_PEN)); for(int i = 10;i--;){ if(i & 1){ ::SetDCPenColor(hdc,RGB(255,0,0)); }else{ ::SetDCPenColor(hdc,RGB(0,0,255)); } ::Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom); ::InflateRect(&rc,-3,-3); } ::SelectObject(hdc,hPen); break; } case WM_ERASEBKGND:{ if( ::WindowFromDC((HDC)wParam) == hWnd ){ return TRUE; } break; } case WM_PAINT:{ PAINTSTRUCT ps; HDC hdc; HGDIOBJ hBitmap; int x,y,cx,cy; // ::BeginPaint(hWnd,&ps); x = ps.rcPaint.left; y = ps.rcPaint.top; cx = ps.rcPaint.right - ps.rcPaint.left; cy = ps.rcPaint.bottom - ps.rcPaint.top; hdc = ::CreateCompatibleDC(ps.hdc); hBitmap = ::CreateCompatibleBitmap(ps.hdc,cx,cy); hBitmap = ::SelectObject(hdc,hBitmap); ::SetWindowOrgEx(hdc,x,y,NULL); // ::SendMessage(hWnd,WM_ERASEBKGND,(WPARAM)hdc,0); ::SendMessage(hWnd,WM_PRINTCLIENT,(WPARAM)hdc,PRF_CLIENT); ::BitBlt(ps.hdc,x,y,cx,cy,hdc,x,y,SRCCOPY); // hBitmap = ::SelectObject(hdc,hBitmap); ::DeleteObject(hBitmap); ::DeleteDC(hdc); ::EndPaint(hWnd,&ps); break; } case WM_DESTROY:{ ::PostQuitMessage(0); break; } } return::DefWindowProc(hWnd, message, wParam, lParam); }
|
кстати, заметил интересное разоблачение: нужно скопировать экран с работающей программой (Alt + Print Scrn) и вставить скриншот в любой редактор, забавный способ снять "розовые очки" ) |