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

时间:2012-07-06 13:16:27

标签: c# vb.net visual-c++

我想使用c#或vc ++使任何应用程序窗口透明而不是其内容。例如,如果我打开计算机,那么它会使我的应用程序而不是文件夹透明。

2 个答案:

答案 0 :(得分:1)

设置表单属性

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

答案 1 :(得分:0)

致Google:

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

您可以轻松地在Windows 7中执行此操作,无需代码。对于Win 200 / XP,再次使用Google机器:

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

  

bool m_bTracking; //当鼠标是真的时候会是真的                       //被跟踪HWND m_hCurrWnd; //处理到哪个窗口                       //老鼠最后出席HCURSOR m_hCursor; //魔杖光标

     

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

     

BOOL CWinTransDlg :: OnInitDialog(){       ....       //获取SetLayeredWindowAttributes的函数指针       //在User32.dll中       HMODULE hUser32 = GetModuleHandle(_T(“USER32.DLL”));       g_pSetLayeredWindowAttributes =(lpfn)GetProcAddress(hUser32,                  “SetLayeredWindowAttributes”);       if(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(); //使鼠标移动事件                          //被引导到这个窗口       m_hCurrWnd = NULL; //目前没有窗口是透明的       m_bTracking = true; //设置跟踪标志       ::的setCursor(m_hCursor); //将鼠标指针转到魔杖光标       ......}

     

void CWinTransDlg :: OnMouseMove(UINT nFlags,CPoint point){       ...       if(m_bTracking)       {           ...           //将鼠标坐标转换为屏幕           ClientToScreen(安培;点);           ...           //在鼠标坐标处找到窗口           m_hCurrWnd = :: WindowFromPoint(point);           ...           //显示窗口的详细信息,如类,标题等。           ...       }       ......}

     

void CWinTransDlg :: OnLButtonUp(UINT nFlags,CPoint point){       ...       //停止跟踪鼠标       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);
}
... }