首页 > 解决方案 > 使用 SetWindowPos 函数时的 MFC 调试断言

问题描述

当我尝试运行该程序时,我收到一条消息“调试断言失败,~\MFC\winoccc.cpp 第 314 行。

这些是我的消息处理程序

BEGIN_MESSAGE_MAP(CProjectMainDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_MAIN, &CProjectMainDlg::OnSelchangeTabMain)
ON_WM_SIZE()
END_MESSAGE_MAP()

我正在尝试在对话框中调整 Wnd 项目的大小。

void CProjectMainDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);

LOG_TRACE(_T("ON_SIZE : nType=%u, cx=%u, cy=%u"), nType, cx, cy);

if (!m_bInitialized)
    return;

CRect cClientRect;
GetClientRect(cClientRect);

m_dlgCalculator.SetWindowPos(&CCalculator::wndBottom, cClientRect.left, cClientRect.top, 
cClientRect.Width(), cClientRect.Height(), SWP_SHOWWINDOW | SWP_DRAWFRAME);
}


m_tabSelection.DeleteAllItems();
m_tabSelection.InsertItem(0, _T("Calc"));
m_tabSelection.InsertItem(1, _T("Paint"));
m_tabSelection.InsertItem(2, _T("Image Test"));

CRect rect;
CRect rect_tab;
m_tabSelection.GetWindowRect(&rect_tab);    //Copies the dimension of tabSelection

CPoint point;       //TopLeft Poiintof TabConrol
point = rect_tab.TopLeft();

//Add Calculator to Tab
m_dlgCalculator.Create(IDD_DIALOG_CALCULATOR, &m_tabSelection); 
m_dlgCalculator.GetWindowRect(&rect);
m_dlgCalculator.MoveWindow(point.x, point.y, rect.Width(), rect.Height());
m_dlgCalculator.ShowWindow(SW_SHOW);

//Add Paint Board to Tab
m_dlgPaintBoard.Create(IDD_DIALOG_PAINTBOARD, &m_tabSelection);
m_dlgPaintBoard.GetWindowRect(&rect);       
m_dlgPaintBoard.MoveWindow(point.x, point.y, rect.Width(), rect.Height());
m_dlgPaintBoard.ShowWindow(SW_HIDE);


//Add Image Test to Tab
m_dlgImageTest.Create(IDD_DIALOG_IMAGETEST, &m_tabSelection);
m_dlgImageTest.GetWindowRect(&rect);
m_dlgImageTest.MoveWindow(point.x, point.y, rect.Width(), rect.Height());
m_dlgImageTest.ShowWindow(SW_HIDE);

这是弹出警报消息的行。

void CCalculator::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);


CRect cRect;
GetClientRect(cRect);

m_ResultList.SetWindowPos(NULL, cRect.left + 300, cRect.top , cRect.Width()/3, cRect.Height(), SWP_SHOWWINDOW);
}

最后一句是我收到警报消息的地方。当我评论该行时,我没有收到消息。我不知道如何解决这个问题。

这是我的 CCalculatorDlg.h 文件

class CCalculator : public CDialogEx
{
DECLARE_DYNAMIC(CCalculator)

public:
CCalculator(CWnd* pParent = nullptr);   // 표준 생성자입니다.
virtual ~CCalculator();

// 대화 상자 데이터입니다.
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_DIALOG_CALCULATOR };
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 지원입니다.

DECLARE_MESSAGE_MAP()
afx_msg void OnClickedButton0();
afx_msg void OnClickedButton1();
afx_msg void OnClickedButton2();
afx_msg void OnClickedButton3();
afx_msg void OnClickedButton4();
afx_msg void OnClickedButton5();
afx_msg void OnClickedButton6();
afx_msg void OnClickedButton7();
afx_msg void OnClickedButton8();
afx_msg void OnClickedButton9();
afx_msg void OnClickedButtonPlus();
afx_msg void OnClickedButtonMinus();
afx_msg void OnClickedButtonMultipy();
afx_msg void OnClickedButtonDivide();
afx_msg void OnClickedButtonCalculate();
afx_msg void OnClickedButtonPoint();
afx_msg void OnClickedButtonDelete();
afx_msg void OnClickedButtonReset();

protected:
CEdit           m_EditInput;        // 인풋
CListBox        m_ResultList;

CString         m_strInput;     
bool            m_bFirstValue;      // 첫번째값이 입력되었는지 확인하는 값
float           m_fValue1;          // 첫번째 계산 값
int             m_intMode;          // 어떤 계산을 할것인가 0 = 덧셈, 1= 뺄셈, 2는 곱셈 3은 나눗셈
bool            m_bNewCalc;
bool            m_bCalcEnable;

void            Calculate();        //계산을 수행
void            ResetCalculator();  //계산기 초기화
void            StartNewCalc();     //계산이후 인풋값 초기화


public:
afx_msg void OnSize(UINT nType, int cx, int cy);
};

标签: c++windowsmfc

解决方案


推荐阅读