I have been looking for the answer for 7 hours. So a quick google isn't going to cap this one. I Am working on a programming notepad app with intellisense like Visual Studio. only I have run into a big issue. In Visual studio the little intellisense window is its own form. Thats no problem, But notice that the little window doesn't take focus when it opens. Thats no problem either right? ShowWindow with a shownotactivate flag. but NOTICE that when you click on the little window. it changes selection but STILL doesn't activate! I can't seem to reproduce that.

I found a exStyle called WS_EX_NOACTIVATE. All over the net it says this does what I want. And in fact it DOES! but only if its created on the MAIN form of an application. have 2 or more forms, if they aren't all WS_EX_NOACTIVATE, then none of them are. End of story.

If someone could show the light, on how this could be done in C#. I would appreciate it. I'm about shot. I don't want to give up. But I might have to use a floating List view like the rest of the internet community has. I just really would like to see this work.

Keep in mind that I am using windows 7. some of the code examples I have found might work on older systems. but not mine. Also. however Visual studio does it, it works on windows7.

try this.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;

namespace ExampleApp
{
    class Program : Form
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Program());
        }

        TextBox m_textBox;
        Program()
        {
            int x = 0;
            int y = 0;
            foreach (string line in new string[] {
                "1234567890", "QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM "})
            {
                foreach (char cur in line)
                {
                    Button button = new Button();
                    button.Location = new Point(x * 25, y * 25);
                    button.Size = new Size(23, 23);
                    button.Text = cur.ToString();
                    button.Click += new EventHandler(Button_Click);
                    Controls.Add(button);
                    x++;
                }
                x = 0;
                y++;
            }

            m_textBox = new TextBox();
            m_textBox.Top = 25 * 4;
            m_textBox.Size = new Size(25 * 10, 23);
            Controls.Add(m_textBox);
            ClientSize = new Size(25 * 10, 25 * 5);
            TopMost = true;
        }

        void Button_Click(object sender, EventArgs e)
        {
            m_textBox.Text = ((Button)sender).Text;
            SendKeys.Send(m_textBox.Text);
        }

        const int WS_EX_NOACTIVATE = 0x8000000;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams ret = base.CreateParams;
                ret.ExStyle |= WS_EX_NOACTIVATE;
                return ret;
            }
        }


    }
}

Compile that simple code and you have a little onscreenkeyboard that will never take focus, but will work just fine. allowing you to click its little buttons with other windows focused.

now create a new windows forms app and open that form from a 2nd one. see that it no longer works.

OK, I have made a small breakthrough. but it doesn't help me. The window Given WS_EX_NOACTIVATE responds correctly as long as no other windows from the same application that don't implement WS_EX_NOACTIVATE have focus.

That is to say, if I have a form that has a button that spawns WS_EX_NOACTIVATE forms, those forms act normally until the main form is minimized. then they act as expected. maximize the main form and they act normal again.

any ideas why? I need the WS_EX_NOACTIVATE window to display infront of the main window allowing me to choose data without leaving the focus of my text box.

I figured it out. Needed to create params for WS_Child, WS_THICKBORDER and then WS_EX_NOACTIVAVE and WS_EX_TOOLWINDOW.

I did this trial and error for an hour before I got what I needed. Also important to note. Setting the location of the form didn't seem to move it. so setting the size int the override create params worked for setting the initial position.

here is a dirty drop in solution for anyone else who needs this.

const int WS_EX_NOACTIVATE = 0x8000000;
        private const int WS_EX_TOOLWINDOW = 0x00000080;

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams ret = base.CreateParams;
                ret.Style = (int) WindowStyles.WS_THICKFRAME | (int)WindowStyles.WS_CHILD;
                ret.ExStyle |= WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW;
                ret.X = this.Location.X;
                ret.Y = this.Location.Y;
                //ret.Parent = IntPtr.Zero;
                return ret;
            }
        }


        [Flags]
        enum WindowStyles : uint
        {
            WS_OVERLAPPED = 0x00000000,
            WS_POPUP = 0x80000000,
            WS_CHILD = 0x40000000,
            WS_MINIMIZE = 0x20000000,
            WS_VISIBLE = 0x10000000,
            WS_DISABLED = 0x08000000,
            WS_CLIPSIBLINGS = 0x04000000,
            WS_CLIPCHILDREN = 0x02000000,
            WS_MAXIMIZE = 0x01000000,
            WS_BORDER = 0x00800000,
            WS_DLGFRAME = 0x00400000,
            WS_VSCROLL = 0x00200000,
            WS_HSCROLL = 0x00100000,
            WS_SYSMENU = 0x00080000,
            WS_THICKFRAME = 0x00040000,
            WS_GROUP = 0x00020000,
            WS_TABSTOP = 0x00010000,

            WS_MINIMIZEBOX = 0x00020000,
            WS_MAXIMIZEBOX = 0x00010000,

            WS_CAPTION = WS_BORDER | WS_DLGFRAME,
            WS_TILED = WS_OVERLAPPED,
            WS_ICONIC = WS_MINIMIZE,
            WS_SIZEBOX = WS_THICKFRAME,
            WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,

            WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | 

WS_MAXIMIZEBOX,
            WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
            WS_CHILDWINDOW = WS_CHILD,

            //Extended Window Styles

            WS_EX_DLGMODALFRAME = 0x00000001,
            WS_EX_NOPARENTNOTIFY = 0x00000004,
            WS_EX_TOPMOST = 0x00000008,
            WS_EX_ACCEPTFILES = 0x00000010,
            WS_EX_TRANSPARENT = 0x00000020,

            //#if(WINVER >= 0x0400)

            WS_EX_MDICHILD = 0x00000040,
            WS_EX_TOOLWINDOW = 0x00000080,
            WS_EX_WINDOWEDGE = 0x00000100,
            WS_EX_CLIENTEDGE = 0x00000200,
            WS_EX_CONTEXTHELP = 0x00000400,

            WS_EX_RIGHT = 0x00001000,
            WS_EX_LEFT = 0x00000000,
            WS_EX_RTLREADING = 0x00002000,
            WS_EX_LTRREADING = 0x00000000,
            WS_EX_LEFTSCROLLBAR = 0x00004000,
            WS_EX_RIGHTSCROLLBAR = 0x00000000,

            WS_EX_CONTROLPARENT = 0x00010000,
            WS_EX_STATICEDGE = 0x00020000,
            WS_EX_APPWINDOW = 0x00040000,

            WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE),
            WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST),

            //#endif /* WINVER >= 0x0400 */

            //#if(WIN32WINNT >= 0x0500)

            WS_EX_LAYERED = 0x00080000,

            //#endif /* WIN32WINNT >= 0x0500 */

            //#if(WINVER >= 0x0500)

            WS_EX_NOINHERITLAYOUT = 0x00100000, // Disable inheritence of mirroring by children
            WS_EX_LAYOUTRTL = 0x00400000, // Right to left mirroring

            //#endif /* WINVER >= 0x0500 */

            //#if(WIN32WINNT >= 0x0500)

            WS_EX_COMPOSITED = 0x02000000,
            WS_EX_NOACTIVATE = 0x08000000

            //#endif /* WIN32WINNT >= 0x0500 */

        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.