在填充Formview时,遇到0XC000041D:用户回调期间遇到未经处理的异常(已解决)

原因:HBRUSH hbr = OnCtlColor(pDC, pWnd, nCtlColor);这一句中应该在OnCtlColor前面添加命名空间:: 否则编译器会误解为递归函数

源码如下:

#pragma once
#include "NormalBtn.h"
#include "resource.h"
#include <Gdiplus.h>
using namespace Gdiplus;

// View_OnlineShopManagement 窗体视图

class View_OnlineShopManagement : public CFormView
{
    DECLARE_DYNCREATE(View_OnlineShopManagement)

protected:
    View_OnlineShopManagement();           // 动态创建所使用的受保护的构造函数
    virtual ~View_OnlineShopManagement();

public:
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_FORMVIEW_OSM };
#endif
#ifdef _DEBUG
    virtual void AssertValid() const;
#ifndef _WIN32_WCE
    virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
    DECLARE_MESSAGE_MAP()

public:
    
    virtual void OnInitialUpdate();
    GdiplusStartupInput m_gdiplusStartupInput;
    ULONG_PTR m_gdiplusToken;
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    virtual void OnDraw(CDC* /*pDC*/);
};



// View_OnlineShopManagement.cpp : 实现文件
//
#include "stdafx.h"
#include "SD3000BAS.h"
#include "View_OnlineShopManagement.h"

// View_OnlineShopManagement

IMPLEMENT_DYNCREATE(View_OnlineShopManagement, CFormView)

View_OnlineShopManagement::View_OnlineShopManagement()
    : CFormView(IDD_FORMVIEW_OSM)
{
}

View_OnlineShopManagement::~View_OnlineShopManagement()
{
}

void View_OnlineShopManagement::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);
    //DDX_Control(pDX, IDC_BUTTON1, register_btn);
}

BEGIN_MESSAGE_MAP(View_OnlineShopManagement, CFormView)
    ON_WM_CTLCOLOR()
END_MESSAGE_MAP()


// View_OnlineShopManagement 诊断

#ifdef _DEBUG
void View_OnlineShopManagement::AssertValid() const
{
    CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void View_OnlineShopManagement::Dump(CDumpContext& dc) const
{
    CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// View_OnlineShopManagement 消息处理程序


void View_OnlineShopManagement::OnInitialUpdate()
{
    CFormView::OnInitialUpdate();
    
    // TODO: 在此添加专用代码和/或调用基类
}

HBRUSH View_OnlineShopManagement::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    //HBRUSH hbr = OnCtlColor(pDC, pWnd, nCtlColor);    //问题出现在这里!!!!!
    HBRUSH hbr = CFormView::CFormView(pDC, pWnd, nCtlColor); //改成这样问题解决
    // TODO:  在此更改 DC 的任何特性
    static CBrush gBr;
    static bool isInited = false;
    if (!isInited)
    {
        CBitmap bitmap;
        bitmap.LoadBitmap(IDB_BITMAP1);
        gBr.CreatePatternBrush(&bitmap);
        COLORREF clearColor = -1;
        bitmap.DeleteObject();
        isInited = true;
    }
    if (pWnd == this)
    {
        pDC->SetBkMode(TRANSPARENT);
        return gBr; //主窗口背景使用这个背景刷
    }
    else
    {
        pDC->SetBkMode(TRANSPARENT);
        return   (HBRUSH)::GetStockObject(NULL_BRUSH); //其他控件使用透明背景
    }


    // TODO:  如果默认的不是所需画笔,则返回另一个画笔
    return hbr;
}


void View_OnlineShopManagement::OnDraw(CDC* /*pDC*/)
{

}