• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            最近想在MFC中運(yùn)用D3D,直接來了就用的單文檔,結(jié)果調(diào)試半天還是坐標(biāo)不對(duì)~

            鼠標(biāo)的位置就是y比畫的圖形要大,而且是越往右下角拉 y 距離相差就越大!!!

            但是同樣的我用多文檔,還有對(duì)話框都沒有這種問題,請(qǐng)高手賜教@謝謝@

             

            為什么多文檔,Dialog都沒這問題呢?
            CODE:

            // TestDSIView.cpp : CTestDSIView 類的實(shí)現(xiàn)
            //

            #include 
            "stdafx.h"
            #include 
            "TestDSI.h"

            #include 
            "TestDSIDoc.h"
            #include 
            "TestDSIView.h"

            #ifdef _DEBUG
            #define new DEBUG_NEW
            #endif


            // CTestDSIView
            DWORD CTestDSIView::D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZRHW|D3DFVF_DIFFUSE);
            IMPLEMENT_DYNCREATE(CTestDSIView, CView)

            BEGIN_MESSAGE_MAP(CTestDSIView, CView)
                
            // 標(biāo)準(zhǔn)打印命令
                ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
                ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
                ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
                ON_WM_LBUTTONDOWN()
                ON_WM_LBUTTONUP()
                ON_WM_MOUSEMOVE()
            END_MESSAGE_MAP()

            // CTestDSIView 構(gòu)造/析構(gòu)

            CTestDSIView::CTestDSIView()
            {
                
            // TODO: 在此處添加構(gòu)造代碼
                m_pD3D = NULL;
                m_pd3dDevice 
            = NULL;
                m_pVB 
            = NULL;
                m_bEdit 
            = false;
            }


            CTestDSIView::
            ~CTestDSIView()
            {
                
            this->Cleanup();
            }


            BOOL CTestDSIView::PreCreateWindow(CREATESTRUCT
            & cs)
            {
                
            // TODO: 在此處通過修改 CREATESTRUCT cs 來修改窗口類或
                
            // 樣式

                
            return CView::PreCreateWindow(cs);
            }


            // CTestDSIView 繪制

            void CTestDSIView::OnDraw(CDC* /*pDC*/)
            {
                CTestDSIDoc
            * pDoc = GetDocument();
                ASSERT_VALID(pDoc);
                
            if (!pDoc)
                    
            return;

                
            // TODO: 在此處為本機(jī)數(shù)據(jù)添加繪制代碼
                Render();
            }



            // CTestDSIView 打印

            BOOL CTestDSIView::OnPreparePrinting(CPrintInfo
            * pInfo)
            {
                
            // 默認(rèn)準(zhǔn)備
                return DoPreparePrinting(pInfo);
            }


            void CTestDSIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
            {
                
            // TODO: 打印前添加額外的初始化
            }


            void CTestDSIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
            {
                
            // TODO: 打印后添加清除過程
            }



            // CTestDSIView 診斷

            #ifdef _DEBUG
            void CTestDSIView::AssertValid() const
            {
                CView::AssertValid();
            }


            void CTestDSIView::Dump(CDumpContext& dc) const
            {
                CView::Dump(dc);
            }


            CTestDSIDoc
            * CTestDSIView::GetDocument() const // 非調(diào)試版本是內(nèi)聯(lián)的
            {
                ASSERT(m_pDocument
            ->IsKindOf(RUNTIME_CLASS(CTestDSIDoc)));
                
            return (CTestDSIDoc*)m_pDocument;
            }

            #endif //_DEBUG

            void CTestDSIView::OnInitialUpdate(void)
            {
                CView::OnInitialUpdate();

                
            this->InitD3D(m_hWnd);
                
            //this->InitVB();
            }


            void CTestDSIView::OnLButtonDown(UINT nFlags, CPoint point)
            {
                m_ptDown 
            = point;
                m_bEdit 
            = true;
                CView::OnLButtonDown(nFlags, point);
            }


            void CTestDSIView::OnLButtonUp(UINT nFlags, CPoint point)
            {
                m_ptUp 
            = point;
                m_bEdit 
            = false;
                InitVB(m_ptDown.x, m_ptDown.y, point.x, point.y);
                Render();
                CView::OnLButtonUp(nFlags, point);
            }


            void CTestDSIView::OnMouseMove(UINT nFlags, CPoint point)
            {
                
            if (m_bEdit)
                
            {
                    m_ptMove 
            = point;
                    InitVB(m_ptDown.x, m_ptDown.y, point.x, point.y);
                    Render();
                }

                CView::OnMouseMove(nFlags, point);
            }



            //////////////////////////////////////////////////////////////////////////
            // d3d function
            HRESULT CTestDSIView::InitD3D( HWND hWnd )
            {
                
            // Create the D3D object.
                if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
                    
            return E_FAIL;

                
            // Set up the structure used to create the D3DDevice
                D3DPRESENT_PARAMETERS d3dpp;
                ZeroMemory( 
            &d3dpp, sizeof(d3dpp) );
                d3dpp.Windowed 
            = TRUE;
                d3dpp.SwapEffect 
            = D3DSWAPEFFECT_DISCARD;
                d3dpp.BackBufferFormat 
            = D3DFMT_UNKNOWN;

                
            // Create the D3DDevice
                if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                    
            &d3dpp, &m_pd3dDevice ) ) )
                
            {
                    
            return E_FAIL;
                }


                
            // Device state would normally be set here

                
            return S_OK;
            }


            HRESULT CTestDSIView::InitVB(
            int x1 /* = 0 */int y1 /* = 0 */int x2 /* = 0 */int y2 /* = 0 */)
            {
                
            // Initialize three vertices for rendering a triangle
                CUSTOMVERTEX vertices[] =
                

                    
            //{  50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
                    
            //      { 50.0f,  50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
                    
            //      { 250.0f, 50.0f, 0.5f, 1.0f, 0xff00ff00, },
                    
            //{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
                    
            //{50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },

                    
            {  x1, y2, 0.f, 0.0f0xff00ffff, },
                    
            { x1,  y1, 0.f, 0.0f0xffff0000, }// x, y, z, rhw, color
                    { x2, y1, 0.f, 0.0f0xff00ff00, },
                    
            { x2, y2, 0.f, 0.0f0xff00ff00, },
                    
            {x1, y2, 0.f, 0.0f0xff00ffff, },

                }
            ;

                
            // Create the vertex buffer. Here we are allocating enough memory
                
            // (from the default pool) to hold all our 3 custom vertices. We also
                
            // specify the FVF, so the vertex buffer knows what data it contains.
                if( FAILED( m_pd3dDevice->CreateVertexBuffer(5*sizeof(CUSTOMVERTEX),
                    
            0, D3DFVF_CUSTOMVERTEX,
                    D3DPOOL_DEFAULT, 
            &m_pVB, NULL ) ) )
                
            {
                    
            return E_FAIL;
                }


                
            // Now we fill the vertex buffer. To do this, we need to Lock() the VB to
                
            // gain access to the vertices. This mechanism is required becuase vertex
                
            // buffers may be in device memory.
                VOID* pVertices;
                
            if( FAILED( m_pVB->Lock( 0sizeof(vertices), (void**)&pVertices, 0 ) ) )
                    
            return E_FAIL;
                memcpy( pVertices, vertices, 
            sizeof(vertices) );
                m_pVB
            ->Unlock();

                
            return S_OK;
            }


            VOID CTestDSIView::Cleanup()
            {
                
            if( m_pVB != NULL )        
                    m_pVB
            ->Release();

                
            if( m_pd3dDevice != NULL ) 
                    m_pd3dDevice
            ->Release();

                
            if( m_pD3D != NULL )       
                    m_pD3D
            ->Release();
            }


            VOID CTestDSIView::Render()
            {
                
            // Clear the backbuffer to a blue color
                m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f0 );

                
            // Begin the scene
                if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
                
            {
                    
            // Draw the triangles in the vertex buffer. This is broken into a few
                    
            // steps. We are passing the vertices down a "stream", so first we need
                    
            // to specify the source of that stream, which is our vertex buffer. Then
                    
            // we need to let D3D know what vertex shader to use. Full, custom vertex
                    
            // shaders are an advanced topic, but in most cases the vertex shader is
                    
            // just the FVF, so that D3D knows what type of vertices we are dealing
                    
            // with. Finally, we call DrawPrimitive() which does the actual rendering
                    
            // of our geometry (in this case, just one triangle).
                    m_pd3dDevice->SetStreamSource( 0, m_pVB, 0sizeof(CUSTOMVERTEX) );
                    m_pd3dDevice
            ->SetFVF( D3DFVF_CUSTOMVERTEX );
                    m_pd3dDevice
            ->DrawPrimitive( D3DPT_LINESTRIP, 04 );

                    
            // End the scene
                    m_pd3dDevice->EndScene();
                }


                
            // Present the backbuffer contents to the display
                m_pd3dDevice->Present( NULL, NULL, NULL, NULL );
            }

            //////////////////////////////////////////////////////////////////////////
            // CTestDSIView 消息處理程序

             

            // TestDSIView.h : CTestDSIView 類的接口
            //


            #pragma once

            #include 
            <d3d9.h>
            #include 
            <d3dx9.h>
            #pragma comment(lib, 
            "d3d9.lib")
            #pragma comment(lib, 
            "d3dx9.lib")
            #pragma comment(lib, 
            "winmm.lib")
            #pragma warning(disable : 
            4244)

            class CTestDSIView : public CView
            {
            protected// 僅從序列化創(chuàng)建
                CTestDSIView();
                DECLARE_DYNCREATE(CTestDSIView)

            // 屬性
            public:
                CTestDSIDoc
            * GetDocument() const;

            // 操作
            public:

            // 重寫
                public:
                
            virtual void OnDraw(CDC* pDC);  // 重寫以繪制該視圖
            virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
            protected:
                
            virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
                
            virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
                
            virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

            //d3d member
            private:
                LPDIRECT3D9                m_pD3D;
                LPDIRECT3DDEVICE9        m_pd3dDevice;
                LPDIRECT3DVERTEXBUFFER9    m_pVB;

                POINT m_ptDown;
                POINT m_ptUp;
                POINT m_ptMove;
                
            bool  m_bEdit;
            //d3d function member
            protected:
                HRESULT InitD3D( HWND hWnd );
                HRESULT InitVB(
            int x1 = 0int y1 = 0int x2 = 0int y2 = 0);
                VOID Cleanup();
                VOID Render();
                
                
            struct CUSTOMVERTEX
                
            {
                    FLOAT x, y, z, rhw; 
            // The transformed position for the vertex
                    DWORD color;        // The vertex color
                }
            ;

                
            // Our custom FVF, which describes our custom vertex structure
                static DWORD D3DFVF_CUSTOMVERTEX;
                
            //#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
            // 實(shí)現(xiàn)
            public:
                
            virtual ~CTestDSIView();
            #ifdef _DEBUG
                
            virtual void AssertValid() const;
                
            virtual void Dump(CDumpContext& dc) const;
            #endif

            protected:

            // 生成的消息映射函數(shù)
            protected:
                DECLARE_MESSAGE_MAP()
                afx_msg 
            void OnLButtonDown(UINT nFlags, CPoint point);
                afx_msg 
            void OnLButtonUp(UINT nFlags, CPoint point);
                afx_msg 
            void OnMouseMove(UINT nFlags, CPoint point);
            public:
                
            virtual void OnInitialUpdate(void);
            }
            ;

            #ifndef _DEBUG  
            // TestDSIView.cpp 的調(diào)試版本
            inline CTestDSIDoc* CTestDSIView::GetDocument() const
               
            return reinterpret_cast<CTestDSIDoc*>(m_pDocument); }
            #endif


            Feedback

            # re: 為什么在MFC中的單文檔下用D3D畫圖坐標(biāo)不對(duì)盤!  回復(fù)  更多評(píng)論   

            2008-09-17 13:34 by 小不點(diǎn)
            請(qǐng)高手賜教嘍!!!!

            # re: 為什么在MFC中的單文檔下用D3D畫圖坐標(biāo)不對(duì)盤!  回復(fù)  更多評(píng)論   

            2008-09-19 16:50 by 匿名
            我也遇到過這樣的問題,創(chuàng)建的800*600的窗口,用getclientrect得到的矩形居然是950*666的,在view視圖中用directx也是短一塊,就相是說我的鼠標(biāo)消息坐標(biāo)是800*600,但是view是950*666的,剛剛發(fā)現(xiàn)還沒仔細(xì)研究,不過這很可能是mfc的問題

            # re: 為什么在MFC中的單文檔下用D3D畫圖坐標(biāo)不對(duì)盤!  回復(fù)  更多評(píng)論   

            2008-09-19 19:12 by 小不點(diǎn)
            但是 多文檔的 只要視圖大小不改變 那么就沒有偏差,一旦視圖大小改變也就又偏差了,
            單文檔 當(dāng)一開始 創(chuàng)建,沒有添加多的東西的時(shí)候(比如左邊添加有樹控件對(duì)話框)那么就只有y坐標(biāo)又偏差,但是當(dāng)添加后x,y多有偏差了。
            對(duì)話框 倒是還好~
            久久免费视频网站| 99久久婷婷国产一区二区| 精品国产日韩久久亚洲| 久久水蜜桃亚洲av无码精品麻豆 | 亚洲国产精品无码久久久秋霞2| 伊人久久大香线蕉av不变影院| 久久777国产线看观看精品| 天堂无码久久综合东京热| 欧美噜噜久久久XXX| 免费精品久久久久久中文字幕| 99久久精品免费看国产一区二区三区 | 中文无码久久精品| 久久久久人妻精品一区三寸蜜桃| 亚洲av成人无码久久精品| 久久久无码精品午夜| 99久久er这里只有精品18| 亚洲国产成人久久综合碰| 99久久国产免费福利| 久久国产精品无码一区二区三区| 亚洲国产成人久久一区WWW| yellow中文字幕久久网| 国产精品美女久久久久| 久久精品国产亚洲AV影院 | 国产精品久久久久天天影视 | 91久久成人免费| 成人国内精品久久久久一区| 少妇内射兰兰久久| 久久99精品国产麻豆宅宅| 伊人久久亚洲综合影院| 久久亚洲AV无码西西人体| 久久人妻少妇嫩草AV无码蜜桃| 一本久久a久久精品综合夜夜| 97久久久精品综合88久久| 色综合久久久久综合体桃花网 | 色欲综合久久中文字幕网| 久久伊人五月丁香狠狠色| 国产欧美久久久精品影院| 伊人久久大香线蕉av不变影院| 无码国产69精品久久久久网站| 亚洲色大成网站WWW久久九九| 色妞色综合久久夜夜|