Windows 2000XP is transparent to the window

xiaoxiao2021-03-06  66

Windows 2000 / XP window transparent to the author: abhinaba Translation: Nanjing BC Foods Co., Ltd. Xiao Jin

Source: http://www.codeproject.com/dialog/winTrans1.as Phase Many articles Demonstrate hierarchical features using Windows 2000 / XP to implement the transparency of the window. This article can pass this feature to transpare any window, even if you don't have the source code of the program. Using the "Wintrans" program You can select any running programs, drag the left mouse button to drag the rod within the left upper box and press it on the title bar of the program, then let go, then the program can become transparent . You can adjust the position of the slider to control transparency. "Wintrans" has a very like SPY interface, and can also demonstrate the following usage of Win32 APIS: Use the mouse pointer positioning window to get window information such as class name, title, etc. Usage In Windows 2000 / XP, User32.dll adds a new function setlayeredWindowAttributes. To use this function, we must set the window style WS_EX_LAYERED (0x00080000) in the generated window or using the setWindowlong function. Once this style is set, we can call this function to transpare the window. The parameters required of this function are as follows:

HWND HWND: Window Handle ColorRef Col: Transparent Color Byte Balpha: = 0: Whole window Transparent, = 255 Experience DWORD DWFLAGS: = 1: Only Color COL Transparency, = 2: The window is transparent in accordance with the Balpha variable.

The code first defines the member variable of the dialog (Wintransdlg.h).

Bool m_btracking; // Set to true when the mouse is captured

HWnd m_hcurrwnd; // Handle of the window where the mouse is located

HCURSOR M_HCURSOR; / / Rod Code Handle

Also define a pointer to the setlayeredWindowAttributes function. This function is defined in user32.dll.

// Global variable

Typedef Bool (WinApi * LPFN) (HWND HWND, ColorRef Cr,

BYTE BALPHA, DWORD DWFLAGS;

LPFN G_PsetLayeredWindowAttribute;

Get the pointer to the SetLayeredWindowAttributes function in the OnInitDialog event and saved in G / PPSetlayeredWindowAttributes in Global Variables.

Bool cwinTransdlg :: oninitdialog ()

{

....

// Get the pointer in the function setlayeredWindowAttribute 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 a stick cursor

Hinstance HinstResource = AFXFINDRESOURCEHANDLE

MakeintResource (IDC_WAND), RT_Group_cursor;

m_hcursor = :: loadcursor (hinstresource, makeintresource; idc_wand);

...

}

Then define the trigger function of the event WM_LButtondown, WM_LButtonup, and WM_MOUSEMOVE. M_LButtondown event code is as follows:

Void CwinTransdlg :: ONLBUTTONDOWN (uint nflags, cpoint point)

{

...

SetCapture (); // The mouse capture is set to the specified window. When the mouse button is pressed, this window will receive all mouse inputs for // current application or the entire system.

m_hcurrwnd = null; // There is no window to transparent

m_btracking = true; // Set the TRACK flag

:: setCursor (m_hcursor); // change the cursor to a rod

}

WM_MOUSEMOVE event handler:

Void CwinTransdlg :: OnMousemove (uint nflags, cpoint points)

{

...

IF (m_btracking)

{

...

/ / Get the mouse position

ClientToscreen (& Point);

...

/ / Get the window handle below the mouse

m_hcurrwnd = :: windowfrompoint (point);

...

// Show information such as the window, title, etc.

...

}

...

}

Once the left mouse button is clicked in the window and does not release it, the pointer of the mouse will become a rod, and the information of the window will be displayed on the Wintrans window. When the left mouse button is released, the event WM_LBUTTONUP handler is called.

Void CwinTransdlg :: ONLBUTTONUP (UINT NFLAGS, CPOINT)

{

...

// Release mouse capture

Releasecapture ();

M_BTRACKING = FALSE;

// If the window below the mouse is not this program Wintrans, we will set the hierarchical style and transparency by setting the slider.

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;

}

...

}

转载请注明原文地址:https://www.9cbs.com/read-90521.html

New Post(0)