简体   繁体   English

使应用程序窗口的背景透明

[英]Make transparent background of application window

I want to make transparent any application window not its contents using c# or vc++. 我想使用c#或vc ++使任何应用程序窗口而不是其内容透明。 For example If I opened my computer then it makes that window transparent from my application not folders. 例如,如果我打开计算机,那么它将使该窗口对我的应用程序(而不是文件夹)透明。

Set the Form properties 设置表单属性

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

To the Google: 致Google:

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

You can do this in Windows 7 easily, no code required. 您可以在Windows 7中轻松完成此操作,不需要任何代码。 For Win 200/XP, to the Google machine once more: 对于Win 200 / XP,再次连接到Google计算机:

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

bool m_bTracking; bool m_bTracking; // will be true when the mouse is // being tracked HWND m_hCurrWnd; //当跟踪鼠标//时为true HWND m_hCurrWnd; // Handle to the window over which // the mouse was last present HCURSOR m_hCursor; //处理到鼠标最后一次出现的窗口HCURSOR m_hCursor; // The wand cursor //魔杖光标

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

BOOL CWinTransDlg::OnInitDialog() { .... // get the function pointer for SetLayeredWindowAttributes // in User32.dll HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL")); BOOL CWinTransDlg :: OnInitDialog(){.... //在User32.dll中获取SetLayeredWindowAttributes的函数指针// HMODULE hUser32 = GetModuleHandle(_T(“ USER32.DLL”)); g_pSetLayeredWindowAttributes = (lpfn)GetProcAddress(hUser32, "SetLayeredWindowAttributes"); g_pSetLayeredWindowAttributes =(lpfn)GetProcAddress(hUser32,“ SetLayeredWindowAttributes”); if (g_pSetLayeredWindowAttributes == NULL) AfxMessageBox ( "Layering is not supported in this version of Windows", MB_ICONEXCLAMATION); 如果(g_pSetLayeredWindowAttributes == NULL)AfxMessageBox(“此版本的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(); void CWinTransDlg :: OnLButtonDown(UINT nFlags,CPoint point){... SetCapture(); // make mouse move events to // be directed to this window m_hCurrWnd = NULL; //使鼠标移动事件//定向到此窗口m_hCurrWnd = NULL; // Currently no window is to be made transparent m_bTracking = true; //当前没有任何窗口是透明的m_bTracking = true; // set the tracking flag ::SetCursor(m_hCursor); //设置跟踪标志:: 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); void CWinTransDlg :: OnMouseMove(UINT nFlags,CPoint point){... if(m_bTracking){... //将鼠标坐标转换为屏幕ClientToScreen(&point); ... // get the window at the mouse coords m_hCurrWnd = ::WindowFromPoint(point); ... //在鼠标坐标处获取窗口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(); void CWinTransDlg :: OnLButtonUp(UINT nFlags,CPoint point){... //停止跟踪鼠标ReleaseCapture(); m_bTracking = false; 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); } ... } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM