but it works fine !
// ---------------------------------------------------------------
// Project: You wanna Rendering 3D materials using Irrlicht on the Web ?
// ---------------------------------------------------------------
// Purpose: Irrlicht as ActiveX Control on the Web Browser such as Internet Explorer.
// Author : June (godmode2k@hotmail.com | MSN)
// Date : July. 2nd. 2007, KST
// ---------------------------------------------------------------
// Note : Ready ?
// Update:
// + August 28, 2008:
// 1. You can check out full of source code relevant this thread below link.
// http://code.google.com/p/gedk/downloads/list
// ---------------------------------------------------------------
Q: I don't know how to create an ActiveX Control with Visual C++ !!!
A: Don't worry baby. See below site.
http://www.codeguru.com/cpp/com-tech/activex/
http://www.codeproject.com/KB/COM/CompleteActiveX.aspx
[STEP #1]
Make an ActiveX Control using MS-VC++ (6.0 or whatever) where Project - > "MFC ActiveX ControlWizard" tab.
Its done ?
[STEP #2]
Adds below code.
Code: Select all
//! ~Ctl.h
// ---------------------------------------------------------------
class ~Ctrl : public COleControl
{
public:
...
// ADD [
HWND m_hWnd;
HWND m_hIrrlichtWindow;
HINSTANCE m_hInstance;
bool m_IsFirst; // set flag, at drawing first time via OnDraw(...)
void EngineTest(CWnd* cWnd);
// ]
...
};
// ---------------------------------------------------------------
Code: Select all
//! ~Ctl.cpp
// ---------------------------------------------------------------
// Global Variable
#include "stdafx.h"
#include "~.h"
#include "~Ctl.h"
#include "~Ppg.h"
//! Here !
#include <irrlicht.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 3D Engine Test
// -----------------------------------------------------------------------------
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
IrrlichtDevice *device = 0;
video::IVideoDriver* driver = 0;
IGUIEnvironment* env = 0;
scene::ISceneManager* smgr = 0;
s32 cnt = 0;
IGUIListBox* listbox = 0;
HWND g_hWnd;
// -----------------------------------------------------------------------------
...
CTest_engine_activex_vc60Ctrl::CTest_engine_activex_vc60Ctrl()
{
InitializeIIDs(&IID_DTest_engine_activex_vc60, &IID_DTest_engine_activex_vc60Events);
// TODO: Initialize your control's instance data here.
// ADD [
m_IsFirst = true;
// ]
}
void ~Ctrl::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);
// ADD [
if( m_IsFirst ) {
m_IsFirst = false;
EngineTest( pdc->GetWindow() );
}
// ]
//! EventReceiver
// Yes, you using your own EventReceiver class as before.
// ADD [
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
...
}
...
};
// ]
void ~Ctrl::EngineTest(CWnd* cWnd)
{
// ADD [
//! Set for Child Window as a Button
// -----------------------------------------
video::E_DRIVER_TYPE driverType;
driverType = video::EDT_OPENGL;
MyEventReceiver receiver;
irr::SIrrlichtCreationParameters param;
m_hWnd = cWnd->m_hWnd;
m_hInstance = AfxGetInstanceHandle();
m_hIrrlichtWindow = CreateWindow("BUTTON", "Test Engine On The ActiveX", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 10, 200, 640, 480, m_hWnd, NULL, m_hInstance, NULL);
param.WindowId = reinterpret_cast<s32>( m_hIrrlichtWindow );
param.DriverType = driverType;
device = createDeviceEx( param );
device->setEventReceiver(&receiver);
// -----------------------------------------
// Your code
// -----------------------------------------
//! Prepare to Rendering
// -----------------------------------------
g_hWnd = m_hWnd;
::ShowWindow( m_hIrrlichtWindow , SW_SHOW );
::UpdateWindow( m_hIrrlichtWindow );
while( device->run() && driver ) {
//! "isWindowActivate()" isn't work here.
//if( device->isWindowActive() ) {
driver->beginScene(true, true, SColor(0,200,200,200));
smgr->drawAll();
env->drawAll();
driver->endScene();
//! ^___^
::UpdateWindow( m_hIrrlichtWindow );
//}
}
// ]
}
//! Mouse Event
// ClassWizard -> add Message "WM_MOUSEACTIVATE"
int ~Ctrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
// ADD [
OnActivateInPlace( true, NULL );
// ]
return COleControl::OnMouseActivate(pDesktopWnd, nHitTest, message);
}
// ---------------------------------------------------------------