BlackOut – Screen Dimmer

Downloads:

Executable
Source Code (C#)

Description:

BlackOut is a multi-monitor screen dimmer application.
This application was designed to reduce the brightness of your monitor or monitors, this can been extremely useful if you find yourself working in a dark environment, it is also very effective at offering a bit of privacy in crowded areas.

Screen Shot(s):

blackoutscreen

Notable Code:

Method used to grow form to cover all monitors

            /*
             * move through all the screens setting x and y to the lowest settings
             * then increase the form size to cover all screens.
             * Do NOT use WindowState or it will revert to one screen.
             */
            foreach (Screen tmpscr in Screen.AllScreens)
            {
                if (this.Location.X > tmpscr.WorkingArea.Location.X)
                {
                    tmpLocationX = tmpscr.WorkingArea.Location.X;
                }
                if (this.Location.Y > tmpscr.WorkingArea.Location.Y)
                {
                    tmpLocationY = tmpscr.WorkingArea.Location.Y;
                }
                tmpwidth += tmpscr.WorkingArea.Width;
                tmpheight += tmpscr.WorkingArea.Height;
            }

            this.Width = tmpwidth;
            this.Height = tmpheight;
            this.Location = new Point(tmpLocationX, tmpLocationY);

Class used to ensure config window snaps to start bar regardless of location

    public class taskBar
    {
        [DllImport("SHELL32", CallingConvention = CallingConvention.StdCall)]
        static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData);

        #region Struct RECT
        [StructLayout(LayoutKind.Sequential)]
        struct RECT
        {
            public int left;
            public int top;
            public int right;
            public int bottom;
        }
        #endregion

        #region Struct APPBARDATA
        [StructLayout(LayoutKind.Sequential)]
        struct APPBARDATA
        {
            public int cbSize;
            public IntPtr hWnd;
            public int uCallbackMessage;
            public int uEdge;
            public RECT rc;
            public IntPtr lParam;
        }
        #endregion

        #region Struct ABMsg
        enum ABMsg : int
        {
            ABM_NEW = 0,
            ABM_REMOVE = 1,
            ABM_QUERYPOS = 2,
            ABM_SETPOS = 3,
            ABM_GETSTATE = 4,
            ABM_GETTASKBARPOS = 5,
            ABM_ACTIVATE = 6,
            ABM_GETAUTOHIDEBAR = 7,
            ABM_SETAUTOHIDEBAR = 8,
            ABM_WINDOWPOSCHANGED = 9,
            ABM_SETSTATE = 10
        }
        #endregion

        #region Struct ABEdge
        enum ABEdge : int
        {
            ABE_LEFT = 0,
            ABE_TOP,
            ABE_RIGHT,
            ABE_BOTTOM
        }
        #endregion

        #region Enum ABState
        enum ABState : int
        {
            ABS_MANUAL = 0,
            ABS_AUTOHIDE = 1,
            ABS_ALWAYSONTOP = 2,
            ABS_AUTOHIDEANDONTOP = 3,
        }
        #endregion

        #region Enum TaskBarEdge
        public enum TaskBarEdge : int
        {
            Bottom,
            Top,
            Left,
            Right
        }
        #endregion

        public Point touchSysTray(Form Form)
        {
            int x=0, y = 0;

            APPBARDATA abd = new APPBARDATA();

            //use if you want to return a different point if the taskbar is autohiding
            #region TaskBar AutoHide Property
            #endregion

            uint ret = SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref abd);
            switch (abd.uEdge)
            {
                case (int)ABEdge.ABE_BOTTOM:
                    y = abd.rc.top - Form.Height;
                    x = abd.rc.right - Form.Width;
                    break;
                case (int)ABEdge.ABE_TOP:
                    y = abd.rc.bottom;
                    x = abd.rc.right - Form.Width;
                    break;
                case (int)ABEdge.ABE_LEFT:
                    y = abd.rc.bottom - Form.Height;
                    x = abd.rc.right;
                    break;
                case (int)ABEdge.ABE_RIGHT:
                    y = abd.rc.bottom - Form.Height;
                    x = abd.rc.left - Form.Width;
                    break;
            }
            return new Point(x, y);

        }
    }

  1. July 29th, 2010 at 03:41 | #1

    Blackout is great but I need to be able to dim monitor on multimonitor setup 1 monitor dim 1 monitor not dim is possible to add?

  2. July 29th, 2010 at 03:42 | #2

    To elaborate I would like to see a function which controls which monitor I can dim so I can have seperate controls per monitor.

  3. July 29th, 2010 at 13:49 | #3

    @Matt
    Thanks for the kind words and interest, that is an interesting idea, and I could see how it would be useful, I am currently a little to swamped to make that change, but when I get some free time, I’ll see if I can make the change. It honestly wouldn’t be to hard, I would just have to spawn a form for each monitor detected, resize the forms to fit their monitor, and then set up a method to control the opacity for each. The code is available, and love to see anyone else interested make the changes.

    If I do have the chance to make the changes I’ll post the results here and email you, once again thanks for your interest and feedback.

  1. No trackbacks yet.