Briskstar Technologies
Briskstar Technologies

Reputation: 2253

Make transparent background of application window

I want to make transparent any application window not its contents using c# or vc++. For example If I opened my computer then it makes that window transparent from my application not folders.

Upvotes: 0

Views: 3182

Answers (2)

GrayFox374
GrayFox374

Reputation: 1782

To the Google:

http://www.intowindows.com/make-windows-7-transparent-with-system-transparency-tool/

You can do this in Windows 7 easily, no code required. For Win 200/XP, to the Google machine once more:

http://www.codeproject.com/Articles/4473/Making-any-application-transparent-in-Windows-2000

bool m_bTracking; // will be true when the mouse is // being tracked HWND m_hCurrWnd; // Handle to the window over which // the mouse was last present HCURSOR m_hCursor; // The wand cursor

// Global definition typedef BOOL (WINAPI *lpfn) (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags); lpfn g_pSetLayeredWindowAttributes;

BOOL CWinTransDlg::OnInitDialog() { .... // get the function pointer for SetLayeredWindowAttributes // in User32.dll HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL")); g_pSetLayeredWindowAttributes = (lpfn)GetProcAddress(hUser32, "SetLayeredWindowAttributes"); if (g_pSetLayeredWindowAttributes == NULL) AfxMessageBox ( "Layering is not supported in this version of Windows", MB_ICONEXCLAMATION);

//  Load the wand cursor
HINSTANCE hInstResource = AfxFindResourceHandle(
     MAKEINTRESOURCE(IDC_WAND), RT_GROUP_CURSOR);
m_hCursor = ::LoadCursor( hInstResource, MAKEINTRESOURCE(IDC_WAND) );
... }

void CWinTransDlg::OnLButtonDown(UINT nFlags, CPoint point) { ... SetCapture(); // make mouse move events to // be directed to this window m_hCurrWnd = NULL; // Currently no window is to be made transparent m_bTracking = true; // set the tracking flag ::SetCursor(m_hCursor); // turn the mouse pointer into the wand cursor ... }

void CWinTransDlg::OnMouseMove(UINT nFlags, CPoint point) { ... if (m_bTracking) { ... // convert mouse coordinates to screen ClientToScreen(&point); ... // get the window at the mouse coords m_hCurrWnd = ::WindowFromPoint(point); ... // Show details of the window like class, caption, etc. ... } ... }

void CWinTransDlg::OnLButtonUp(UINT nFlags, CPoint point) { ... // stop tracking the mouse ReleaseCapture(); m_bTracking = false;

//  If the window under the mouse is not of this 
//  application we toggle its
//  layer style flag and apply the alpha as set by the slider control
if (g_pSetLayeredWindowAttributes && m_hCurrWnd != m_hWnd)
{
    ::SetWindowLong(m_hCurrWnd, GWL_EXSTYLE,
                    GetWindowLong(m_hCurrWnd, 
                    GWL_EXSTYLE) ^ WS_EX_LAYERED);
    g_pSetLayeredWindowAttributes(m_hCurrWnd, 0,
                    (BYTE)m_slider.GetPos(), LWA_ALPHA);

    ::RedrawWindow(m_hCurrWnd, NULL, NULL,
                   RDW_ERASE | RDW_INVALIDATE | 
                   RDW_FRAME | RDW_ALLCHILDREN);
}
... }

Upvotes: 0

MMK
MMK

Reputation: 3721

Set the Form properties

this.BackColor = System.Drawing.Color.Lime;
this.TransparencyKey = System.Drawing.Color.Lime;

Upvotes: 1

Related Questions