2009-10-19 1 views
1

Windows 데스크톱을 페이드 아웃하거나 어둡게하는 방법을 알아 내려고 평소에 데스크탑의 직사각형 부분을 표시하려고합니다. 이것은 화면 영역 캡처 프로그램을위한 것입니다. Jing에서 나는 정확한 효과를 볼 수 있습니다. 웹 페이지에서 배경을 약화시키는 것도 일반적으로 이루어집니다. 모든 팁/포인터/C + + 소스 많이 감사하겠습니다. Google은 지금까지 도움이되지 못했습니다.C++에서 Windows 데스크톱 페이드 화

감사합니다, 네빌

+0

Nevf에서 해당 작업을 수행, 지금 뭐하는 거지 너가하는 일을 가까이하면, 이걸로 나를 도울 수 있니? http://stackoverflow.com/questions/32431612/how-to-show-semitransparent-window-above-all-windows/32432473#32432473 – yozhik

+0

나는이 방법을 우리의 반투명 한 최상위 화면이 편집 가능하고 클릭 가능 했습니까? prntscr.com/8dkvvw – yozhik

답변

8

를 사용하여 전체 화면을 커버하지만, 컬러 키 값으로 페인트 계층화 된 창 그러한이자 (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; 
} 
+0

고마워요 클레이, 그게 의미가 있지만, 나는 그것을 수행하기 위해 몇 가지 샘플 코드를 쓰는 데 어려움을 겪고 있습니다. 나는 투명한 창문을 가지고 있지만 여기에서 어디로 가야 할 지에 달려있다. 낮은 수준의 Windows 그래픽 코딩을 수행 한 이후로 오랜 시간이 걸렸지 만 절대로 내 장점이 아닙니다. – nevf

+0

좋아요,이 동일한 질문에 대한 또 다른 대답으로 전체 샘플을 게시 해 드리겠습니다. –

+0

완전한 예제 nevf가 있습니다. 아휴. 희망이 도움이됩니다. –

-1

공식적인 방법은 FadeWindow() API를 함께 :

여기 완전한 작업 예제 윈도우 디스플레이 제어판

See the standard code in C

+0

감사합니다. 그러나 Windows에서 FadeWindow() API를 찾을 수 있습니다. VS2008 도움말 및 MSDN을 검색했습니다. 내가 Clay가 제시 한 SetLayeredWindowAttributes()를 사용한 링크 된 사이트에서 기사를 찾았습니다. 이 방법은 Window를 페이드하는 데는 효과적이지만, Window에서 일반적인 페인트를 수행 할 수 없습니다. – nevf

+0

Win32 그룹에서 다시 질문 할 수 있습니다. 고전적인 질문입니다 (api는 서수로 호출해야합니다) – marcus

관련 문제