vs2015
工具栏.png
类向导.png
创建控件类.png
BOOL CMyControl::RegisterWindowClass(HINSTANCE hInstance)
{
LPCWSTR className = L"CMyControl";//"CMyControl"控件类的名字
WNDCLASS windowclass;
if (hInstance)
hInstance = AfxGetInstanceHandle();
if (!(::GetClassInfo(hInstance, className, &windowclass)))
{
windowclass.style = CS_DBLCLKS;
windowclass.lpfnWndProc = ::DefWindowProc;
windowclass.cbClsExtra = windowclass.cbWndExtra = 0;
windowclass.hInstance = hInstance;
windowclass.hIcon = NULL;
windowclass.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
windowclass.hbrBackground = ::GetSysColorBrush(COLOR_WINDOW);
windowclass.lpszMenuName = NULL;
windowclass.lpszClassName = className;
}
return AfxRegisterClass(&windowclass);
}
CMyControl::CMyControl()
{
RegisterWindowClass();
}
控件属性.png
void CMyTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CUSTOM1, m_control);
}
以上步骤就完成了一个简单的自定控件