关于custom control的问题,求教大神
mfc吧
全部回复
仅看楼主
level 2
CHRF000 楼主
小白,自己写了一个custom control ,出现断点,不知道是什么原因,求大神不吝赐教。代码如下
#include "stdafx.h"
#include "Mine.h"
#define MYWNDCLASS "Mine"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BOOL Mine::InitWnd()
{
WNDCLASS windowclass;
HINSTANCE hInst = AfxGetInstanceHandle();
if (!(::GetClassInfo(hInst, MYWNDCLASS, &windowclass)))
{
windowclass.style = CS_DBLCLKS;
windowclass.lpfnWndProc = ::DefWindowProc;
windowclass.cbClsExtra = windowclass.cbWndExtra = 0;
windowclass.hInstance = hInst;
windowclass.hIcon = NULL;
windowclass.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
windowclass.hbrBackground = ::GetSysColorBrush(COLOR_WINDOW);
windowclass.lpszMenuName = NULL;
windowclass.lpszClassName = MYWNDCLASS;
if (!AfxRegisterClass(&windowclass))
{
AfxThrowResourceException();
return FALSE;
}
}
return TRUE;
}
Mine::Mine() noexcept
{
InitWnd();
position = 0;
this->range = 100;
judge = FALSE;
}
Mine::~Mine()
{
}
void Mine::OnDraw(CDC* pDC)
{
//pDC->TextOutA(0, 0, "你好");
CRect dcRect;
GetClientRect(dcRect);
dcRect.right = position;
CBrush brush;
brush.CreateSolidBrush(RGB(0, 0, 255));
pDC->FillRect(dcRect, &brush);
}
BEGIN_MESSAGE_MAP(Mine, CView)
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
void Mine::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CView::OnTimer(nIDEvent);
}
void Mine::OnLButtonDown(UINT nFlags, CPoint point)
{
position = point.x;
this->Invalidate();
judge = true;
CView::OnLButtonDown(nFlags, point);
}
void Mine::OnMouseMove(UINT nFlags, CPoint point)
{
if (judge)
{
position = point.x;
this->Invalidate();
}
CView::OnMouseMove(nFlags, point);
}
void Mine::OnLButtonUp(UINT nFlags, CPoint point)
{
judge = false;
CView::OnLButtonUp(nFlags, point);
}
再次拜谢大神
2019年01月04日 12点01分 1
1