C #: Getting a shortcut entered in a panel with application status status to display

I am writing a .Net COM DLL that runs inside a native Windows application.

I am trying to add an additional panel to this application status bar and it does not have any specific implementation, so I am trying to subclass the application status panel myself.

I am using the Win32 API SetParent () to switch the parent of a label control from a .Net form to an instance of msctls_statusbar32. I used the shortcut because it is the closest implementation for my own “static” control class, which I could find without writing my own control.

Somehow I even managed to get NativeWindow to successfully connect to both the status bar and my messages with tags (although at the moment it just passes them to all the next WndProc), and I assigned the appropriate styles and styleExs to my label window, and I I can see my label as a child with msctls_statusbar32 as a parent. Everything looks as if it should work correctly, but it is not. My control does not appear in the status bar of the parent application.

I do not understand why he does not appear. Almost everything that I can think of matches correctly is provided, the class for my shortcut is "WindowsForms10.STATIC.app.0.378734a" and not "static", but except that it is on the correct process and thread, it has the corresponding a stylesheet (at least a hexadecimal value ... Spy ++ seems to list them differently), and for all purposes it combines quite a bit with the rest of the controls. Does anyone know what else needs to be done to make this visible?

(I initially went along the CreateWindowEx path and set up WNDPROC callbacks, but I couldn’t get the application to work ... it will freeze for a minute or so and then unfreeze, and I would notice that my window disappeared from the tree window)

Thank!

0
3

, ... X Y . (0, 0), ! , : # WinForms .Net COM-

0

; , reset ; , , . , : msdn

, , . # com, win32, , , .

    [ComVisible(true)]
    [Guid("CC5B405F-F3CD-417E-AA00-4638A12A2E94"),
    ClassInterface(ClassInterfaceType.None)]
    public class TestInterface : ITestInterface // see declaration of the interface below
    {
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, IntPtr lParam);

        public const int SB_SETTEXT = 1035;
        public const int SB_SETPARTS = 1028;
        public const int SB_GETPARTS = 1030;

        public unsafe void Test()
        {
            IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
            // find status bar control on the main window of the application
            IntPtr statusBarHandle = FindWindowEx(mainWindowHandle, IntPtr.Zero, "msctls_statusbar32", IntPtr.Zero);
            if (statusBarHandle != IntPtr.Zero)
            {
                // set text for the existing part with index 0
                IntPtr text = Marshal.StringToHGlobalAuto("test text 0");
                SendMessage(statusBarHandle, SB_SETTEXT, 0, text);
                Marshal.FreeHGlobal(text);

                // create new parts width array
                int nParts = SendMessage(statusBarHandle, SB_GETPARTS, 0, IntPtr.Zero).ToInt32();
                nParts++;
                IntPtr memPtr = Marshal.AllocHGlobal(sizeof(int) * nParts);
                int partWidth = 100; // set parts width according to the form size
                for (int i = 0; i < nParts; i++)
                {
                    Marshal.WriteInt32(memPtr, i*sizeof(int), partWidth);
                    partWidth += partWidth;
                }
                SendMessage(statusBarHandle, SB_SETPARTS, nParts, memPtr);
                Marshal.FreeHGlobal(memPtr);

                // set text for the new part
                IntPtr text0 = Marshal.StringToHGlobalAuto("new section text 1");
                SendMessage(statusBarHandle, SB_SETTEXT, nParts-1, text0);
                Marshal.FreeHGlobal(text0);
            }
        }
    }

    [ComVisible(true)]
    [Guid("694C1820-04B6-4988-928F-FD858B95C880")]
    public interface ITestInterface
    {
       [DispId(1)]
       void Test();
    }

, ,

+2

For many reasons:

  • The .Net Label control explodes when it finds that it does not have a WinForms parent.
  • A custom status bar draws a shortcut control due to an incorrect Z-Order.
  • Label control is not displayed.
0
source

All Articles