Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing an hwnd to activeX control

Status
Not open for further replies.

gorgor

Programmer
Aug 15, 2002
164
US
I have an MFC application. In the application, I create 2 activeX controls (using CWnd's CreateControl() function),(control A and control B). I made the controls so I can add whatever I need to them. I guess it's important to note that both controls are created AND visible. Control A has a custom property of type 'unsigned long'. I use control A's property to pass it the HWND of control B. The application actually does the work. It passes control A the HWND of control B through control A's IDispatch interface. In control A, I cast the unsigned long to an HWND variable. I then attach the HWND to a CWnd object. I then have 'full' control over control B from control A. I can then do whatever I want to control B from control A. That is, I can perform standard CWnd methods on control B. This is the code I have used in control A:

ASSERT(m_hControlB != NULL);
CWnd * controlBCwnd = new CWnd;
controlBCwnd->Attach(m_hControlB);

//Do standard CWnd stuff here to control B.

controlBCwnd->Detach();
delete controlBCwnd;

What I really need to do is to set control B's properties from control A. This doesn't seem to be working since controlBCwnd isn't a pointer to an OLE control-type CWnd object?? It's just a standard CWnd. When I try to get a pointer to control B's IUnknown interface from control A, the program crashes. Being able to move control B around from control A is pretty cool, but that's not what I need to do. I need to set control B's properties from control A but it doesn't seem to work.

I hope this question is clear enough. It's hard to word the question so that it isn't too long to read.

Thanks in advance for any ideas.
 
For set properties/executing functions of control B from any other places you should use IDispatch of Control B. When you pass a HWND, you can perform only standard window operations with it. If there is an ActiveX, your controls use many than a single window in its location. So, you should find all of windows you need. Also if controls are in some container, you can do only what container allow you to do.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top