ActiveX Property Pages 
Author Message
 ActiveX Property Pages

Hello all -

I want to call a function in a custom control from the control's own
property page. Is this possible in VB? I've found how to do it in C, but
would rather avoid that for now. It's becoming a quest...

Thanks!

Darren



Mon, 23 Apr 2001 03:00:00 GMT  
 ActiveX Property Pages
I'm not a VB programmer but from a COM perspective when you want to do this
sort of thing what you'd do is define a custom interface that the property
pages would use to access the function.

I assume when you say you've found how to do this C you mean you'd do it by
casting.  It's much safer to use a custom interface and doesn't lock your
property pages into the structure of your control class.

Quote:

>Hello all -

>I want to call a function in a custom control from the control's own
>property page. Is this possible in VB? I've found how to do it in C, but
>would rather avoid that for now. It's becoming a quest...

>Thanks!

>Darren



Tue, 24 Apr 2001 03:00:00 GMT  
 ActiveX Property Pages
Hello, James -

Quote:

>I'm not a VB programmer but from a COM perspective when you want to do this
>sort of thing what you'd do is define a custom interface that the property
>pages would use to access the function.

That's all well and good, but its not clear to me that this is possible in
VB.  They hide a lot of things to make it safer for the VB programmer, which
is great sometimes.  I'm used to C/C++, "the language that let's you drive
drunk," where I pay for mistakes when I make them but am allowed to make
them with wild abandon.

Quote:
>I assume when you say you've found how to do this C you mean you'd do it by
>casting.  It's much safer to use a custom interface and doesn't lock your
>property pages into the structure of your control class.

I found the following in the MSDN (and similar info other places), which I
think I follow, but my control is written in VB.  The magic below is by
using the GetObjectArray() method of the CMyPropPage class. I am thinking
that if I can pass in a pointer to the property page object (which should be
possible) to a custom C++ DLL, I should be able to call
pMyPPPointer->GetObjectArray(), then get pMyControl using the cast. If i
were making a variety of property pages like this, I would go to the effort
of generating the control in VC, and doing as you suggest. For now I am
looking for the quick-and-dirty (well, relatively dirty) approach...

All of these examples assume that the property page is only for a single
control, which in my case is not an issue (this will be true if you let the
wizard generate the property page).

MSDN Article ID: Q143432:

   // The header file of the control-derived class must be included in
   // the same source file.
   #include "myctrl.h"

   CMyCtrl* CMyPropPage::GetControlClass()
   {
     CMyCtrl *pMyCtrl;
     ULONG Ulong;

     // Get the array of IDispatchs stored in the property page
     LPDISPATCH FAR *m_lpDispatch = GetObjectArray(&Ulong);

     // Get the CCmdTarget object associated to any one of the above
     // array elements
     pMyCtrl = (CMyCtrl*) CCmdTarget::FromIDispatch(m_lpDispatch[0]);

     // Cleanup
     return pMyCtrl;
   }

   // If your control has a public member variable, in this case
   // I am using m_direct_control, then that variable can be
   // manipulated as follows.

   void CMyPropPage::OnLButtonDown(UINT nFlags, CPoint point)
   {
     // Modify a member variable of Control directly.
     CMyCtrl *pMyCtrl = GetControlClass();
     pMyCtrl->m_direct_control++;

     // Display the new value of the variable in a message box.
     char buf[100];
     AfxMessageBox (_itoa (pMyCtrl->m_direct_control, buf, 10));

     COlePropertyPage::OnLButtonDown(nFlags, point);
   }



Tue, 24 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Activex property page question

2. ActiveX Property Page OK

3. How to Hide the Default Property Page for an ActiveX Control in Front Page

4. Host for Property Pages or Public Property Page

5. Host for Property Pages or Public Property Page

6. Setting an ActiveX-property from a web-page?

7. Help: Property Pages in ActiveX controls

8. ActiveX Control Property Pages

9. ActiveX Control Property Page Bug

10. ActiveX Control Property Page Bug

11. Property Pages at Runtime of a ActiveX Control

12. Property Page Usage Cause ActiveX Control Corruption

 

 
Powered by phpBB® Forum Software