如何在ActiveX Controls里面调用其它的COM ???

huangbeyond 2003-02-28 02:57:08
我写了一个ActiveX Controls(MFC的.ocx程序),我希望能够在该运行能够使用其它的COM,比如flash的控件,或者某些MEDIA的COM,我该如何进行?!

能够在一个OCX里调用其它的COM吗?
如果能,在该OCX里,应该使用哪些MFC类或者API来使用那些COM?!
...全文
147 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zfan333 2003-02-28
  • 打赏
  • 举报
回复
楼上的好长,我没看。。
你要使用别的控件,有几种情况。一:只需要使用某些功能性的调用。这种情况下,你只需要创建有关的com对象,根据接口调用功能就可以了。二:你需要依赖别的控件的比较复杂的功能,比如涉及到显示。这种情况,你需要完成一个包容器的工作。可以使用atl复合控件,它已经完成了包容器的代码。
masterz 2003-02-28
  • 打赏
  • 举报
回复
just as you do in other program, the difference is that you don't have to call CoInitialize(NULL);
////////////////////////////////////////////////////////////////////////////////
// Use swflash.ocx to play flash
// if it works, it is written by masterz, otherwise I don't know who writes it(*_*)
////////////////////////////////////////////////////////////////////////////////
#define MAX_LOADSTRING 100
#import "c:\winnt\system32\macromed\flash\flash.ocx"
#include <atlbase.h>
CComModule _Module;
#include <atlwin.h>
#pragma comment(lib,"atl")
#define ODS(x) OutputDebugString(x)


// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
CAxWindow m_container;
using namespace ShockwaveFlashObjects;
IShockwaveFlash* shwaveflash;

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Initialize global strings
wsprintf(szTitle,"use flash control in sdk exe");
wsprintf(szWindowClass,"flashinsdk");
MyRegisterClass(hInstance);
CoInitialize(NULL);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
return FALSE;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
return msg.wParam;
}

// FUNCTION: MyRegisterClass()
// PURPOSE: Registers the window class.
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;//(LPCSTR)IDC_FLSH;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
return RegisterClassEx(&wcex);
}

// FUNCTION: InitInstance(HANDLE, int)
// PURPOSE: Saves instance handle and creates main window
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
AtlAxWinInit();
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
HWND heditfilepath;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
wsprintf(szHello,"use flash control in sdk");
HWND hbtnstart;
HWND hbtOpenFile;
RECT rc;
switch (message)
{
case WM_CREATE:
GetClientRect(hWnd, &rc );
rc.top = (rc.bottom+rc.top)/2;
m_container.Create( hWnd, rc, LPCTSTR("ShockwaveFlash.ShockwaveFlash.1"), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL );//create a browser control
hbtnstart=CreateWindow("BUTTON","play",WS_CHILD|WS_VISIBLE,0,0,120,30,hWnd,(HMENU)0x100,hInst,0);
hbtOpenFile = CreateWindow("BUTTON","Open...",WS_CHILD|WS_VISIBLE,130,0,100,30,hWnd,(HMENU)0x101,hInst,0);

heditfilepath=CreateWindow("EDIT","filepath",WS_CHILD|WS_VISIBLE|WS_BORDER,0,40,420,30,hWnd,(HMENU)0x101,hInst,0);
SetWindowText(heditfilepath,"c:\\downloads\\Sayforever.swf");
m_container.QueryControl( __uuidof(IShockwaveFlash), reinterpret_cast<void**>(&shwaveflash) );
break;
case WM_SIZING:
GetClientRect(hWnd, &rc );
rc.top = (rc.bottom+rc.top)/2;
m_container.MoveWindow(&rc,true);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case 0x100:
{
ODS("0x100");
char buf[256];
GetWindowText(heditfilepath,buf,255);
_bstr_t bstr((char*)buf);
ODS(buf);
//bstr=_bstr_t("c:\\2.1.swf");
shwaveflash->put_Movie(bstr); // you have to change the path here
shwaveflash->Play();
}
break;
case 0x101:
{

char fileName[256];
fileName[0]=0;
OPENFILENAME ofStruct;
ZeroMemory(&ofStruct,sizeof(ofStruct));
ofStruct.lStructSize=sizeof(OPENFILENAME);
ofStruct.hwndOwner=hWnd;
ofStruct.nFilterIndex=1;
ofStruct.lpstrFile=fileName;
ofStruct.nMaxFile=sizeof(fileName);
ofStruct.lpstrTitle="Choose a flash";
ofStruct.Flags=OFN_FILEMUSTEXIST;
ofStruct.lpstrDefExt="*";
ofStruct.lpstrInitialDir="C:\\Downloads";
if(HIWORD(wParam)==BN_CLICKED)
if(GetOpenFileName(&ofStruct))
{
SetWindowText(heditfilepath,ofStruct.lpstrFile);
_bstr_t bstr((char*)ofStruct.lpstrFile);
shwaveflash->put_Movie(bstr); // you have to change the path here
shwaveflash->Play();
}
DWORD dwerr=CommDlgExtendedError();
switch(dwerr) {
case CDERR_DIALOGFAILURE:
OutputDebugString("CDERR_DIALOGFAILURE");
break;
case CDERR_FINDRESFAILURE:
OutputDebugString("CDERR_FINDRESFAILURE");
break;
case CDERR_INITIALIZATION:
OutputDebugString("CDERR_INITIALIZATION");
break;
default:
break;
;
}

}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
huangbeyond 2003-02-28
  • 打赏
  • 举报
回复
希望有经验的朋友帮帮忙啊!!

3,248

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧