Non posso impostare la trasparenza di una finestra per il manico in C #?
-
13-09-2019 - |
Domanda
sto cercando di impostare la trasparenza di tutte le finestre. Ho seguente codice.
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public const int GWL_EXSTYLE = -20;
public const int WS_EX_LAYERED = 0x80000;
public const int LWA_ALPHA = 0x2;
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
SetWindowLong(theprocess.Handle, GWL_EXSTYLE,
GetWindowLong(theprocess.Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED);
SetLayeredWindowAttributes(theprocess.Handle, 0, 128, LWA_ALPHA);
}
}
}
non succede nulla quando eseguo il codice.
Quello che non va ??
Soluzione
SetWindowLong
prende un handle di finestra (hWnd), ma si sta passando un handle di processo, invece.
Modificare tutte le istanze di
theprocess.Handle
a
theProcess.MainWindowHandle
Dopo la modifica che, ha funzionato sulla macchina Windows XP ho testato su. Ora dovro 'di modificare il codice per ottenere le finestre di nuovo al normale;) Per fortuna, il Visual Studio 2010 finestra era inalterato
.Altri suggerimenti
Questa parte del codice: ^ WS_EX_LAYERED
ribalta il bit WS_EX_LAYERED,
Penso che si desidera: | WS_EX_LAYERED
Hai provato a impostare l'opacità ?
this.Opacity = 0.50;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow