// 定义一个无边框的对话框,类型是WS_CHILD,记住选中Visible.// 头文件
#if !defined(AFX_MYDIALOG_H__69D79D95_CFD6_48A2_B4AA_6C39942E936E__INCLUDED_)
#define AFX_MYDIALOG_H__69D79D95_CFD6_48A2_B4AA_6C39942E936E__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyDialog.h : header file
///////////////////////////////////////////////////////////////////////////////
// CMyDialog dialogclass CMyDialog : public CDialog
{
// Construction
public:
CMyDialog(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CMyDialog)
enum { IDD = IDD_DIALOG1 };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CMyDialog)
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYDIALOG_H__69D79D95_CFD6_48A2_B4AA_6C39942E936E__INCLUDED_)// CPP文件
// MyDialog.cpp : implementation file
//#include "stdafx.h"
#include "TestFHOCX.h"
#include "MyDialog.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMyDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlersvoid CMyDialog::OnButton1()
{
MessageBox("Test IS OK!");
}
#if !defined(AFX_MYDIALOG_H__69D79D95_CFD6_48A2_B4AA_6C39942E936E__INCLUDED_)
#define AFX_MYDIALOG_H__69D79D95_CFD6_48A2_B4AA_6C39942E936E__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyDialog.h : header file
///////////////////////////////////////////////////////////////////////////////
// CMyDialog dialogclass CMyDialog : public CDialog
{
// Construction
public:
CMyDialog(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CMyDialog)
enum { IDD = IDD_DIALOG1 };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CMyDialog)
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYDIALOG_H__69D79D95_CFD6_48A2_B4AA_6C39942E936E__INCLUDED_)// CPP文件
// MyDialog.cpp : implementation file
//#include "stdafx.h"
#include "TestFHOCX.h"
#include "MyDialog.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMyDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlersvoid CMyDialog::OnButton1()
{
MessageBox("Test IS OK!");
}
#define AFX_TESTFHOCXCTL_H__2B4D172A_8FED_4FF2_BC46_02D41D286192__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include "MyDialog.h"// TestFHOCXCtl.h : Declaration of the CTestFHOCXCtrl ActiveX Control class./////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl : See TestFHOCXCtl.cpp for implementation.class CTestFHOCXCtrl : public COleControl
{
DECLARE_DYNCREATE(CTestFHOCXCtrl)// Constructor
public:
CTestFHOCXCtrl();// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestFHOCXCtrl)
public:
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
virtual void DoPropExchange(CPropExchange* pPX);
virtual void OnResetState();
//}}AFX_VIRTUAL// Implementation
protected:
~CTestFHOCXCtrl();// ********************注意声明对象*********************
CMyDialog dlg;
// ********************注意声明对象********************* DECLARE_OLECREATE_EX(CTestFHOCXCtrl) // Class factory and guid
DECLARE_OLETYPELIB(CTestFHOCXCtrl) // GetTypeInfo
DECLARE_PROPPAGEIDS(CTestFHOCXCtrl) // Property page IDs
DECLARE_OLECTLTYPE(CTestFHOCXCtrl) // Type name and misc status// Message maps
//{{AFX_MSG(CTestFHOCXCtrl)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()// Dispatch maps
//{{AFX_DISPATCH(CTestFHOCXCtrl)
// NOTE - ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP() afx_msg void AboutBox();// Event maps
//{{AFX_EVENT(CTestFHOCXCtrl)
// NOTE - ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_EVENT
DECLARE_EVENT_MAP()// Dispatch and event IDs
public:
enum {
//{{AFX_DISP_ID(CTestFHOCXCtrl)
// NOTE: ClassWizard will add and remove enumeration elements here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_DISP_ID
};
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_TESTFHOCXCTL_H__2B4D172A_8FED_4FF2_BC46_02D41D286192__INCLUDED)
#include "TestFHOCX.h"
#include "TestFHOCXCtl.h"
#include "TestFHOCXPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CTestFHOCXCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message mapBEGIN_MESSAGE_MAP(CTestFHOCXCtrl, COleControl)
//{{AFX_MSG_MAP(CTestFHOCXCtrl)
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch mapBEGIN_DISPATCH_MAP(CTestFHOCXCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CTestFHOCXCtrl)
// NOTE - ClassWizard will add and remove dispatch map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CTestFHOCXCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event mapBEGIN_EVENT_MAP(CTestFHOCXCtrl, COleControl)
//{{AFX_EVENT_MAP(CTestFHOCXCtrl)
// NOTE - ClassWizard will add and remove event map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CTestFHOCXCtrl, 1)
PROPPAGEID(CTestFHOCXPropPage::guid)
END_PROPPAGEIDS(CTestFHOCXCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guidIMPLEMENT_OLECREATE_EX(CTestFHOCXCtrl, "TESTFHOCX.TestFHOCXCtrl.1",
0xa10cf65e, 0x9c9c, 0x48e2, 0xb3, 0x69, 0x7e, 0xb, 0x54, 0x9b, 0xb1, 0x5d)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and versionIMPLEMENT_OLETYPELIB(CTestFHOCXCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDsconst IID BASED_CODE IID_DTestFHOCX =
{ 0x20388a7f, 0x33d2, 0x4451, { 0x91, 0x30, 0xa0, 0xdf, 0x9f, 0xf5, 0x6a, 0x24 } };
const IID BASED_CODE IID_DTestFHOCXEvents =
{ 0x43ce1439, 0x8c55, 0x46c3, { 0xb2, 0xf5, 0xcd, 0x16, 0x73, 0x65, 0x1d, 0xb2 } };
/////////////////////////////////////////////////////////////////////////////
// Control type informationstatic const DWORD BASED_CODE _dwTestFHOCXOleMisc =
OLEMISC_SIMPLEFRAME |
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;IMPLEMENT_OLECTLTYPE(CTestFHOCXCtrl, IDS_TESTFHOCX, _dwTestFHOCXOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl::CTestFHOCXCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CTestFHOCXCtrlBOOL CTestFHOCXCtrl::CTestFHOCXCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0. if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_TESTFHOCX,
IDB_TESTFHOCX,
afxRegApartmentThreading,
_dwTestFHOCXOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl::CTestFHOCXCtrl - ConstructorCTestFHOCXCtrl::CTestFHOCXCtrl()
{
InitializeIIDs(&IID_DTestFHOCX, &IID_DTestFHOCXEvents); EnableSimpleFrame(); // TODO: Initialize your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl::~CTestFHOCXCtrl - DestructorCTestFHOCXCtrl::~CTestFHOCXCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl::OnDraw - Drawing functionvoid CTestFHOCXCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->Ellipse(rcBounds);
}
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl::DoPropExchange - Persistence supportvoid CTestFHOCXCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX); // TODO: Call PX_ functions for each persistent custom property.}
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl::OnResetState - Reset control to default statevoid CTestFHOCXCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange // TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl::AboutBox - Display an "About" box to the uservoid CTestFHOCXCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_TESTFHOCX);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CTestFHOCXCtrl message handlersint CTestFHOCXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1; // 在这里创建对象。显示即可, 你还可以调整位置和大小。 dlg.Create(IDD_DIALOG1, this);
dlg.ShowWindow(SW_SHOW);
return 0;
}