Ejemplo n.º 1
0
        /// <summary>
        /// Creates the helper message window that is used to receive messages from the taskbar icon.
        /// </summary>
        private void CreateMessageWindow()
        {
            // Generate a unique ID for the window
            WindowClassId = "MP2-ServiceeMonitor_" + DateTime.Now.Ticks;

            // Register window message handler
            _messageHandler = OnWindowMessageReceived;

            // Create a simple window class which is reference through the messageHandler delegate
            WindowClass wc;

            wc.style         = 0;
            wc.lpfnWndProc   = _messageHandler;
            wc.cbClsExtra    = 0;
            wc.cbWndExtra    = 0;
            wc.hInstance     = IntPtr.Zero;
            wc.hIcon         = IntPtr.Zero;
            wc.hCursor       = IntPtr.Zero;
            wc.hbrBackground = IntPtr.Zero;
            wc.lpszMenuName  = "";
            wc.lpszClassName = WindowClassId;

            // Register the window class
            WinApi.RegisterClass(ref wc);

            // Create the message window
            MessageWindowHandle = WindowsAPI.CreateWindowEx(0, WindowClassId, "", 0, 0, 0, 1, 1, 0, 0, 0, 0);

            if (MessageWindowHandle == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }