Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+中淡入Windows桌面+;_C++_Windows_Screen Capture - Fatal编程技术网

C++ 在C+中淡入Windows桌面+;

C++ 在C+中淡入Windows桌面+;,c++,windows,screen-capture,C++,Windows,Screen Capture,我正在尝试解决如何淡出或调暗Windows桌面,然后正常显示桌面的矩形部分。这是一个屏幕区域捕获程序。你可以看到我在网页背景淡入淡出后的精确效果,这也是常见的。非常感谢任何提示/指针/C++源代码。到目前为止,谷歌没有提供帮助 谢谢, Neville使用覆盖整个屏幕的分层窗口,但使用颜色键值绘制,以便感兴趣的矩形区域(应未标记的区域)完全用颜色键填充。这个区域将是完全透明的,不会像桌面的其他部分那样变暗。分层窗口的其余部分应设置为具有恒定的alpha值,该值基本上是透明的,并用深色填充 下面是一

我正在尝试解决如何淡出或调暗Windows桌面,然后正常显示桌面的矩形部分。这是一个屏幕区域捕获程序。你可以看到我在网页背景淡入淡出后的精确效果,这也是常见的。非常感谢任何提示/指针/C++源代码。到目前为止,谷歌没有提供帮助

谢谢,
Neville

使用覆盖整个屏幕的分层窗口,但使用颜色键值绘制,以便感兴趣的矩形区域(应未标记的区域)完全用颜色键填充。这个区域将是完全透明的,不会像桌面的其他部分那样变暗。分层窗口的其余部分应设置为具有恒定的alpha值,该值基本上是透明的,并用深色填充

下面是一个完整的工作示例:

#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; } #包括“stdafx.h” #包括“ScreenCapper.h” #定义最大加载字符串100 //全局变量: HINSTANCE hInst;//当前实例 TCHAR szTitle[MAX_LOADSTRING];//标题栏文本 TCHAR szWindowClass[最大加载字符串];//主窗口类名称 //转发此代码模块中包含的函数声明: ATOM MyRegisterClass(HINSTANCE HINSTANCE); BOOL InitInstance(HINSTANCE,int); LRESULT回调WndProc(HWND、UINT、WPARAM、LPARAM); INT_PTR回调关于(HWND、UINT、WPARAM、LPARAM); const COLORREF transparentColor=RGB(255,0,0);//纯红色是颜色键,或完全透明的颜色 const BYTE overall-tranparencyamount=90;//255人中 int DesktopWidth,DesktopHeight; int APIENTRY_tWinMain(HINSTANCE HINSTANCE、HINSTANCE HPPREINSTANCE、LPTSTR lpCmdLine、int nCmdShow) { 未引用的_参数(HPPreInstance); 未引用的_参数(lpCmdLine); DesktopWidth=GetSystemMetrics(SM_CXSCREEN); DesktopHeight=GetSystemMetrics(SM_CYSCREEN); 味精; HACCEL hAccelTable; 加载字符串(hInstance、IDS\U APP\U TITLE、szTitle、MAX\U加载字符串); LoadString(hInstance、IDC_SCREENCAPPER、szWindowClass、MAX_LoadString); MyRegisterClass(hInstance); 如果(!InitInstance(hInstance,nCmdShow)) { 返回FALSE; } hAccelTable=加载加速器(hInstance、MAKEINTRESOURCE(IDC_SCREENCAPPER)); while(GetMessage(&msg,NULL,0,0)) { if(!TranslateAccelerator(msg.hwnd、hAccelTable和msg)) { 翻译信息(&msg); 发送消息(&msg); } } 返回(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(空,IDC_箭头); wcex.hbrBackground=(HBRUSH)(彩色窗口+1); //wcex.lpszMenuName=MAKEINTRESOURCE(IDC_SCREENCAPPER); wcex.lpszClassName=szWindowClass; wcex.hIconSm=LoadIcon(wcex.hInstance,MAKEINTRESOURCE(IDI_SMALL)); 返回注册表类(&wcex); } BOOL InitInstance(HINSTANCE HINSTANCE,int nCmdShow) { hInst=hInstance; HWND HWND=CreateWindowEx(WS_EX_分层,szWindowClass,szTitle,WS_弹出窗口,0,0,DesktopWidth,DesktopHeight,NULL,NULL,hInstance,NULL); 如果(!hWnd) 返回FALSE; 设置LayeredWindowAttributes(hWnd,透明色,32,LWA_颜色键| LWA_ALPHA); 显示窗口(hWnd、nCmdShow); 更新窗口(hWnd); 返回TRUE; } LRESULT回调WndProc(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM) { int wmId,wmEvent; PAINTSTRUCT-ps; HDC-HDC; 如果(消息==WM_命令) { wmId=LOWORD(wParam); wmEvent=HIWORD(wParam); //解析菜单选项: 交换机(wmId) { 案例IDM_退出: 窗口(hWnd); 打破 违约: 返回DefWindowProc(hWnd、message、wParam、lParam); } } else if(消息==WM\U PAINT) { hdc=开始喷漆(hWnd和ps); HBRUSH hDarkBackgroundBrush=CreateSolidBrush(RGB(0,0,0)); HBRUSH hRegionOfInterestBrush=创建实体笔刷(透明色); RECT-screenRect; screenRect.left=screenRect.top=0; screenRect.right=桌面宽度; screenRect.bottom=桌面高度; 直接利息; interestRect.left=interestRect.top=300; interestRect.right=interestRect.bottom=600; FillRect(hdc和screenRect、hDarkBackgroundBrush); FillRect(hdc和interestRect、hRegionOfInterestBrush); DeleteObject(hDarkBackgroundBrush); DeleteObject(hRegionOfInterestBrush); 端漆(hWnd和ps); } else if(消息==WM_DESTROY) { PostQuitMessage(0); } 其他的 返回DefWindowProc(hWnd、message、wParam、lParam); 返回0; }
使用覆盖整个屏幕的分层窗口,但使用颜色键值绘制它,以便感兴趣的矩形区域(应未标记的区域)完全由颜色键填充。这个区域将是完全透明的,不会像桌面的其他部分那样变暗。分层窗口的其余部分应设置为具有恒定的alpha值,该值基本上是透明的,并用深色填充

下面是一个完整的工作示例:

#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; } #包括“stdafx.h” #包括“ScreenCapper.h” #定义最大加载字符串100 //全局变量: HINSTANCE hInst;//当前实例 TCHAR szTitle[MAX_LOADSTRING];//标题栏文本 TCHAR szWindowClass[最大加载字符串];//主窗口类名称 //远期职能声明