CでのフェードWindowsデスクトップ++
-
22-09-2019 - |
質問
私はフェードアウトまたはWindowsデスクトップを暗くして、通常のデスクトップの長方形の部分を表示する方法をうまくしようとしています。これは、画面領域キャプチャプログラムです。あなたはにジンは、Webページ内の背景がまた、一般的に行われているフェージングした後、私は正確な効果を見ることができます。任意のヒント/ポインタ/ C ++ソースに感謝します。 Googleはこれまでに役立っていません。
おかげで、 ネビル
解決
を使用レイヤードウィンドウそのカバー画面全体が、カラーキー値とそれをペイント関心(undarkenedされるべき領域)の矩形領域は、カラーキーと完全に充填されるようになっています。この領域は、その後、完全に透明で、デスクトップの残りの部分のように暗くはありません。あなたのレイヤードウィンドウの残りの部分は、ほとんど透明で濃い色で塗りつぶさある一定のアルファ値を持つように設定する必要があります。
ここで完全な作業例です。
#include "stdafx.h" #include "ScreenCapper.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); const COLORREF transparentColor = RGB(255,0,0); // Pure red is the color key, or totally transparent color const BYTE overallTranparencyAmount = 90; // Out of 255 int DesktopWidth,DesktopHeight; int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); DesktopWidth = GetSystemMetrics(SM_CXSCREEN); DesktopHeight = GetSystemMetrics(SM_CYSCREEN); MSG msg; HACCEL hAccelTable; LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_SCREENCAPPER, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SCREENCAPPER)); while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; memset(&wcex,0,sizeof(WNDCLASSEX)); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SCREENCAPPER)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); //wcex.lpszMenuName = MAKEINTRESOURCE(IDC_SCREENCAPPER); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; HWND hWnd = CreateWindowEx(WS_EX_LAYERED, szWindowClass, szTitle,WS_POPUP, 0, 0, DesktopWidth, DesktopHeight, NULL, NULL, hInstance, NULL); if (!hWnd) return FALSE; SetLayeredWindowAttributes(hWnd,transparentColor,32,LWA_COLORKEY | LWA_ALPHA); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; if (message == WM_COMMAND) { wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } else if (message == WM_PAINT) { hdc = BeginPaint(hWnd, &ps); HBRUSH hDarkBackgroundBrush = CreateSolidBrush(RGB(0,0,0)); HBRUSH hRegionOfInterestBrush = CreateSolidBrush(transparentColor); RECT screenRect; screenRect.left = screenRect.top = 0; screenRect.right = DesktopWidth; screenRect.bottom = DesktopHeight; RECT interestRect; interestRect.left = interestRect.top = 300; interestRect.right = interestRect.bottom = 600; FillRect(hdc,&screenRect,hDarkBackgroundBrush); FillRect(hdc,&interestRect,hRegionOfInterestBrush); DeleteObject(hDarkBackgroundBrush); DeleteObject(hRegionOfInterestBrush); EndPaint(hWnd, &ps); } else if (message == WM_DESTROY) { PostQuitMessage(0); } else return DefWindowProc(hWnd, message, wParam, lParam); return 0; }
他のヒント
公式の方法はFadeWindow()APIを使用することです: Windowsがないことを表示上のコントロールパネル
所属していません StackOverflow