5

I would like to create pop-up windows (of a fixed size) like this:

pop-up windows

in my application using C#. I've looked into NativeWindow but I am not sure if this is the right way to do it. I want a window to behave exactly like the volume control or "connect to" window in Windows 7.

How can I accomplish this?

pnuts
  • 58,317
  • 11
  • 87
  • 139
zsalzbank
  • 9,685
  • 1
  • 26
  • 39

4 Answers4

4

Using WinForms, create a form and set the following:

Text = "";
FormBorderStyle = Sizable;
ControlBox = false;
MaximizeBox = false;
MinimizeBox = false;
ShowIcon = false;

Edit:

This does require the window be sizable, but you can cheat at that a little. Set the MinimumSize and MaximumSize to the desired size. This will prevent the user from resizing.

As Jeff suggested, you can also do this in CreateParams:

protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        unchecked
        {
            cp.Style |= (int)0x80000000;    // WS_POPUP
            cp.Style |= 0x40000;            // WS_THICKFRAME
        }
        return cp;
    }
}

In both cases, however, you'll still get a sizing cursor when you hover over the edges. I'm not sure how to prevent that from happening.

Jon B
  • 51,025
  • 31
  • 133
  • 161
  • Do you think it would be possible to capture some kind of window messages to disable the cursors? Thanks – zsalzbank May 12 '09 at 17:05
  • @codethis: I looked around a bit, and didn't find anything. There's bound to be a way, though. – Jon B May 12 '09 at 17:24
  • I was able to get rid of the resizing cursor by canceling WM_SETCURSOR. protected override void WndProc(ref Message m) { if (m.Msg == 0x20) { m.Result = (IntPtr)1; return; } base.WndProc(ref m); } That does it but leaves a weird side effect - the first time you hover over a border, the wait cursor shows up. Then when you move it into the client area it works correctly. Not sure how to fax that... – zsalzbank May 13 '09 at 05:12
2

In your CreateParams specify WS_POPUP and WS_THICKFRAME.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
2

I was able to accomplish this:

if (m.Msg == 0x84 /* WM_NCHITTEST */) {
    m.Result = (IntPtr)1;
    return;
}
base.WndProc(ref m);
0

To prevent the sizing cursors over the borders handle WM_NCHITTEST and when over the borders return HTBORDER.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
TK.
  • 1