Пример #1
0
        /// <summary>
        /// The hook procedure for window messages generated by the FileOpenDialog
        /// </summary>
        /// <param name="hWnd">the handle of the window at which this message is targeted</param>
        /// <param name="msg">the message identifier</param>
        /// <param name="wParam">message-specific parameter data</param>
        /// <param name="lParam">mess-specific parameter data</param>
        /// <returns></returns>


        public IntPtr MyHookProc(IntPtr hWnd, UInt16 msg, Int32 wParam, Int32 lParam)
        {
            // return if invalid window
            if (hWnd == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            //the message passed by AlphaSlider control
            if (msg == 0x5050)
            {
                //update the text box value
                Trace.WriteLine(wParam);
                _textAlpha.Text = wParam.ToString();
            }


            //this is total hack
            //I could not find the message posted by ChooColor dialog when user presses OK
            //this I found the last message sent and using it
            //TODO: find the correct message as documented i.e. COLOROKSTRING
            if (msg == 0xC072 /*==COLOROKSTRING*/)
            {
                //get the current ChooseColor structure
                IntPtr      ipNotify   = new IntPtr(lParam);
                ChooseColor cc         = (ChooseColor)Marshal.PtrToStructure(ipNotify, typeof(ChooseColor));
                IntPtr      hWndParent = NativeMethods.GetParent(hWnd);

                //extract the RGB values from structure
                int R = (char )(cc.rgbResult);
                int G = (char )(((int)(cc.rgbResult)) >> 8);
                int B = (char )(cc.rgbResult >> 16);

                //the typecase problem
                //TODO: write the C# version of GetRValue, GetGValue, GetBValue
                if (R > 256)
                {
                    R = R / 257;
                }

                if (G > 256)
                {
                    G /= 257;
                }

                //get the alpha value from slider control
                _color = Color.FromArgb(_sliderAlpha.Value, R, G, B);
                Trace.WriteLine(_color);
            }

            // Behaviour is dependant on the message received
            switch (msg)
            {
            // We're not interested in every possible message; just return a NULL for those we don't care about
            default:
            {
                return(IntPtr.Zero);
            }


            // WM_INITDIALOG - at this point the ChooseColorDialog exists, so we pull the user-supplied control
            // into the FileOpenDialog now, using the SetParent API.
            case WindowMessage.InitDialog:
            {
                //set the parent window of slider control to recieve change in value messages
                _sliderAlpha.SetParent(hWnd);

                //increase the width of the default dialog box
                //place the slider and text box controls on the right most
                POINT       topLeft     = new POINT();
                POINT       bottomRight = new POINT();
                IntPtr      ipNotify    = new IntPtr(lParam);
                ChooseColor cc          = (ChooseColor)Marshal.PtrToStructure(ipNotify, typeof(ChooseColor));
                IntPtr      hWndParent  = NativeMethods.GetParent(hWnd);
                NativeMethods.SetParent(_panelAlpha.Handle, hWnd);
                RECT rc = new RECT();
                NativeMethods.GetWindowRect(hWnd, ref rc);
                topLeft.X = rc.right;
                topLeft.Y = rc.top;
                NativeMethods.ScreenToClient(hWnd, ref topLeft);
                bottomRight.X = rc.right;
                bottomRight.Y = rc.bottom;
                NativeMethods.ScreenToClient(hWnd, ref bottomRight);

                Rectangle rcClient = _panelAlpha.ClientRectangle;
                NativeMethods.MoveWindow(hWnd, rc.left, rc.top, bottomRight.X + rcClient.Width + 10, bottomRight.Y + 28, true);

                return(IntPtr.Zero);
            }

            // WM_SIZE - the OpenFileDialog has been resized, so we'll resize the content and user-supplied
            // panel to fit nicely
            case WindowMessage.Size:
            {
                PlaceCustomControls(hWnd);
                return(IntPtr.Zero);
            }
            }
        }
Пример #2
0
		internal static extern bool ChooseColor( ref ChooseColor cc );
Пример #3
0
 internal static extern bool ChooseColor(ref ChooseColor cc);