Click here to Skip to main content
15,883,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm very aware of how to use an activeX control's properties in HTML. But how do you access the methods of an activeX in HTML? I've tried google, ehow, stack overflow, and other sites. Nothing worked. My custom C++ ActiveX embeds in the webpage perfectly, but it's useless unless I can use the methods. BTW - What is the difference between methods and properties? they are the same except methods are better because they can have more than one stupid parameter in the syntax. (AFAIK)
Posted

1 solution

You just use the dot operator - the same as you do in vb.
Take this sample for example:
JavaScript
var excelApp=null, excelFile=null, excelSheet=null;

function initExcel(filename)
{
  excelApp = new ActiveXObject("Excel.Application");
  excelFile = excelApp.Workbooks.Open(filename);
  excelSheet = excelApp.Worksheets('Sheet1');
}


As for methods/properties - they're quite simply what their names imply - properties hold information about the object, methods are things that the object can do (functions).

WorkBooks is a property, Open is a method of that property.
Worksheets is another property of excelApp.

Properties can be simple types, like int, char, byte etc - or they can be objects with several properties/methods.

But in short - property=data, method=function. :)
 
Share this answer
 
Comments
time-killer-games 23-Aug-12 19:40pm    
For the strangest reason, I feel that I've already tried that. I'll give it another go once I get home.
time-killer-games 31-Aug-12 13:42pm    
//Does this require a specific way to write my OCX plugin? I tried that and it didn't work.
//Here's all I have in my code, apart from what is automatically generated by the ActiveX OCX project templet:

HANDLE handle;
HWND apphwnd;

int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{
DWORD pID;
DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);
if (TpID == (DWORD)param)
{
apphwnd=hwnd;
return false;
}
return true;
}

HANDLE StartProcess(LPCTSTR program, LPCTSTR args)
{

HANDLE hProcess = NULL;
PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
::ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
if(::CreateProcess(program, (LPTSTR)args,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&startupInfo,
&processInfo))
{
::EnumWindows(&EnumWindowsProc, processInfo.dwThreadId);
hProcess = processInfo.hProcess;
WaitForSingleObject(hProcess,INFINITE);
}
return hProcess;
}

void HostExe(LPCTSTR Exe)
{
CRect rect;
GetClientRect(GetActiveWindow(),&rect);
handle=StartProcess(Exe,Exe);
if(apphwnd!=NULL)
{
::SetParent(apphwnd,GetActiveWindow());
SetWindowLong(apphwnd, GWL_STYLE, WS_VISIBLE);
::MoveWindow(apphwnd, rect.left, rect.top,rect.right, rect.bottom, true);

}
}

void CHostExe2Ctrl::HostingStartEmbed(LPCTSTR Exe)
{
HostExe(Exe);
}

void CHostExe2Ctrl::HostingEndEmbed()
{
TerminateProcess(handle,0);
}

void CHostExe2Ctrl::HostingSetRectangle(long Left, long Top, long Right, long Bottom)
{
::MoveWindow(apphwnd,Left,Top,Right,Bottom,true);
}

void CHostExe2Ctrl::HostingSetParent(LPCTSTR Parent)
{
::SetParent(apphwnd,(HWND)Parent);
}

void CHostExe2Ctrl::HostingSetChild(LPCTSTR Child)
{
::SetParent((HWND)Child,(HWND)GetActiveWindow());
}

//I added the methods with the class wizard. Is there anything else I need to add to access these methods from IE?
//Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900