描述:
如何在ATL下ActiveX控件,具有可视化,能否像MFC的VIEW或者DIALOG那样显示呢.
解决方案1:
for dialog
class CMyDialog : public CDialogImpl<CMyDialog>
{
BEGIN_MSG_MAP( CMyDialog )
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDOK, OnOk)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()
public:
CMyDialog();
~CMyDialog();
enum{ IDD = IDD_DLGSUBCLASS };
public:
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// TODO : Add Code for message handler. Call DefWindowProc if necessary.
pm.SubclassWindow( GetDlgItem( IDC_EDITSUBCLASS ) );
return 0;
}
LRESULT OnOk( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled )
{
EndDialog( wID );
return 0;
}
LRESULT OnCancel( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled )
{
EndDialog( wID );
return 0;
}
CNoNumEdit pm;
};
1、像View一样,直接用MFC ActiveX向导生成就Ok了
2、像Dialog一样,看下边文章:
http://www.codeguru.com/Cpp/COM-Tech/activex/controls/article.php/c2615/
class CAboutUS :
public CAxDialogImpl<CAboutUS>
{
public:
CAboutUS()
{
m_hDialogBrush = CreateSolidBrush(RGB(255,255, 255));
}
~CAboutUS()
{
DeleteObject(m_hDialogBrush);
}
enum { IDD = IDD_ABOUTUS };
BEGIN_MSG_MAP(CAboutUS)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
MESSAGE_HANDLER(WM_CTLCOLORDLG, OnCtlColorDlg) //Add this macro
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorDlg) //Add this macro
END_MSG_MAP()
public:
HBRUSH m_hDialogBrush;
// Handler prototypes:
// LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
// LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
// LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 1; // Let the system set the focus
}
LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
//EndDialog(wID);
DestroyWindow();
return 0;
}
LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
//EndDialog(wID);
DestroyWindow();
return 0;
}
LRESULT OnCtlColorDlg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return (long) m_hDialogBrush;
// return 0;
}
};
调用:
CAboutUSDlg AboutUSDlg;
AboutUSDlg.Create(g_hMainWnd,NULL);//g_hMainWnd是网页的主窗口句柄
AboutUSDlg.ShowWindow(SW_SHOW);
CAxWindow TempWnd = AboutUSDlg;
TempWnd.CenterWindow(NULL);