// this is the new wndproc, just show a messagebox on left button down:
        private int MyWndProc(IntPtr hWnd, int Msg, int wParam, int lParam)
        {
            System.Diagnostics.Debug.WriteLine(Msg.ToString());


            switch (Msg)
            {
            case 0x4e:
            {
                unsafe
                {
                    NMHDR *hdr = (NMHDR *)lParam;

                    if (hdr->code == LVN_LINKCLICK)
                    {
                        MessageBox.Show("Link clicked!");
                        return(0);
                    }
                }
                break;
            }

            default:
                break;
            }

            return(CallWindowProc(oldWndProc, hWnd, Msg, wParam, lParam));
        }
Esempio n. 2
0
        protected unsafe override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case 8270:
                NMHDR *ptr = (NMHDR *)((void *)m.LParam);
                if (ptr->code == NM_CUSTOMDRAW)
                {
                    NMTVCUSTOMDRAW nMTVCUSTOMDRAW = (NMTVCUSTOMDRAW)m.GetLParam(typeof(NMTVCUSTOMDRAW));
                    int            dwDrawStage    = nMTVCUSTOMDRAW.nmcd.dwDrawStage;
                    if (dwDrawStage == (CDDS_ITEM | CDDS_PREPAINT))
                    {
                        TreeNode treeNode = TreeNode.FromHandle(this, nMTVCUSTOMDRAW.nmcd.dwItemSpec);
                        if (treeNode != null)
                        {
                            using (Graphics graphics = Graphics.FromHdcInternal(nMTVCUSTOMDRAW.nmcd.hdc))
                            {
                                var bounds = treeNode.Bounds;
                                using (var brush = new SolidBrush(GetNodeRowBackgroundColor(treeNode)))
                                {
                                    graphics.FillRectangle(brush, new Rectangle(0, bounds.Top, this.Width, bounds.Height));
                                }
                            }
                        }
                    }
                }
                break;

            case WM_ERASEBKGND:
                // in this handler erase only part of background that is not covered by nodes
                TreeNode  lastVisible = FindLastVisible(Nodes);
                Rectangle r;
                if (lastVisible != null)
                {
                    r = new Rectangle(0, lastVisible.Bounds.Bottom, Width, Height);
                }
                else
                {
                    r = new Rectangle(0, 0, Width, Height);
                }
                using (var g = CreateGraphics())
                    g.FillRectangle(Brushes.White, r);
                m.Result = (IntPtr)1;
                return;                         // skip default processing

            case WM_HSCROLL:
                Invalidate();
                break;
            }
            base.WndProc(ref m);
        }
        private unsafe void OnWmReflectNotify(ref Message m)
        {
            NMHDR *hdr = (NMHDR *)m.LParam;

            if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista) && hdr->code == LVN_LinkClick)
            {
                NMLVLINK link = (NMLVLINK)Marshal.PtrToStructure(m.LParam, typeof(NMLVLINK));

                this.OnGroupLinkClicked(this.FindGroup(link.SubItemIndex));
            }
            else if (hdr->code == NM_DBLClk)
            {
                if (!_doubleClickChecks && this.CheckBoxes)
                {
                    _doubleClickCheckHackActive = true;
                }
            }
        }
Esempio n. 4
0
        public static unsafe void ReflectMessage(ref Message msg, out bool handled)
        {
            IntPtr hWndChild = IntPtr.Zero;

            if (msg.MessageId == WindowMessages.WM_COMMAND)
            {
                if (msg.LParam != IntPtr.Zero)
                {
                    hWndChild = msg.LParam;
                }
            }
            else if (msg.MessageId == WindowMessages.WM_NOTIFY)
            {
                NMHDR *header = (NMHDR *)msg.LParam;
                hWndChild = header->hWndFrom;
            }
            else if (msg.MessageId == WindowMessages.WM_PARENTNOTIFY)
            {
                uint submessage = (uint)((int)msg.WParam & 0xFFFF);
                if (submessage == WindowMessages.WM_CREATE || submessage == WindowMessages.WM_DESTROY)
                {
                    hWndChild = msg.LParam;
                }
                else
                {
                    int controlId = ((int)msg.WParam >> 16) & 0xFFFF;
                    hWndChild = NativeMethods.GetDlgItem(msg.TargetHandle, controlId);
                }
            }
            else if (msg.MessageId == WindowMessages.WM_DRAWITEM)
            {
                if (msg.WParam != IntPtr.Zero)
                {
                    DRAWITEMSTRUCT *drawItemStruct = (DRAWITEMSTRUCT *)msg.WParam;
                    hWndChild = drawItemStruct->hwndItem;
                }
            }
            else if (msg.MessageId == WindowMessages.WM_MEASUREITEM)
            {
                if (msg.WParam != IntPtr.Zero)
                {
                    MEASUREITEMSTRUCT *measureItemStruct = (MEASUREITEMSTRUCT *)msg.WParam;
                    hWndChild = NativeMethods.GetDlgItem(msg.TargetHandle, (int)measureItemStruct->CtlID);
                }
            }
            else if (msg.MessageId == WindowMessages.WM_COMPAREITEM)
            {
                if (msg.WParam != IntPtr.Zero)
                {
                    COMPAREITEMSTRUCT *compareStruct = (COMPAREITEMSTRUCT *)msg.WParam;
                    hWndChild = compareStruct->hwndItem;
                }
            }
            else if (msg.MessageId == WindowMessages.WM_DELETEITEM)
            {
                if (msg.WParam != IntPtr.Zero)
                {
                    DELETEITEMSTRUCT *deleteStruct = (DELETEITEMSTRUCT *)msg.WParam;
                    hWndChild = deleteStruct->hwndItem;
                }
            }
            else if (msg.MessageId == WindowMessages.WM_VKEYTOITEM || msg.MessageId == WindowMessages.WM_CHARTOITEM ||
                     msg.MessageId == WindowMessages.WM_HSCROLL || msg.MessageId == WindowMessages.WM_VSCROLL)
            {
                hWndChild = msg.LParam;
            }
            else if (msg.MessageId == WindowMessages.WM_CTLCOLORBTN || msg.MessageId == WindowMessages.WM_CTLCOLORDLG ||
                     msg.MessageId == WindowMessages.WM_CTLCOLOREDIT || msg.MessageId == WindowMessages.WM_CTLCOLORMSGBOX ||
                     msg.MessageId == WindowMessages.WM_CTLCOLORMSGBOX || msg.MessageId == WindowMessages.WM_CTLCOLORSCROLLBAR ||
                     msg.MessageId == WindowMessages.WM_CTLCOLORSTATIC)
            {
                hWndChild = msg.LParam;
            }

            if (hWndChild == IntPtr.Zero)
            {
                handled = false;
                return;
            }

            if (!NativeMethods.IsWindow(hWndChild))
            {
                throw new InvalidOperationException("hwndChild not a valid HWND");
            }

            // This code relies on the fact that NativeMethods.GetProp() returns IntPtr.Zero
            // if the property has not been set. This code only cares if the handled flag
            // was set to true. If the flag is false, this code behaves the same as if
            // SetReflectedMessageHandled() was never called at all.

            NativeMethods.RemoveProp(hWndChild, HandledProperty); // clear it out, just in case
            IntPtr result = NativeMethods.SendMessage(hWndChild, msg.MessageId + WM_REFLECTED_MESSAGE_BASE, msg.WParam, msg.LParam);

            handled = NativeMethods.GetProp(hWndChild, HandledProperty) != IntPtr.Zero;
            NativeMethods.RemoveProp(hWndChild, HandledProperty);
            if (handled)
            {
                msg.Result = result;
            }
        }
Esempio n. 5
0
 afx_msg void OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);