Il codice sorgente per una versione precedente di Paint.Net è disponibile presso openpdn Fork of Paint.NET 3.36.7
ho cercato di estrarre i loro metodi da che il codice sorgente nel esempio di lavoro più concisa ero capace:
Pinvoking classe:
internal static class Win32 {
public const int WM_ACTIVATE = 0x006;
public const int WM_ACTIVATEAPP = 0x01C;
public const int WM_NCACTIVATE = 0x086;
[DllImport("user32.dll", SetLastError = false)]
internal static extern IntPtr SendMessageW(IntPtr hWnd, uint msg,
IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal extern static bool PostMessageW(IntPtr handle, uint msg,
IntPtr wParam, IntPtr lParam);
}
Modulo Base:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private bool ignoreNcActivate = false;
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
switch (m.Msg) {
case Win32.WM_NCACTIVATE:
if (m.WParam == IntPtr.Zero) {
if (ignoreNcActivate) {
ignoreNcActivate = false;
} else {
Win32.SendMessageW(this.Handle, Win32.WM_NCACTIVATE, new IntPtr(1), IntPtr.Zero);
}
}
break;
case Win32.WM_ACTIVATEAPP:
if (m.WParam == IntPtr.Zero) {
Win32.PostMessageW(this.Handle, Win32.WM_NCACTIVATE, IntPtr.Zero, IntPtr.Zero);
foreach (Form2 f in this.OwnedForms.OfType<Form2>()) {
f.ForceActiveBar = false;
Win32.PostMessageW(f.Handle, Win32.WM_NCACTIVATE, IntPtr.Zero, IntPtr.Zero);
}
ignoreNcActivate = true;
} else if (m.WParam == new IntPtr(1)) {
Win32.SendMessageW(this.Handle, Win32.WM_NCACTIVATE, new IntPtr(1), IntPtr.Zero);
foreach (Form2 f in this.OwnedForms.OfType<Form2>()) {
f.ForceActiveBar = true;
Win32.SendMessageW(f.Handle, Win32.WM_NCACTIVATE, new IntPtr(1), IntPtr.Zero);
}
}
break;
}
}
protected override void OnShown(EventArgs e) {
base.OnShown(e);
Form2 f = new Form2();
f.Show(this);
}
}
Sempre attivo Form2 (a meno che l'app non sia attiva):
public partial class Form2 : Form {
internal bool ForceActiveBar { get; set; }
public Form2() {
InitializeComponent();
this.ShowInTaskbar = false;
this.ForceActiveBar = true;
}
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == Win32.WM_NCACTIVATE) {
if (this.ForceActiveBar && m.WParam == IntPtr.Zero) {
Win32.SendMessageW(this.Handle, Win32.WM_NCACTIVATE, new IntPtr(1), IntPtr.Zero);
}
}
}
}
Non è necessario impostare TopMost su true per Form2 poiché dovrebbe essere di proprietà dal modulo principale quando viene visualizzato. Inoltre, Form2 non è un modulo figlio MDI.
Cosa ti fa pensare che abbia sempre al centro? Non è così. Una volta cliccato all'interno della finestra principale, l'attenzione è sparita. Stai cercando di nascondere la visualizzazione della finestra focalizzata? Perché questa è la differenza che posso vedere riguardo a queste finestre degli strumenti. – dowhilefor
Allora devo essere ingenuo. Tutte le finestre degli strumenti hanno l'aspetto mirato a loro. Anche i controlli nelle finestre degli strumenti sembrano raccogliere correttamente gli eventi di hover. – Darkzaelus
Ecco cosa intendevo per visualizzazione. Sembrano concentrati. Ma non reagiscono più alla messa a fuoco della tastiera, possono essere testati con la finestra dei colori e la casella combinata. Hai provato a impostare il proprietario sulla finestra principale e a dare lo stile della finestra degli strumenti? – dowhilefor