Пример #1
0
        /// <summary>
        /// 绘制角色图
        /// </summary>
        /// <param name="strCHpath">角色图地址</param>
        private void drawCharactor(string strCHpath)
        {
            Guid guid = System.Guid.NewGuid();

            DxVBLib.DirectDraw7       dDraw = dx.DirectDrawCreate(guid.ToString());
            DxVBLib.DirectDrawClipper dDclipper;
            dDraw.SetCooperativeLevel(this.Handle.ToInt32(), DxVBLib.CONST_DDSCLFLAGS.DDSCL_NORMAL);

            DxVBLib.RECT rect, rectSec = new DxVBLib.RECT();
            DxVBLib.DirectDrawSurface7 dDsurface;
            DxVBLib.DirectDrawSurface7 dDsurfaceActor;
            DxVBLib.DDSURFACEDESC2     dDDesc      = new DxVBLib.DDSURFACEDESC2();
            DxVBLib.DDSURFACEDESC2     dDDescActor = new DxVBLib.DDSURFACEDESC2();

            dDDesc.lFlags        = DxVBLib.CONST_DDSURFACEDESCFLAGS.DDSD_CAPS;
            dDDesc.ddsCaps.lCaps = DxVBLib.CONST_DDSURFACECAPSFLAGS.DDSCAPS_PRIMARYSURFACE;

            dDsurface = dDraw.CreateSurface(ref dDDesc);
            dDclipper = dDraw.CreateClipper(0);
            dDclipper.SetHWnd(this.Handle.ToInt32());
            dDsurface.SetClipper(dDclipper);

            DxVBLib.DDCOLORKEY dDcolorKey = new DxVBLib.DDCOLORKEY();

            try
            {
                dDsurfaceActor = dDraw.CreateSurfaceFromFile(strCHpath, ref dDDescActor);
                dx.GetWindowRect(this.Handle.ToInt32(), ref rectSec);
                rect.Top        = 0;
                rect.Left       = 0;
                rect.Bottom     = dDDescActor.lHeight;
                rect.Right      = dDDescActor.lWidth;
                rectSec.Top     = rectSec.Bottom - dDDescActor.lHeight;
                rectSec.Left   += (rectSec.Right - rectSec.Left - dDDescActor.lWidth) / 2;
                rectSec.Bottom -= 0;
                rectSec.Right   = rectSec.Left + dDDescActor.lWidth;

                dDcolorKey.high = 0; //被屏蔽
                dDcolorKey.low  = 0; //的颜色介于这两者之间
                dDsurfaceActor.SetColorKey(DxVBLib.CONST_DDCKEYFLAGS.DDCKEY_SRCBLT, ref dDcolorKey);

                dDsurface.Blt(ref rectSec, dDsurfaceActor, ref rect, DxVBLib.CONST_DDBLTFLAGS.DDBLT_WAIT | DxVBLib.CONST_DDBLTFLAGS.DDBLT_KEYSRC);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                // 没有找到文件。
                if ((uint)e.ErrorCode == 0x800A0035)
                {
                    MessageBox.Show("没有找到文件'sample.bmp'.\n该文件必须和程序放在一个目录下面。", "图片没有找到");
                }
                else
                {
                    MessageBox.Show("异常: " + e.ToString(), "异常信息");
                }
                Application.Exit();
                Application.DoEvents();
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        public Rectangle GetWindowRect(IntPtr handle)
        {
            var innerWindowRect = new DxVBLib.RECT();

            DirectX.GetWindowRect(handle.ToInt32(), ref innerWindowRect);
            var windowRect = Rectangle.FromLTRB(innerWindowRect.Left, innerWindowRect.Top, innerWindowRect.Right, innerWindowRect.Bottom);

            return(windowRect);
        }
Пример #3
0
        /// <summary>
        /// 绘制背景图
        /// </summary>
        /// <param name="strBgPath">背景图地址</param>
        private void drawBackground(string strBGpath)
        {
            Guid guid = System.Guid.NewGuid();

            DxVBLib.DirectDraw7       dDraw = dx.DirectDrawCreate(guid.ToString());
            DxVBLib.DirectDrawClipper dDclipper;
            dDraw.SetCooperativeLevel(this.Handle.ToInt32(), DxVBLib.CONST_DDSCLFLAGS.DDSCL_NORMAL);

            DxVBLib.RECT rect    = new DxVBLib.RECT();
            DxVBLib.RECT rectSec = new DxVBLib.RECT();
            DxVBLib.DirectDrawSurface7 dDsurface;
            DxVBLib.DirectDrawSurface7 dDsurfaceSec;
            DxVBLib.DDSURFACEDESC2     dDDesc    = new DxVBLib.DDSURFACEDESC2();
            DxVBLib.DDSURFACEDESC2     dDDescSec = new DxVBLib.DDSURFACEDESC2();

            dDDesc.lFlags        = DxVBLib.CONST_DDSURFACEDESCFLAGS.DDSD_CAPS;
            dDDesc.ddsCaps.lCaps = DxVBLib.CONST_DDSURFACECAPSFLAGS.DDSCAPS_PRIMARYSURFACE;

            dDsurface = dDraw.CreateSurface(ref dDDesc);
            dDclipper = dDraw.CreateClipper(0);
            dDclipper.SetHWnd(this.Handle.ToInt32());
            dDsurface.SetClipper(dDclipper);

            try
            {
                dDsurfaceSec = dDraw.CreateSurfaceFromFile(strBGpath, ref dDDescSec);
                dx.GetWindowRect(this.Handle.ToInt32(), ref rectSec);
                rect.Top    = 0;
                rect.Left   = 0;
                rect.Right  = dDDescSec.lWidth;
                rect.Bottom = dDDescSec.lHeight;
                //dDsurface.BltFast(0, 0, dDsurfaceSec, ref rect, DxVBLib.CONST_DDBLTFASTFLAGS.DDBLTFAST_WAIT);

                dDsurface.Blt(ref rectSec, dDsurfaceSec, ref rect, DxVBLib.CONST_DDBLTFLAGS.DDBLT_WAIT);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                // 没有找到文件。
                if ((uint)e.ErrorCode == 0x800A0035)
                {
                    MessageBox.Show("没有找到文件\n" + "图片没有找到");
                }
                else
                {
                    MessageBox.Show("异常: " + e.ToString(), "异常信息");
                }
                Application.Exit();
                Application.DoEvents();
            }
        }
Пример #4
0
        /// <summary>
        /// ���Ʊ���ͼ
        /// </summary>
        /// <param name="strBgPath">����ͼ��ַ</param>
        private void drawBackground(string strBGpath)
        {
            Guid guid = System.Guid.NewGuid();
            DxVBLib.DirectDraw7 dDraw = dx.DirectDrawCreate(guid.ToString());
            DxVBLib.DirectDrawClipper dDclipper;
            dDraw.SetCooperativeLevel(this.Handle.ToInt32(), DxVBLib.CONST_DDSCLFLAGS.DDSCL_NORMAL);

            DxVBLib.RECT rect = new DxVBLib.RECT();
            DxVBLib.RECT rectSec = new DxVBLib.RECT();
            DxVBLib.DirectDrawSurface7 dDsurface;
            DxVBLib.DirectDrawSurface7 dDsurfaceSec;
            DxVBLib.DDSURFACEDESC2 dDDesc = new DxVBLib.DDSURFACEDESC2();
            DxVBLib.DDSURFACEDESC2 dDDescSec = new DxVBLib.DDSURFACEDESC2();

            dDDesc.lFlags = DxVBLib.CONST_DDSURFACEDESCFLAGS.DDSD_CAPS;
            dDDesc.ddsCaps.lCaps = DxVBLib.CONST_DDSURFACECAPSFLAGS.DDSCAPS_PRIMARYSURFACE;

            dDsurface = dDraw.CreateSurface(ref dDDesc);
            dDclipper = dDraw.CreateClipper(0);
            dDclipper.SetHWnd(this.Handle.ToInt32());
            dDsurface.SetClipper(dDclipper);

            try
            {
                dDsurfaceSec = dDraw.CreateSurfaceFromFile(strBGpath, ref dDDescSec);
                dx.GetWindowRect(this.Handle.ToInt32(), ref rectSec);
                rect.Top = 0;
                rect.Left = 0;
                rect.Right = dDDescSec.lWidth;
                rect.Bottom = dDDescSec.lHeight;
                //dDsurface.BltFast(0, 0, dDsurfaceSec, ref rect, DxVBLib.CONST_DDBLTFASTFLAGS.DDBLTFAST_WAIT);

                dDsurface.Blt(ref rectSec, dDsurfaceSec, ref rect, DxVBLib.CONST_DDBLTFLAGS.DDBLT_WAIT);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                // û���ҵ��ļ���
                if ((uint)e.ErrorCode == 0x800A0035)
                {
                    MessageBox.Show("û���ҵ��ļ�\n" + "ͼƬû���ҵ�");
                }
                else
                {
                    MessageBox.Show("�쳣: " + e.ToString(), "�쳣��Ϣ");
                }
                Application.Exit();
                Application.DoEvents();
            }
        }
Пример #5
0
        /// <summary>
        /// ���ƽ�ɫͼ
        /// </summary>
        /// <param name="strCHpath">��ɫͼ��ַ</param>
        private void drawCharactor(string strCHpath)
        {
            Guid guid = System.Guid.NewGuid();
            DxVBLib.DirectDraw7 dDraw = dx.DirectDrawCreate(guid.ToString());
            DxVBLib.DirectDrawClipper dDclipper;
            dDraw.SetCooperativeLevel(this.Handle.ToInt32(), DxVBLib.CONST_DDSCLFLAGS.DDSCL_NORMAL);

            DxVBLib.RECT rect, rectSec = new DxVBLib.RECT();
            DxVBLib.DirectDrawSurface7 dDsurface;
            DxVBLib.DirectDrawSurface7 dDsurfaceActor;
            DxVBLib.DDSURFACEDESC2 dDDesc = new DxVBLib.DDSURFACEDESC2();
            DxVBLib.DDSURFACEDESC2 dDDescActor = new DxVBLib.DDSURFACEDESC2();

            dDDesc.lFlags = DxVBLib.CONST_DDSURFACEDESCFLAGS.DDSD_CAPS;
            dDDesc.ddsCaps.lCaps = DxVBLib.CONST_DDSURFACECAPSFLAGS.DDSCAPS_PRIMARYSURFACE;

            dDsurface = dDraw.CreateSurface(ref dDDesc);
            dDclipper = dDraw.CreateClipper(0);
            dDclipper.SetHWnd(this.Handle.ToInt32());
            dDsurface.SetClipper(dDclipper);

            DxVBLib.DDCOLORKEY dDcolorKey = new DxVBLib.DDCOLORKEY();

            try
            {
                dDsurfaceActor = dDraw.CreateSurfaceFromFile(strCHpath, ref dDDescActor);
                dx.GetWindowRect(this.Handle.ToInt32(), ref rectSec);
                rect.Top = 0;
                rect.Left = 0;
                rect.Bottom = dDDescActor.lHeight;
                rect.Right = dDDescActor.lWidth;
                rectSec.Top = rectSec.Bottom - dDDescActor.lHeight;
                rectSec.Left += (rectSec.Right - rectSec.Left - dDDescActor.lWidth) / 2;
                rectSec.Bottom -= 0;
                rectSec.Right = rectSec.Left + dDDescActor.lWidth;

                dDcolorKey.high = 0; //������
                dDcolorKey.low = 0; //����ɫ����������֮��
                dDsurfaceActor.SetColorKey(DxVBLib.CONST_DDCKEYFLAGS.DDCKEY_SRCBLT, ref dDcolorKey);

                dDsurface.Blt(ref rectSec, dDsurfaceActor, ref rect, DxVBLib.CONST_DDBLTFLAGS.DDBLT_WAIT | DxVBLib.CONST_DDBLTFLAGS.DDBLT_KEYSRC);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                // û���ҵ��ļ���
                if ((uint)e.ErrorCode == 0x800A0035)
                {
                    MessageBox.Show("û���ҵ��ļ�'sample.bmp'.\n���ļ�����ͳ������һ��Ŀ¼���档", "ͼƬû���ҵ�");
                }
                else
                {
                    MessageBox.Show("�쳣: " + e.ToString(), "�쳣��Ϣ");
                }
                Application.Exit();
                Application.DoEvents();
            }
        }