BlackOut – Screen Dimmer

April 16th, 2011 Leave a comment Go to comments

Downloads:

Executable XP
Source Code (C#)

Executable Vista/Win 7
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
**Win 7 uses Bounds in place of WorkingArea

            /*
             * 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.

  4. V
    April 4th, 2011 at 03:07 | #4

    I like this program. I wish that it dimmed the taskbar as well, though.

    • April 16th, 2011 at 01:11 | #5

      @V
      This application has been updated, it should now properly cover the toolbar section in windows 7 and Vista
      New version Win 7 update

  5. stealz
    June 15th, 2011 at 18:36 | #6

    I would also love to see an option to control the dimming of monitors individually, for example when I watch movies or play games on one, being able to dim the other.

    This would also be helpful so you could adjust the monitors to eachother if they have different brightness

  6. Adam
    January 5th, 2012 at 09:09 | #7

    Just what I was looking for, thanks!

  7. Adam
    January 5th, 2012 at 09:09 | #8

    @stealz
    I agree, that would be useful.

  8. Adam
    January 5th, 2012 at 09:11 | #9

    It would be nice to have an option to toggle whether or not to dim the taskbar.

    • January 14th, 2012 at 15:57 | #10

      this functionality is currently available from the tray icon, I haven’t ported the code to use win7 method for adding functionality to the taskbar, and probably won’t be anytime soon, sorry of the inconvenience

  9. Desmond
    March 16th, 2012 at 10:15 | #11

    Can you program it to dim monitors that currently do not have the mouse or cursor on?
    I have three monitors, each of them large, One is used purely as a reference list/alert monitor. Idealy, if I see an alert popup and I move my mouse over to that monitor it would dim the other two monitors.

    • March 16th, 2012 at 10:19 | #12

      Sadly, the way the dimming is being done, this would be rather difficult, as all dimming is applied to all screens by the same form, if I rewrite the application, I will keep this in mind as a requirement, but currently don’t have a timeline for the rewrite. Thanks for your comment.

  10. Desmond
    March 16th, 2012 at 10:20 | #13

    @Desmond
    I thought about this after I submitted. If the above can be done an “instant dim” may not be desired, maybe a fade, as you move from monitor to monitor it fades to the desired dim level. But moving back it’s instantly bright again.

  11. Desmond
    March 16th, 2012 at 10:22 | #14

    Ah thank you for your quick reply :) It’s fair enough I do like the dimmer, and will use it for the moment, but if a multi-dimming active bright app is found I’ll most likely use that, even if it cost money. I’m suffering from a little eye strain so I’d rather dim monitors then that at least for the time being.

  12. Spencer Hatch
    November 28th, 2012 at 15:08 | #15

    Excellent. Very helpful! Thanks for making this available.

  1. No trackbacks yet.