/// <include file='doc\TrayIcon.uex' path='docs/doc[@for="NotifyIcon.ShowContextMenu"]/*' />
        /// <devdoc>
        ///     Shows the context menu for the tray icon.
        /// </devdoc>
        /// <internalonly/>
        private void ShowContextMenu() {

            if (contextMenu != null || contextMenuStrip != null) {
                NativeMethods.POINT pt = new NativeMethods.POINT();
                UnsafeNativeMethods.GetCursorPos(pt);

                // VS7 #38994
                // The solution to this problem was found in MSDN Article ID: Q135788.
                // Summary: the current window must be made the foreground window
                // before calling TrackPopupMenuEx, and a task switch must be
                // forced after the call.
                UnsafeNativeMethods.SetForegroundWindow(new HandleRef(window, window.Handle));

                if (contextMenu != null) {
                    contextMenu.OnPopup( EventArgs.Empty );

                    SafeNativeMethods.TrackPopupMenuEx(new HandleRef(contextMenu, contextMenu.Handle),
                                             NativeMethods.TPM_VERTICAL | NativeMethods.TPM_RIGHTALIGN,
                                             pt.x,
                                             pt.y,
                                             new HandleRef(window, window.Handle),
                                             null);

                    // Force task switch (see above)
                    UnsafeNativeMethods.PostMessage(new HandleRef(window, window.Handle), NativeMethods.WM_NULL, IntPtr.Zero, IntPtr.Zero);
                }
                else if (contextMenuStrip != null) {
                    // this will set the context menu strip to be toplevel
                    // and will allow us to overlap the system tray
                    contextMenuStrip.ShowInTaskbar(pt.x, pt.y);
                }
            }
        }
示例#2
0
文件: Form.cs 项目: mind0n/hive
        /// <devdoc>
        ///     WM_NCHITTEST handler
        /// </devdoc>
        /// <internalonly/>
        private void WmNCHitTest(ref Message m) {
            if (formState[FormStateRenderSizeGrip] != 0 ) {
                int x = NativeMethods.Util.LOWORD(m.LParam);
                int y = NativeMethods.Util.HIWORD(m.LParam);

                // Convert to client coordinates
                //
                NativeMethods.POINT pt = new NativeMethods.POINT(x, y);
                UnsafeNativeMethods.ScreenToClient(new HandleRef(this, this.Handle), pt );

                Size clientSize = ClientSize;

                // If the grip is not fully visible the grip area could overlap with the system control box; we need to disable 
                // the grip area in this case not to get in the way of the control box.  We only need to check for the client's
                // height since the window width will be at least the size of the control box which is always bigger than the 
                // grip width.
                if( pt.x >= (clientSize.Width  - SizeGripSize) && 
                    pt.y >= (clientSize.Height - SizeGripSize) && 
                    clientSize.Height >= SizeGripSize){
                        m.Result = IsMirrored ? (IntPtr)NativeMethods.HTBOTTOMLEFT : (IntPtr)NativeMethods.HTBOTTOMRIGHT;
                        return;
                }
            }

            base.WndProc(ref m);

            // If we got any of the "edge" hits (bottom, top, topleft, etc),
            // and we're AutoSizeMode.GrowAndShrink, return non-resizable border
            // The edge values are the 8 values from HTLEFT (10) to HTBOTTOMRIGHT (17).
            if (AutoSizeMode == AutoSizeMode.GrowAndShrink)
            {
                int result = unchecked( (int) (long)m.Result);
                if (result >= NativeMethods.HTLEFT && 
                    result <= NativeMethods.HTBOTTOMRIGHT) {
                    m.Result = (IntPtr)NativeMethods.HTBORDER;
                }
            }
        }
示例#3
0
        protected override void WndProc(ref Message m) {
            switch (m.Msg) {
                case NativeMethods.WM_COMMAND + NativeMethods.WM_REFLECT:
                    WmReflectCommand(ref m);
                    break;

                case NativeMethods.WM_NOTIFY:
                case NativeMethods.WM_NOTIFY + NativeMethods.WM_REFLECT:
                    NativeMethods.NMHDR note = (NativeMethods.NMHDR) m.GetLParam(typeof(NativeMethods.NMHDR));
                    switch (note.code) {
                        case NativeMethods.TTN_NEEDTEXTA:
                            // MSDN:
                            // Setting the max width has the added benefit of enabling multiline
                            // tool tips!
                            //
                            // [....]: temporarily commenting out this code to fix Pri0 bug 152233
                            // UnsafeNativeMethods.SendMessage(new HandleRef(note, note.hwndFrom), NativeMethods.TTM_SETMAXTIPWIDTH, 0, SystemInformation.MaxWindowTrackSize.Width);
                            WmNotifyNeedTextA(ref m);
                            m.Result = (IntPtr)1;
                            return;

                        case NativeMethods.TTN_NEEDTEXTW:
                            // On Win 98/IE 5,we still get W messages.  If we ignore them, it will send the A version.
                            if (Marshal.SystemDefaultCharSize == 2) {
                                // MSDN:
                                // Setting the max width has the added benefit of enabling multiline
                                // tool tips!
                                //
                                // [....]: temporarily commenting out this code to fix Pri0 bug 152233
                                // UnsafeNativeMethods.SendMessage(new HandleRef(note, note.hwndFrom), NativeMethods.TTM_SETMAXTIPWIDTH, 0, SystemInformation.MaxWindowTrackSize.Width);
                                WmNotifyNeedText(ref m);
                                m.Result = (IntPtr)1;
                                return;
                            }
                            break;
                        case NativeMethods.TTN_SHOW:
                            // VSWhidbey 177016: Prevent the tooltip from displaying in the upper left corner of the
                            // desktop when the control is nowhere near that location.
                            NativeMethods.WINDOWPLACEMENT wndPlacement = new NativeMethods.WINDOWPLACEMENT();
                            int nRet = UnsafeNativeMethods.GetWindowPlacement(new HandleRef(null, note.hwndFrom), ref wndPlacement);

                            // Is this tooltip going to be positioned in the upper left corner of the display,
                            // but nowhere near the toolbar button?
                            if (wndPlacement.rcNormalPosition_left == 0 &&
                                wndPlacement.rcNormalPosition_top == 0 &&
                                this.hotItem != -1) {

                                // Assume that we're going to vertically center the tooltip on the right edge of the current
                                // hot item.

                                // Where is the right edge of the current hot item?
                                int buttonRight = 0;
                                for(int idx = 0; idx <= this.hotItem; idx++) {
                                    // How wide is the item at this index? (It could be a separator, and therefore a different width.)
                                    buttonRight += buttonsCollection[idx].GetButtonWidth();
                                }

                                // Where can we place this tooltip so that it will be completely visible on the current display?
                                int tooltipWidth = wndPlacement.rcNormalPosition_right - wndPlacement.rcNormalPosition_left;
                                int tooltipHeight = wndPlacement.rcNormalPosition_bottom - wndPlacement.rcNormalPosition_top;

                                // We'll need screen coordinates of this position for setting the tooltip's position
                                int x = this.Location.X + buttonRight + 1;
                                int y = this.Location.Y + (this.ButtonSize.Height / 2);
                                NativeMethods.POINT leftTop = new NativeMethods.POINT(x, y);
                                UnsafeNativeMethods.ClientToScreen(new HandleRef(this, this.Handle), leftTop);

                                // Will the tooltip bleed off the top?
                                if (leftTop.y < SystemInformation.WorkingArea.Y) {
                                    // Reposition the tooltip to be displayed below the button
                                    leftTop.y += (this.ButtonSize.Height / 2) + 1;
                                }

                                // Will the tooltip bleed off the bottom?
                                if (leftTop.y + tooltipHeight > SystemInformation.WorkingArea.Height) {
                                    // Reposition the tooltip to be displayed above the button
                                    leftTop.y -= ((this.ButtonSize.Height / 2) + tooltipHeight + 1);
                                }

                                // Will the tooltip bleed off the right edge?
                                if (leftTop.x + tooltipWidth > SystemInformation.WorkingArea.Right) {
                                    // Move the tooltip far enough left that it will display in the working area
                                    leftTop.x -= (this.ButtonSize.Width + tooltipWidth + 2);
                                }

                                SafeNativeMethods.SetWindowPos(new HandleRef(null, note.hwndFrom), NativeMethods.NullHandleRef, leftTop.x, leftTop.y, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE);
                                m.Result = (IntPtr)1;
                                return;
                            }
                            break;

                        case NativeMethods.TBN_HOTITEMCHANGE:
                            WmNotifyHotItemChange(ref m);
                            break;


                        case NativeMethods.TBN_QUERYINSERT:
                            m.Result = (IntPtr)1;
                            break;

                        case NativeMethods.TBN_DROPDOWN:
                            WmNotifyDropDown(ref m);
                            break;
                    }
                    break;

            }
            base.WndProc(ref m);
        }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.GetPoint"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public Point GetPoint(PointProperty prop) {
            //valid values are 0xd49 to 0xd50
            if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)PointProperty.Offset, (int)PointProperty.MinSize5))
            {
                throw new InvalidEnumArgumentException("prop", (int)prop, typeof(PointProperty));
            }

            NativeMethods.POINT point = new NativeMethods.POINT();
            lastHResult = SafeNativeMethods.GetThemePosition(new HandleRef(this, Handle), part, state, (int)prop, point);
            return new Point(point.x, point.y);
        }        
示例#5
0
文件: Form.cs 项目: mind0n/hive
        protected override void OnVisibleChanged(EventArgs e) {
            UpdateRenderSizeGrip();
            Form mdiParent = MdiParentInternal;
            if (mdiParent != null) {
                mdiParent.UpdateMdiWindowListStrip();
            }
            base.OnVisibleChanged(e);

            // windows forms have to behave like dialog boxes sometimes. If the
            // user has specified that the mouse should snap to the
            // Accept button using the Mouse applet in the control panel,
            // we have to respect that setting each time our form is made visible.
            bool data = false;
            if (IsHandleCreated
                    && Visible
                    && (AcceptButton != null)
                    && UnsafeNativeMethods.SystemParametersInfo(NativeMethods.SPI_GETSNAPTODEFBUTTON, 0, ref data, 0)
                    && data) {

                Control button = AcceptButton as Control;
                NativeMethods.POINT ptToSnap = new NativeMethods.POINT(
                    button.Left + button.Width / 2,
                    button.Top + button.Height / 2);

                UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), ptToSnap);
                if (!button.IsWindowObscured) {
                    // SECREVIEW : It is safe to change the cursor position from here.
                    //
                    IntSecurity.AdjustCursorPosition.Assert();
                    try {
                        Cursor.Position = new Point(ptToSnap.x, ptToSnap.y);
                    }
                    finally {
                        System.Security.CodeAccessPermission.RevertAssert();
                    }
                }
            }
        }
示例#6
0
		private int HitTest(Point point)
		{
			NativeMethods.POINT pt = new NativeMethods.POINT();
			pt.x = point.X;
			pt.y = point.Y;

			int hit = NativeMethods.SendMessage(Handle, NativeMethods.TB_HITTEST, 0, ref pt);
			if (hit > 0)
			{
				point = this.PointToScreen(point);
				Rectangle bounds = this.RectangleToScreen(new Rectangle(0, 0, Width, Height));
				if (!bounds.Contains(point))
				{
					return -1;
				}
			}

			return hit;
		}
        /// <include file='doc\ListViewInsertionMark.uex' path='docs/doc[@for="ListViewInsertionMark.Index"]/*' />
        /// <devdoc>
        ///     Performs a hit-test at the specified insertion point
    	///     and returns the closest item.
        /// </devdoc>
        ///
    	public int NearestIndex(Point pt)
        {
            NativeMethods.POINT point = new NativeMethods.POINT();
            point.x = pt.X;
            point.y = pt.Y;

            NativeMethods.LVINSERTMARK lvInsertMark = new NativeMethods.LVINSERTMARK();
            UnsafeNativeMethods.SendMessage(new HandleRef(listView, listView.Handle), NativeMethods.LVM_INSERTMARKHITTEST, point, lvInsertMark);

            return lvInsertMark.iItem;
        }       
示例#8
0
 /// <devdoc>
 ///   Child controls run their
 /// </devdoc>
 private MouseEventArgs TranslateMouseEvent(Control child, MouseEventArgs e) {
     if (child != null && IsHandleCreated) {
         // same control as PointToClient or PointToScreen, just
         // with two specific controls in mind.
         NativeMethods.POINT point = new NativeMethods.POINT(e.X, e.Y);
         UnsafeNativeMethods.MapWindowPoints(new HandleRef(child, child.Handle), new HandleRef(this, Handle), point, 1);
         return new MouseEventArgs(e.Button, e.Clicks, point.x, point.y , e.Delta);
     }
     return e;
 }
示例#9
0
            private void ProcessMouseButtonPressed(IntPtr hwndMouseMessageIsFrom, int x, int y) {
                Debug.WriteLineIf(ToolStrip.SnapFocusDebug.TraceVerbose, "[ModalMenuFilter.ProcessMouseButtonPressed] Found a mouse down.");

                int countDropDowns = _inputFilterQueue.Count;
                for (int i = 0; i < countDropDowns; i++) {
                    ToolStrip activeToolStrip = GetActiveToolStripInternal();

                    if (activeToolStrip != null) {
                        NativeMethods.POINT pt = new NativeMethods.POINT();
                        pt.x = x;
                        pt.y = y;
                        UnsafeNativeMethods.MapWindowPoints(new HandleRef(activeToolStrip, hwndMouseMessageIsFrom), new HandleRef(activeToolStrip, activeToolStrip.Handle), pt, 1);
                        if (!activeToolStrip.ClientRectangle.Contains(pt.x, pt.y)) {
                            ToolStripDropDown activeToolStripDropDown = activeToolStrip as ToolStripDropDown;
                            if (activeToolStripDropDown != null) {

                                if (!(activeToolStripDropDown.OwnerToolStrip != null
                                    && activeToolStripDropDown.OwnerToolStrip.Handle == hwndMouseMessageIsFrom
                                    && activeToolStripDropDown.OwnerDropDownItem != null
                                     && activeToolStripDropDown.OwnerDropDownItem.DropDownButtonArea.Contains(x, y))) {
                                    // the owner item should handle closing the dropdown 
                                    // this allows code such as if (DropDown.Visible) { Hide, Show } etc.
                                    CloseActiveDropDown(activeToolStripDropDown, ToolStripDropDownCloseReason.AppClicked);
                                }
                            }
                            else {
                                // make sure we clear the selection.
                                activeToolStrip.NotifySelectionChange(/*selectedItem=*/null);
                                // we're a toplevel toolstrip and we've clicked somewhere else.
                                // Exit menu mode
                                Debug.WriteLineIf(ToolStrip.SnapFocusDebug.TraceVerbose, "[ModalMenuFilter.ProcessMouseButtonPressed] Calling exit because we're a toplevel toolstrip and we've clicked somewhere else.");
                                ExitMenuModeCore();
                            }
                        }
                        else {
                            // we've found a dropdown that intersects with the mouse message
                            break;
                        }
                    }
                    else {
                        Debug.WriteLineIf(ToolStrip.SnapFocusDebug.TraceVerbose, "[ModalMenuFilter.ProcessMouseButtonPressed] active toolstrip is null.");
                        break;
                    }
                }

            }
示例#10
0
      protected override void  WndProc(ref Message m)            {                
          if ((m.Msg == NativeMethods.WM_NCHITTEST) && SizingGrip) {
            // if we're within the grip bounds tell windows
            // that we're the bottom right of the window.  
            Rectangle sizeGripBounds = SizeGripBounds;
            int x = NativeMethods.Util.LOWORD(m.LParam);
            int y = NativeMethods.Util.HIWORD(m.LParam);

                       
            if (sizeGripBounds.Contains(PointToClient(new Point(x, y)))) {
                HandleRef rootHwnd = WindowsFormsUtils.GetRootHWnd(this);

                // if the main window isnt maximized - we should paint a resize grip.
                // double check that we're at the bottom right hand corner of the window.
                if (rootHwnd.Handle != IntPtr.Zero && !UnsafeNativeMethods.IsZoomed(rootHwnd)) {
                    // get the client area of the topmost window.  If we're next to the edge then 
                    // the sizing grip is valid.
                    NativeMethods.RECT rootHwndClientArea = new NativeMethods.RECT();
                    UnsafeNativeMethods.GetClientRect(rootHwnd, ref rootHwndClientArea);
                    
                    // map the size grip FROM statusStrip coords TO the toplevel window coords.
                    NativeMethods.POINT gripLocation;
                    if (RightToLeft == RightToLeft.Yes) {
                        gripLocation = new NativeMethods.POINT(SizeGripBounds.Left, SizeGripBounds.Bottom);
                    }
                    else {
                        gripLocation = new NativeMethods.POINT(SizeGripBounds.Right, SizeGripBounds.Bottom);
                    }
                    UnsafeNativeMethods.MapWindowPoints(new HandleRef(this, this.Handle), rootHwnd, gripLocation, 1);

                    int deltaBottomEdge = Math.Abs(rootHwndClientArea.bottom - gripLocation.y);
                    int deltaRightEdge = Math.Abs(rootHwndClientArea.right - gripLocation.x);
                    
                    if (RightToLeft != RightToLeft.Yes) {
                        if ((deltaRightEdge + deltaBottomEdge) < 2) {
                            m.Result = (IntPtr)NativeMethods.HTBOTTOMRIGHT;                   
                            return;                      
                        }
                    }
                    
                    
                }
               
            }                
          }
          base.WndProc(ref m);            
       }