Exemplo n.º 1
0
        private bool RegisterWindowClass(string windowClassName)
        {
            Console.WriteLine("RegisterWindowClass with className : " + windowClassName);
            // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633577(v=vs.85).aspx
            WNDCLASSEX wind_class = new WNDCLASSEX
            {
                cbSize      = Marshal.SizeOf(typeof(WNDCLASSEX)),
                style       = (int)(ClassStyles.CS_HREDRAW | ClassStyles.CS_VREDRAW),
                lpfnWndProc = Marshal.GetFunctionPointerForDelegate(delegWndProc),
                cbClsExtra  = 0,
                cbWndExtra  = 0,
                hInstance   = Marshal.GetHINSTANCE(GetType().Module),
                hIcon       = NativeMethods.LoadIcon(IntPtr.Zero, (int)SystemIcons.IDI_WARNING),
                hCursor     = NativeMethods.LoadCursor(IntPtr.Zero, (int)IDC_STANDARD_CURSORS.IDC_ARROW),

                // (IntPtr)COLOR.ACTIVECAPTION; Zero pointer will cause background to be 'null' that will help to avoid blinks. IntPtr.Zero
                hbrBackground = (IntPtr)COLOR.BACKGROUND + 2,
                lpszMenuName  = windowClassName,
                lpszClassName = windowClassName,
                hIconSm       = IntPtr.Zero
            };

            ushort regResult = NativeMethods.RegisterClassEx(ref wind_class);

            Console.WriteLine("RegisterWindowClass: " + regResult);

            if (regResult == 0)
            {
                uint error = NativeMethods.GetLastError();
                Console.WriteLine("RegisterWindowClass: error : " + error);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
 internal static extern ushort RegisterClassEx(ref WNDCLASSEX lpWndClass);