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

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

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

#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);
}

因为现在的操作系统都是在鼠标左键按下并且移动的过程中就“改变了窗口大小”,因此这两个消息都会触发的。
简单说,你处理OnSize就够了。

鼠标按下时候做个标记,移动时候也做一个,两个标记为真时候,onpaint函数内直接返回不做绘图,你试试这样行不行。