G
Guest
Hi Folks
I'm trying to create a popup window on a Form by overriding the CreateParams property of a control.
I can get all the functionality of this to work in my application but for one little problem. Thi
is that when I select something on the popup my application deactivates (the title bar goes faint)
How do I stop this from happening. Any help with this would be much appreciated
Thanks in advanc
Jon Rushwort
A simplified example of the code is as follows
using System
using System.Drawing
using System.Windows.Forms
namespace PopupExampl
public enum WindowStyles : uin
WS_POPUP = 0x8000000
public enum WindowExStyle
WS_EX_TOPMOST = 0x00000008
WS_EX_TOOLWINDOW = 0x0000008
public enum MouseActivateFlag
MA_NOACTIVATE =
public enum Msg
WM_MOUSEACTIVATE = 0x002
public class PopupList : Contro
private ListBox listBox = new ListBox()
public PopupList(
listBox.Size=new Size(100,100)
listBox.Location=new Point(0,0)
listBox.Items.AddRange(new object[]{"Bashful", "Doc", "Sleepy", "Sneezy", "Happy", "Dopey", "Grumpy"})
Controls.Add(listBox)
protected override CreateParams CreateParams
ge
CreateParams createParams = new CreateParams()
// Define the screen position and siz
createParams.X = Location.X
createParams.Y = Location.Y
createParams.Height = Size.Height
createParams.Width = Size.Width
// As a top-level window it has no paren
createParams.Parent = IntPtr.Zero
// Appear as a pop-up windo
createParams.Style = unchecked((int)WindowStyles.WS_POPUP)
createParams.ExStyle = (int)WindowExStyles.WS_EX_TOPMOST +
(int)WindowExStyles.WS_EX_TOOLWINDOW
return createParams
protected override void WndProc(ref Message m
if (m.Msg == (int)Msgs.WM_MOUSEACTIVATE
m.Result = (IntPtr)MouseActivateFlags.MA_NOACTIVATE
els
base.WndProc(ref m)
public class frmMain : System.Windows.Forms.For
private PopupList popupList = new PopupList()
public frmMain(
popupList.CreateControl()
Text="Popup Example (Click the Form)"
Click+=new EventHandler(OnClick)
private void OnClick(object sender, System.EventArgs e
popupList.Location=Cursor.Position
popupList.Size=new Size(100,100)
popupList.Show()
[STAThread
static void Main()
Application.Run(new frmMain())
I'm trying to create a popup window on a Form by overriding the CreateParams property of a control.
I can get all the functionality of this to work in my application but for one little problem. Thi
is that when I select something on the popup my application deactivates (the title bar goes faint)
How do I stop this from happening. Any help with this would be much appreciated
Thanks in advanc
Jon Rushwort
A simplified example of the code is as follows
using System
using System.Drawing
using System.Windows.Forms
namespace PopupExampl
public enum WindowStyles : uin
WS_POPUP = 0x8000000
public enum WindowExStyle
WS_EX_TOPMOST = 0x00000008
WS_EX_TOOLWINDOW = 0x0000008
public enum MouseActivateFlag
MA_NOACTIVATE =
public enum Msg
WM_MOUSEACTIVATE = 0x002
public class PopupList : Contro
private ListBox listBox = new ListBox()
public PopupList(
listBox.Size=new Size(100,100)
listBox.Location=new Point(0,0)
listBox.Items.AddRange(new object[]{"Bashful", "Doc", "Sleepy", "Sneezy", "Happy", "Dopey", "Grumpy"})
Controls.Add(listBox)
protected override CreateParams CreateParams
ge
CreateParams createParams = new CreateParams()
// Define the screen position and siz
createParams.X = Location.X
createParams.Y = Location.Y
createParams.Height = Size.Height
createParams.Width = Size.Width
// As a top-level window it has no paren
createParams.Parent = IntPtr.Zero
// Appear as a pop-up windo
createParams.Style = unchecked((int)WindowStyles.WS_POPUP)
createParams.ExStyle = (int)WindowExStyles.WS_EX_TOPMOST +
(int)WindowExStyles.WS_EX_TOOLWINDOW
return createParams
protected override void WndProc(ref Message m
if (m.Msg == (int)Msgs.WM_MOUSEACTIVATE
m.Result = (IntPtr)MouseActivateFlags.MA_NOACTIVATE
els
base.WndProc(ref m)
public class frmMain : System.Windows.Forms.For
private PopupList popupList = new PopupList()
public frmMain(
popupList.CreateControl()
Text="Popup Example (Click the Form)"
Click+=new EventHandler(OnClick)
private void OnClick(object sender, System.EventArgs e
popupList.Location=Cursor.Position
popupList.Size=new Size(100,100)
popupList.Show()
[STAThread
static void Main()
Application.Run(new frmMain())