Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am developing C# application for that i need to use setWindowLong & getWindowLong. I wish to know more about it. Does it help to make From control transparent?

Thanks!!!
Posted

1 solution

Yes. Use this in your ToolStripRenderer class

C#
// WINAPI Constants
private const int GWL_EXSTYLE = -20;
private const int WS_EX_LAYERED = 0x80000;
private const int LWA_ALPHA = 2;

// WINAPI Functions
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hwnd, int nIndex);

[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);

[DllImport("user32.dll")]
private static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

public static void ApplyMenuTransparency(IntPtr Handle, byte Transparency)
{
    SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) | WS_EX_LAYERED);
    SetLayeredWindowAttributes(Handle, 0, Transparency, LWA_ALPHA);
}

protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
    if (e.Item.IsOnDropDown)
        Manager.ApplyMenuTransparency(e.ToolStrip.Handle, this.MenuTransparency);
    base.OnRenderMenuItemBackground(e);
}
 
Share this answer
 
v2
Comments
Frederic GIRARDIN 6-Jun-17 6:17am    
Does it still work with 64bits system ? As VB.net developper, I'm looking for reading and changing windows style before setting a panel as new parent for external windows by using setparent API, to be able to give window style back to initial, event if i break parent link. Can't find both declaration (32/64) for both function (get/set).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900