VC++ 自界說控件的樹立及應用辦法。本站提示廣大學習愛好者:(VC++ 自界說控件的樹立及應用辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是VC++ 自界說控件的樹立及應用辦法正文
1、VC++界說自界說控件與delphi,VB有些差別。
delphi,vb在 file-new-other中樹立。vc++在對象欄中就有自界說控件,但必需參加控件類型。
很多書本都在類領導中樹立。我這裡引見的是手動樹立,其成果是一樣的。
二.樹立過自界說控件類型:
2.1、把對象欄上的自界說控件放入對話框中
2.2、樹立Mycontrol.h, Mycontrol.cpp文件
2.3、Mycontrol.h中的界說是
#ifndef __MYCTROLTRL_H__
#define __MYCTROLTRL_H__
#define MYWNDCLASS "mycontrol"
#include <afxtempl.h>
class CMycontrol: public CWnd
{
private:
public:
static BOOL RegisterWndClass();
CMycontrol();
void customfun();//一個自界說辦法
};
#endif
2.4 Mycontrol.cpp中的完成部門
#include "StdAfx.h"
#include "mycontrol.h"
CMycontrol::CMycontrol()
{
CMycontrol::RegisterWndClass();
}
//注冊控件RegisterWndClass格局是固定的不要記憶沒有誰人需要直接拷貝粘貼便可以。
CMycontrol::RegisterWndClass()
{
WNDCLASS windowclass;
HINSTANCE hInst = AfxGetInstanceHandle();
//Check weather the class is registerd already
if (!(::GetClassInfo(hInst, MYWNDCLASS, &windowclass)))
{
//If not then we have to register the new class
windowclass.style = CS_DBLCLKS;// | CS_HREDRAW | CS_VREDRAW;
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;
}
//自界說辦法
void CMycontrol::customfun()
{
AfxMessageBox(_T("my control!"));
}
3、應用自界說控件
3.1.在類領導中綁定自界說控件時你是找不到適才你界說的類型的,所以我采取手動參加代碼辦法。
3.2.在對話框.h文件中手動參加:public: CMycontrol m_mycontrol;
3.3.在對話框.cpp文件中手動參加:DDX_Control(pDX,IDC_CUSTOM1,m_mycontrol);
3.4.在對話框中參加Button 在點擊事宜中參加測試代碼:
void CCustomcontrolDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_mycontrol.customfun();
}
4、編譯運轉vc++自界說控件的對話框窗體.編譯勝利但運轉甚麼也不顯示的處理
右鍵自界說控件->屬性->類型中填寫"mycontrol"再次許可OK!
到此VC++自界說控件就全體引見終了,你可以在類型中參加你要完成的辦法。
以上所述就是本文的全體內容了,願望年夜家可以或許愛好。