lnhv013710 2019-05-08 19:09 采纳率: 96.7%
浏览 1068
已采纳

vs2010 MFC 对话框程序 窗口拖动缩放

如题。
请教,如何在鼠标拖动窗口时不要onpaint,在放开鼠标时才onpaint?

我的绘图代码放在onpaint内的一个绘图函数内。
void CMyadsDlg::OnSize(UINT nType, int cx, int cy)
在上面这个函数内根据cx和cy数值,处理更新绘图所需的数据,
我看到有网友说onsizeing是拖动过程中执行,onsize是松开鼠标才执行。我现在用的onsize为啥拖动时也刷新
谢谢

  • 写回答

3条回答 默认 最新

  • threenewbee 2019-05-08 19:17
    关注

    #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)

    在OnPaint
    if(!KEY_DOWN(VK_LBUTTON))
    {
    你原来的代码
    }

    之前的问题 https://ask.csdn.net/questions/756791 不知道是否解决,如果解决,麻烦点下采纳,谢谢啦


    图片说明

    
    // Q760485View.cpp : implementation of the CQ760485View class
    //
    
    #include "pch.h"
    #include "framework.h"
    // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
    // and search filter handlers and allows sharing of document code with that project.
    #ifndef SHARED_HANDLERS
    #include "Q760485.h"
    #endif
    
    #include "Q760485Doc.h"
    #include "Q760485View.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    // CQ760485View
    
    IMPLEMENT_DYNCREATE(CQ760485View, CView)
    
    BEGIN_MESSAGE_MAP(CQ760485View, CView)
        // Standard printing commands
        ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
        ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
        ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CQ760485View::OnFilePrintPreview)
        ON_WM_CONTEXTMENU()
        ON_WM_RBUTTONUP()
        ON_WM_CREATE()
        ON_WM_TIMER()
    END_MESSAGE_MAP()
    
    // CQ760485View construction/destruction
    
    CQ760485View::CQ760485View() noexcept
    {
        // TODO: add construction code here
    
    }
    
    CQ760485View::~CQ760485View()
    {
    }
    
    BOOL CQ760485View::PreCreateWindow(CREATESTRUCT& cs)
    {
        // TODO: Modify the Window class or styles here by modifying
        //  the CREATESTRUCT cs
    
        return CView::PreCreateWindow(cs);
    }
    
    // CQ760485View drawing
    
    #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
    
    void CQ760485View::OnDraw(CDC* pDC)
    {
        CQ760485Doc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        if (!pDoc)
            return;
        if (KEY_DOWN(VK_LBUTTON))
        {
            pDC->TextOut(100, 100, _T("SIZING"), 6);
            return;
        }
        // TODO: add draw code for native data here
        CString str;
        str.Format(_T("%d"), m_count);
        RECT rect;
        rect.top = 100;
        rect.left = 100;
        rect.bottom = 200;
        rect.right = 200;
        pDC->DrawText(str, str.GetLength(), &rect, 0);
    }
    
    
    // CQ760485View printing
    
    
    void CQ760485View::OnFilePrintPreview()
    {
    #ifndef SHARED_HANDLERS
        AFXPrintPreview(this);
    #endif
    }
    
    BOOL CQ760485View::OnPreparePrinting(CPrintInfo* pInfo)
    {
        // default preparation
        return DoPreparePrinting(pInfo);
    }
    
    void CQ760485View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
        // TODO: add extra initialization before printing
    }
    
    void CQ760485View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
        // TODO: add cleanup after printing
    }
    
    void CQ760485View::OnRButtonUp(UINT /* nFlags */, CPoint point)
    {
        ClientToScreen(&point);
        OnContextMenu(this, point);
    }
    
    void CQ760485View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
    {
    #ifndef SHARED_HANDLERS
        theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
    #endif
    }
    
    
    // CQ760485View diagnostics
    
    #ifdef _DEBUG
    void CQ760485View::AssertValid() const
    {
        CView::AssertValid();
    }
    
    void CQ760485View::Dump(CDumpContext& dc) const
    {
        CView::Dump(dc);
    }
    
    CQ760485Doc* CQ760485View::GetDocument() const // non-debug version is inline
    {
        ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQ760485Doc)));
        return (CQ760485Doc*)m_pDocument;
    }
    #endif //_DEBUG
    
    
    // CQ760485View message handlers
    
    
    int CQ760485View::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        if (CView::OnCreate(lpCreateStruct) == -1)
            return -1;
    
        // TODO:  Add your specialized creation code here
    
        m_count = 0;
        SetTimer(123, 500, NULL);
        return 0;
    }
    
    void CQ760485View::OnTimer(UINT_PTR nIDEvent)
    {
        // TODO: Add your message handler code here and/or call default
    
        if (nIDEvent == 123)
        {
            m_count++;
            if (!KEY_DOWN(VK_LBUTTON))
            {
                this->GetDocument()->UpdateAllViews(NULL);
            }
        }
        CView::OnTimer(nIDEvent);
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?