Controlling Charms...

Superfly

Developer
VIP Member
Guru
Messages
1,099
Location
Cape Town
After an initial attempt here at getting to grips with the Charms bar being an intrusion... I dug a bit deeper and did some alternate coding on disabling Charms...(primarily as the current solution causes a flash of the foreground window's title bar when Charms gets hidden)

First I tried killing the Charms process itself - but Windows explorer went nuts and restarted itself (with Charms - further proof that Charms is fully integrated therein)

I have thus far not found a way to deactivate Charms without some negative effect .. I recoded the method to hide the Charms bar but this removes focus from the foreground window and requires adddition user interaction (tap/click the current window to re-focus)

See the code below... NB: uncommenting the SendMessage line (and commenting out the SetWindowsPos line gives the flash effect - i.e moves focus back to the initial window)

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;

namespace NoCharm
{

   class Program
    {

        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern short GetKeyState(int keyCode); // Will be used to re-enable Win+C

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

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        static extern bool SetWindowPos(
             int hWnd,             // Window handle
             int hWndInsertAfter,  // Placement-order handle
             int X,                // Horizontal position
             int Y,                // Vertical position
             int cx,               // Width
             int cy,               // Height
             uint uFlags);         // Window positioning flags

        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_CLOSE = 0xF060;
        public const int SC_MINIMIZE = 0xF020;  //used with WM_SYSCOMMAND has the same effect as SetWindowPos and SMP_NOMOVE  
        public const uint SWP_NOMOVE = 0x0002 ;

         static void Main(string[] args)
        {
            try
                {
                    while (true)
                    {
                       IntPtr hWndCharmBar = FindWindowByCaption(IntPtr.Zero, "Charm Bar");
                       IntPtr hWndCharmClock = FindWindowByCaption(IntPtr.Zero, "Clock and Date");
                       SetWindowPos((int)hWndCharmBar,0, 0, 0, 0, 0, SWP_NOMOVE);
                       //SendMessage(hWndCharmClock, WM_SYSCOMMAND, SC_CLOSE, 0);
                       //SendMessage(hWndCharmBar, WM_SYSCOMMAND, SC_CLOSE, 0);
                       Thread.Sleep(10); // sleep to save CPU resources... uses 0% CPU and 1.7 MB RAM
                    }
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }
            Process.GetCurrentProcess().WaitForExit();
        }
    }
}

Download binary.
 

My Computer

System One

  • OS
    PC-DOS v1.0
    Computer type
    PC/Desktop
    System Manufacturer/Model
    IBM
    CPU
    Intel 8088, 4.77MHz
    Memory
    16K, 640K max
    Graphics Card(s)
    What's that?
    Sound Card
    Not quite
    Screen Resolution
    80 X 24 text
    Hard Drives
    dual 160KB 5.25-inch disk drives
Ya that's the basic stuff... there are drivers that do not disable the right swipe...
 

My Computer

System One

  • OS
    PC-DOS v1.0
    Computer type
    PC/Desktop
    System Manufacturer/Model
    IBM
    CPU
    Intel 8088, 4.77MHz
    Memory
    16K, 640K max
    Graphics Card(s)
    What's that?
    Sound Card
    Not quite
    Screen Resolution
    80 X 24 text
    Hard Drives
    dual 160KB 5.25-inch disk drives
Back
Top