Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 680
  • Last Modified:

ATL ActiveX Entry point!!!


I am developing an ATL Activex control. I want to invoke an event at startup ( run-time only ), depending upon the value of a property. The scenario is like,
the proprty name is "InvokeAtStartup", if this property is set to TRUE at design time, then the OCX is supposed to fire an event at startup during run-time. Can anyone tell me where i should write the code to test for the value of this property( there I should also be able to know, whether the control is being used as run / design time component ), and invoke the event depending upon the value of the "InvokeAtStartup" property.

Thanks in advance
1 Solution
If your control has always has a window then you can think about doing that inside handler for WM_CREATE.

You can force to always have a window by setting m_bWindowedOnly bit.

coxswainindiaAuthor Commented:
how can i know whether the control is created at design time or at run-time. The event needs to be fired only at run-time. Furthermore, How can I get the property value of the control in WM_CREATE?
HRESULT CComControl::GetAmbientUserMode(BOOL& mode)

this tells if the control is in design time (FALSE) or runtime mode (TRUE).

HRESULT CComControl::GetAmbientProperty( DISPID dispid, VARIANT& var )

use this method to fetch value of any property including predefined ones and your own properties as well.

hope this helps.

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

if you are asking about how to add handler for WM_CREATE then you need to add a MSG map to your control like


LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
coxswainindiaAuthor Commented:
WM_CREATE will not work in my case, just because my control doesn't have any window associated with it. For that reason I think, I may not be able to check for the property value in OnCreate(). Can u pls tell me whether, I can use CComControl::FinalConstruct( ) for this ??

Will all the property values be loaded at this time ??
coxswainindiaAuthor Commented:

nobody there to help me OUT!!!
GetAmbientUserMode i snot working, its always returning TRUE, Furthermore even microsoft has recommended not to use this method. Is there any other work-around ??
!! You can force to always have a window by setting m_bWindowedOnly bit.

>> CComControl::FinalConstruct( ) for this ??

I am not so sure about that and i think it wont,

>> Will all the property values be loaded at this time ??

precisely this appears to be an issues with FinalConstruct, plus i dint think any client can connect to the control to catch its events before FinalConstruct return, If finalContruct fails the object is not created at all, that is why i recommended you to do it in WM_CREATE handler. You can force the control to always have a window by setting a flag in the contructor m_bWindowOnly, as far as i remember that is inside a union. A more exact way to set this flag is given in MSDN. Its been a long time so i may be forgetting something.

>> GetAmbientUserMode i snot working, its always returning TRUE

where are you calling it from ? OnCreate ? or FinalConstruct ? can you post a link to the information forbidding its use ?

and yes sorry for late reply ...
coxswainindiaAuthor Commented:
Thanks for your interest...

I tried calling GetAmbientUserMode from FinalConstruct(). I cannot use OnCreate for this, just b'coz, if the container application is VB, and if the developer uses declaration something like this

Dim withevents object as ActiveX

Then I will certainly landup in trouble. b'coz I think such declarations will never create a window and the program control will not even reach OnCreate. Is there any other point where I can check for the mode by calling GetAmbientUserMode and the property value and then fire the respective event if neccessary.

Thanks in advance
>> I think such declarations will never create a window and the program control will not even reach OnCreate

almost true

>> Dim withevents obj as ActiveX

This is not the usual way of instantiating ActiveX controls from VB, why would you like to do it that way ? you can add it directly on the Form from the Toolbox and no need to declare a var and create it.

Any other place , oh well you can fire it from OnDraw() if the usermode is TRUE, and perhaps keep a flag to make it fire once only.

I cant think of any other place at the moment. However i do recommend that you do it from OnCreate.

Even if you provide a method say FireIt , that fires the event , are you sure you can make the following work

Dim withevents obj as ActiveX

correct me if am wrong
coxswainindiaAuthor Commented:
I am not writing this OCX for my use. If it was for my requirement, then I can very much avoid using "withevents". But my client wants provisions for window-less activation.

Will the poroperty values be available at OnCreate. As far as I know, the property values are loaded by a call to LoadObject of IPropertyBag. Moreover Is it possible to get the USERMODE from OnCreate() ?

Above all, I feel, OnCreate will not be called for "withevents"!!!

Pls correct me if I am wrong.
Yes property values are accessible from OnCreate, i remember another question like that and the questioneer solved it by using Windowed only style. His exact problem was also determining the usermode as soon as possible.

>> OnCreate will not be called for "withevents"!!!

Nothing will be called or callable , because you need to do

set obj = new MyObject

to instantiate the control and it is after that that you recieve events or can call method, also the control will get a WM_CREATE at that point
coxswainindiaAuthor Commented:
I have one more doubt...

If I use "withevents" and "Set" in VB, then the resulting ActiveX object will not be having any window associated with it!!!
Then How come OnCreate be invoked ??

OnCreate is invoked to create the window, But in this case, there is no window associated with the object, then how can I handle it in OnCreate()
>> my client wants provisions for window-less activation

umm yes, because of the above facts the problem still remains otherwise it could have been tackled by setting an Invisible property and creating a window that is invisible, this way WM_CREATE is ensured.

But i think you cannot force WindowOnly mode because of the above fact.

Looks like i have to dig in deeper this time ...
coxswainindiaAuthor Commented:
Pls do that, I've tried a lot, and to be frank, I'm getting a bit wierd, with not getting the results.

Anyway thanks for your interest...
Dear coxswainindia

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to

     "refund the points and PAQ at zero points"

since nobody had a satisfying answer for you.

Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now