How to determine if ActiveX control is in desingn mode

I am creating an active X control as a descendant of a VCL that I wrote.  Inside of the VCL unit how can I tell if the activeX control is being used
in a design environment (VB for example)?
CHORNAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

halapayaCommented:
Hm.. this is just an idea,
if anyone is in design environment, designing form or whaterver is a child window of the VB/Delphi IDE. soo that means if u can get the current windows parent window handle, pass it to get that windows informataino. u can check for Parent window caption[Delphi/VB IDE caption] if its Delphi or visual basic enterprise 6.0 or what ever the caption u need, u can go ahead and do ur stuff, cause u found it.
0
CHORNAuthor Commented:
Delphi does not have a method that
can return the handle of a vb form
that is the parent of the control.
0
DrDelphiCommented:
VB Doesn't need to have such a method. You can compile a function into the VCL component that returns the Component.Parent.Handle  (HWND). This works regardless of the development environment (Delphi, VB, C++, etc).

Good luck!!
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

intheCommented:
could you not use the componentstate .

on component create event;
if (csdesigning in ComponentState) then
//do something..
else
//do something else..
0
CHORNAuthor Commented:
I have tried this but it does not return true when using the control in
VB.
0
DrDelphiCommented:
Chorn,
  the answer that I gave you is something that I have actually used... try it... it WILL work.
0
CHORNAuthor Commented:
I did try it.  If you make a Quick Active X Control and place it on a vb form; when you check the componentstate
property it is empty.
0
intheCommented:
no DrDelphi means try his suggestion of looking for parent name,i see no other way of doing it.
0
DrDelphiCommented:
ARRRRGHHHH!!! I never said to use the componentstate property. OLE doesn't know what the hell componentstate is. What I am saying is that you insert into your VCL component a function which exports the Component.Parent.Handle. This handle in the OCX will represent the HWND of the form that the control is sitting on.With this HWND you can get the parent of the form using GetParent. that should tell you the development environment. (either in it's text or classname).


   
0
DrDelphiCommented:
thanks inthe... I was beginning to think
I was spitting in the wind! <g>

0
RadlerCommented:
Put the property ComponentState "Published"( is public at now )
change anything ?
T++, Radler.
0
CHORNAuthor Commented:
Thank you Dr. delphi & inthe for the suggestions.
Dr. Delphi I can appreciate your frustration. I have tried your suggestion.  If you make a simple ActiveX control (say derive it from TEditBox) and create a property which exposes the Component.Parentwindow or
Component.Parent.handle it does return a value.  Unfortunately the value is not the same value as the Hwnd property of the VB form.  This is very strange behavior.  If you use winspy to look at the handle's returned by the form and the control's parent.handle (which as I mentioned are different) you will notice the parent.handle is another window completely unrelated to the form the control's are being placed upon.  It seem's that microsoft is creating another hidden form to harbour the ActiveX control.
0
intheCommented:
of course the hwnd is not the same ,try restarting windows and noticccce it is most likely different each time.
you need to use something like
s:= getwindowtext(the parent hwnd) then check if it contains whatever vb contains in its projects caption.
if pos(somevbcaption,s)<>0  then running in vb := true;
else
if pos(some other caption,s) then
running in something other := true
 ..etc

0
CHORNAuthor Commented:
I really do apreciate your help.
As I have mentioned if i use the parent
..handle property it does not return the handle of the window that the control resides on.  It returns the handle of a hidden window that is in now way related to the parent form.  If you
make a quick OCX and put it on a VB form
you will see that the parent.handle property returns a value different than
the form.handle property.
Thanks Again.
0
intheCommented:
cant help then as dont own vb ..
0
nrobinCommented:
Chorn,

I have the definitive answer, but I think you should up the points a bit, as this question is infact far from easy.

Nick.
0
intheCommented:
This is Bribrary ...
0
rwilson032697Commented:
Sounds like negotiation to me :-)
0
nrobinCommented:
8)
0
nrobinCommented:
8)
0
intheCommented:
hi,
found this in a faq ,please try it:

Q: How do I know if my ActiveX control is in design or run mode?
A: You can find out by determining if your control's container is in
  design mode.  You can find this out by querying the container's
  UserMode ambient property.

Example:

// This function returns a pointer to a contained control's site
function ClientSite( obj: IUnknown ): IOleClientSite;
var
  Site: IOleClientSite;
  OleObj: IOleObject;
begin
  if (obj.QueryInterface( IOleObject, OleObj ) = S_OK) and
     (OleObj.GetClientSite( Site ) = S_OK) then
    Result := Site
  else
    Result := nil;
end;

// This function returns TRUE if the contained object's container is in
// design mode; FALSE if the container is not in design mode or
// does not support design mode, or on any failure.
//
function IsControlInDesignMode( obj: IUnknown ): Boolean;
var
  Mode: Boolean;
begin
  try
    Mode := not ((ClientSite(obj) as IAmbientDispatch).UserMode);
  except
    Mode := False;
  end;
  Result := Mode;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CHORNAuthor Commented:
This is perfect. Thank you for your patience and perseverance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.