コード例 #1
0
        public static bool TryRegisterHotKey(HwndSource hwndSource, int HOTKEY_ID, ModifierCode modifiers, VirtualKeyCode key, Action OnHotKeyPressed)
        {
            IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
            {
                const int WM_HOTKEY = 0x0312;

                switch (msg)
                {
                case WM_HOTKEY:
                    if (wParam.ToInt32() == HOTKEY_ID)
                    {
                        OnHotKeyPressed();
                        handled = true;
                    }
                    break;
                }
                return(IntPtr.Zero);
            };
            hwndSource.AddHook(HwndHook);

            if (!PInvoke.RegisterHotKey((HWND)hwndSource.Handle, HOTKEY_ID, (uint)modifiers, (uint)key))
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Get the combined modifier code for the coding scheme.
        /// </summary>
        /// <param name="symbolCode">the symbol code</param>
        /// <returns>a friendly name for the combined modifier code</returns>
        public static string GetName(string symbolCode)
        {
            if (!SymbolData.Check(ref symbolCode))
            {
                return(string.Empty);
            }

            char leadCode  = ModifierCode.GetCode(symbolCode);
            char trailCode = Echelon.GetCode(symbolCode);

            if (leadCode == ModifierCode.Mobility || leadCode == ModifierCode.Towed)
            {
                return(Mobility.GetName(symbolCode));
            }

            if (leadCode == ModifierCode.Installation)
            {
                return((trailCode == 'B') ? "Feint Dummy Installation" : "Installation");
            }

            string mod = ModifierCode.GetName(symbolCode);
            string ech = Echelon.GetName(symbolCode);

            if (string.IsNullOrEmpty(mod) || string.IsNullOrEmpty(ech))
            {
                return(string.Empty);
            }

            if (mod == "None" && ech == "None")
            {
                return(string.Empty);
            }

            if (mod == "None")
            {
                return(ech);
            }

            if (ech == "None")
            {
                return(mod);
            }

            return(mod + "\n" + ech);
        }
コード例 #3
0
ファイル: MilHats.cs プロジェクト: HillHouse/MilSym
        /// <summary>
        /// Generates the correct combination of task force, installation, and feint dummy for a symbol.
        /// </summary>
        /// <param name="ms">
        /// The symbol to which the generated rendering is attached.
        /// </param>
        /// <param name="symbolCode">
        /// The symbol code for the given symbol
        /// </param>
        /// <returns>
        /// The maximum height of the generated rendering.
        /// </returns>
        internal static double Generate(MilSymbol ms, string symbolCode)
        {
            // This is the maximum height generated by this combination of pieces
            Rect r = ms.BaseRect;

            if (r.IsEmpty)
            {
                return(0);
            }

            double height = r.Top;

            if (!SymbolData.Check(ref symbolCode))
            {
                return(height);
            }

            char code = ModifierCode.GetCode(symbolCode);

            switch (code)
            {
            case ModifierCode.Headquarters:     // headquarters
                ms.AddChild("HQ", GenerateHeadquarters(ms));
                break;

            case ModifierCode.TaskForceHeadquarters:     // task force, headquarters
                ms.AddChild("TF", GenerateTaskForce(ms, out height));
                ms.AddChild("HQ", GenerateHeadquarters(ms));
                break;

            case ModifierCode.FeintDummyHeadquarters:     // feint dummy, headquarters
                ms.AddChild("FD", GenerateFeintDummy(ms, ref height));
                ms.AddChild("HQ", GenerateHeadquarters(ms));
                break;

            case ModifierCode.FeintDummyTaskForceHeadquarters:     // feint dummy, task force, headquarters
                ms.AddChild("TF", GenerateTaskForce(ms, out height));
                ms.AddChild("FD", GenerateFeintDummy(ms, ref height));
                ms.AddChild("HQ", GenerateHeadquarters(ms));
                break;

            case ModifierCode.TaskForce:     // task force
                ms.AddChild("TF", GenerateTaskForce(ms, out height));
                break;

            case ModifierCode.FeintDummy:     // feint dummy
                ms.AddChild("FD", GenerateFeintDummy(ms, ref height));
                break;

            case ModifierCode.FeintDummyTaskForce:     // feint dummy/task force
                ms.AddChild("TF", GenerateTaskForce(ms, out height));
                ms.AddChild("FD", GenerateFeintDummy(ms, ref height));
                break;

            case ModifierCode.Installation:     // installation
                ms.AddChild("Installation", GenerateInstallation(ms, out height));

                // There is an unfortunate overloading of the echelon character in the standard
                if (Echelon.GetCode(symbolCode) == 'B')
                {
                    ms.AddChild("FD", GenerateFeintDummy(ms, ref height));
                }

                break;

            case ModifierCode.Mobility:  // mobility
            case ModifierCode.Towed:     // towed
                break;
            }

            return(height);
        }