Exemplo n.º 1
0
        static BitmapSource GetWindowIcon(IntPtr windowHandle)
        {
            var hIcon = default(IntPtr);

            hIcon = WindowApi.SendMessage(windowHandle, (int)Message.WM_GETICON, WindowApi.ICON_BIG, IntPtr.Zero);

            if (hIcon == IntPtr.Zero)
            {
                hIcon = WindowApi.GetClassLongPtr(windowHandle, WindowApi.GCL_HICON);
            }

            if (hIcon == IntPtr.Zero)
            {
                //TODO: define this constant in the api. it's messy in here.
                hIcon = WindowApi.LoadIcon(IntPtr.Zero, (IntPtr)0x7F00 /*IDI_APPLICATION*/);
            }

            if (hIcon != IntPtr.Zero)
            {
                return(Imaging.CreateBitmapSourceFromHIcon(hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
            }
            else
            {
                throw new InvalidOperationException("Could not load window icon.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Override clipboard changed event
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            // defined in winuser.h
            const int wmDrawclipboard = 0x308;
            const int wmChangecbchain = 0x030D;

            try
            {
                switch (m.Msg)
                {
                case wmDrawclipboard:
                    IDataObject iData = Clipboard.GetDataObject();
                    Object      oData = null;
                    if (iData != null)
                    {
                        oData = iData.GetData(DataFormats.UnicodeText);
                    }

                    string textData = String.Empty;
                    if (oData != null)
                    {
                        textData = oData.ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(textData) && _flagCheckTranslate)
                    {
                        _clipboardData = textData;
                        ShowTranslationButton();
                    }

                    break;

                case wmChangecbchain:
                    if (m.WParam == _nextClipboardViewer)
                    {
                        _nextClipboardViewer = m.LParam;
                    }
                    else
                    {
                        WindowApi.SendMessage(_nextClipboardViewer, m.Msg, m.WParam, m.LParam);
                    }
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }