// 刷新文档和视图
        public void RefreshDocAndView(UIDocument uiDoc)
        {
            if (uiDoc == null)
            {
                return;
            }
            m_uiDoc = uiDoc;
            if (m_GridNumShowMag == null)
            {
                m_GridNumShowMag = new ShowGridNumberManager(uiDoc);
            }
            else
            {
                m_GridNumShowMag.RefreshUIDocument(m_uiDoc);
            }
            IntPtr intPtr = IntPtr.Zero;

            try
            {
                //SendMessageWindows API宏,在WinUser.h中根据是否已定义Unicode被定义为SendMessageW或SendMessageA
                //,这两个函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。
                //而和函数PostMessage不同,PostMessage是将一个消息寄送到一个线程的消息队列后就立即返回。
                //553u 应用程序将WM_MDIGETACTIVE消息发送到多文档界面(MDI)客户端窗口,以检索活动MDI子窗口的句柄。
                m_hWndChildHandle = (IntPtr)SendMessage(m_hMDIChildHandle, 553u, 0, 0);
                if (m_hWndChildProcNew == null)
                {
                    m_hWndChildProcNew = new GridNumberForm.NewWndProc(WndMsgProcChild);
                }
                m_hWndChildProcOld = GridNumberForm.SetWindowLong(m_hWndChildHandle, -4, m_hWndChildProcNew);
                //转换 String 类写入非托管内存
                intPtr = Marshal.StringToHGlobalAnsi("AfxFrameOrView");
                EnumChildWindows(m_hWndChildHandle, new CallBack(EnumMDIChildClient), intPtr);
                if (m_hWndChildClientProcNew == null)
                {
                    m_hWndChildClientProcNew = new GridNumberForm.NewWndProc(WndMsgProcChildClient);
                }
                //SetWindowLong该函数用来改变指定窗口的属性

                m_hWndChildClientProcOld = GridNumberForm.SetWindowLong(m_hWndChildClientHandle, -4, m_hWndChildClientProcNew);
            }
            catch (Exception)
            {
                m_appShowGrid.DrawGridNumber = false;
            }
            finally
            {
                //释放非托管的字符串
                Marshal.FreeHGlobal(intPtr);
            }
        }
Exemple #2
0
        // 转换插入点   文字圆圈位置修正
        public void TranformIntersectPt(IntPtr hFormClient)
        {
            try
            {
                foreach (GridNumShowInfo gridNumShowInfo in m_GridNumShowInfos)
                {
                    XYZ intersectPoint = gridNumShowInfo.IntersectPoint;
                    if (intersectPoint != null)
                    {
                        XYZ cirPt  = null;
                        XYZ textPt = null;
//                      switch (gridNumShowInfo.OutViewSide)
//                      {
//                      case OutViewSide._Up:
//                             textPt = intersectPoint + XYZ.BasisY * 20;
//                             cirPt = intersectPoint - XYZ.BasisX * 20;
//                          break;
//                      case OutViewSide._Left:
//                             textPt = intersectPoint + XYZ.BasisX * 5.0;
//                             cirPt = intersectPoint - XYZ.BasisY * 20;
//                          break;
//                      case OutViewSide._Right:
//                             textPt = intersectPoint - XYZ.BasisX * 5.0;
//                             cirPt = intersectPoint - XYZ.BasisY * 20 - XYZ.BasisX * 42;
//                          break;
//                      case OutViewSide._Bottom:
//                             textPt = intersectPoint - XYZ.BasisY * 20;
//                             cirPt = intersectPoint - XYZ.BasisY * 42 - XYZ.BasisX * 20;
//                          break;
//                      }
                        float  fontSize     = ShowGridApplication.m_gridNumberShowForm.fontSize;
                        float  circleRadius = (fontSize + 5) / 2;
                        int    margin       = 3;
                        double marginX      = fontSize / 5 * 2.5;
                        switch (gridNumShowInfo.OutlineSide)
                        {
                        case OutViewSide._Up:
                            textPt = intersectPoint + XYZ.BasisY * (fontSize / 2 + margin);
                            /*cirPt = intersectPoint - XYZ.BasisX * (circleRadius) - XYZ.BasisY * (circleRadius - (fontSize / 2 + margin));*/
                            cirPt = textPt - XYZ.BasisX * circleRadius - XYZ.BasisY * circleRadius;
                            break;

                        case OutViewSide._Left:
                            textPt = intersectPoint + XYZ.BasisX * margin;
                            /*cirPt = intersectPoint / *- XYZ.BasisX * 2 - XYZ.BasisY * 11* /;*/
                            cirPt = textPt - XYZ.BasisX * circleRadius + XYZ.BasisX * marginX - XYZ.BasisY * circleRadius;
                            break;

                        case OutViewSide._Right:
                            textPt = intersectPoint - XYZ.BasisX * margin;
                            /*cirPt = intersectPoint - XYZ.BasisX * (circleRadius * 2) + XYZ.BasisY * ((fontSize / 2 + margin));*/
                            cirPt = textPt - XYZ.BasisX * circleRadius - XYZ.BasisX * marginX - XYZ.BasisY * circleRadius;
                            break;

                        case OutViewSide._Bottom:
                            textPt = intersectPoint - XYZ.BasisY * (fontSize / 2 + margin);
                            cirPt  = textPt - XYZ.BasisX * circleRadius - XYZ.BasisY * circleRadius;
                            break;
                        }
                        System.Drawing.Point cirlLocation = new System.Drawing.Point((int)cirPt.X, (int)cirPt.Y);
                        ShowGridNumberManager.ScreenToClient(hFormClient, ref cirlLocation);
                        gridNumShowInfo.CirlLocation = cirlLocation;
                        System.Drawing.Point textLocation = new System.Drawing.Point((int)textPt.X, (int)textPt.Y);
                        ShowGridNumberManager.ScreenToClient(hFormClient, ref textLocation);
                        gridNumShowInfo.TextLocation = textLocation;
                    }
                }
            }
            catch
            {
            }
        }