MFC的自定义控件步骤

2018-02-23  本文已影响0人  JasonChen8888

MFC的自定义控件

开发环境

vs2015

步骤:

 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();
  }
 void CMyTestDlg::DoDataExchange(CDataExchange* pDX)
 {
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_CUSTOM1, m_control);
 }

以上步骤就完成了一个简单的自定控件

上一篇 下一篇

猜你喜欢

热点阅读