Link to home
Start Free TrialLog in
Avatar of Stuart_Johnson
Stuart_Johnson

asked on

Windows & Parents

Howdy.

I need to create a new Window whose parent is not the program creating the window.  I need to use an existing application as the parent.

I tried Form1 := TForm.CreateParented(FHwnd); (where FHWnd is the handle of the existing program), but it didn't work.

Any ideas?

Thanks,

Stu.
Avatar of GabeinOZ
GabeinOZ

Stuart,
Can you give us a little more detail such as is the application you wish to 'adopt' your form a delphi application?  And what are you hoping to achieve with this? having the old application take full control of the new form?

Gabe
Avatar of simonet
Try setting the parent window in the CreateParams

  TForm1 = class(TForm)
    procedure CreateParams(var Params : TCreateParams); override;
  private

(...)

procedure TForm1.CreateParams(var Params : TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := ParentWindowHandle;
end;



now in the code you listed, shouldn't it be

Form1 := TForm1.CreateParented(FHwnd);

???

Yours,

Alex
Oh, by the way, in the code I posted, ParentWindowHandle should be the handle of the window that must be set as the parent (I guess it's FHWnd in your case).

Alex
Hi
is this of any help?

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
   procedure CreateParams(var Params : TCreateParams); override;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.CreateParams(var Params : TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := GetDesktopWindow;
end;

end.


this would make the desktop the owner of the form2.
Regards Barry
wow sorry alex ;-)
what happened to the time?
i opened this page not 2 minutes ago and your comments werent there, then i paste my comment and post it and all a sudden its 11 minutes later???
Avatar of Stuart_Johnson

ASKER

Hi Gabe.

Thanks for your interest in my question.  The application I am writing is going to eventually prevent a user from accessing this program when a preditermined user count has been reached.  All it has to do is display a form over the old application with the message 'User count exceeded' and just sit there until my server program releases it (when the user count drops below the preset level).

FYI - this application is part of a MPEG Video Server Licencing program I am writing.

Alex.

Thanks you too for your comments.  I just typed in that bit about Form1 := ... I didnt even check to see if it was all right or not.

I'll try your example now.

Do you want to post an answer so I dont delete the question on you :)

Stu.
Hi Barry,

Alex and I are having the same problems.  He or I will post a comment when there is no comments in a question, then all of a sudden, the others' comment will appear as if it had been there for 10 minutes!  Very weird.

Stu.
i heard about this before and they say it may be to do with were the e.e servers are located ,as they are not on a main line and sometimes the traffic gets too much for them ,pain though ..
Another problem that's starting to annoy me is that I am getting notification messages 10-15 minutes late, and sometimes even more. Whenever I am online, my mail box is automatically checked every 5 minutes, but that's not the source of the problems. Even if I check my mail box every minute, messages from EE still arrive a lot after they were posted.

I guess this gives the other experts an unfair advantage in what has been called the "rat race for points"!

Alex
Could this be a problem with your mail server, Alex?  I am getting almost immediate notification at work, but at home on my dial up account, I could be getting notification upto 5 minutes after a question was updated.

I have OE 5 checking automaticallye very 1 minute here and at home.

Stu.
>problem with your mail server

Unlikely. I tried sending my self messages from Hotmail, Geocities, zipmail.com.br, bhmail.com.br, and a few other free mail places where I have/had accounts, and **all** of them arrived at my mail box almost immediatly (I kept clicking the send/receive btn until I recv'd the message).

Alex
Alex,

I've been having the exact same problem mate. I'll get a notification an hour or two after a notification for a comment that was put up AFTER the other one.  I think EE's servers are just having a bit of trouble with the load.  But it is free.....so.....

Gabe
i get notification  straight away but often when posting comments its suddenly 10-15 minutes later and there are other comments that i have not seen ,it gets annoying like when i post the same or similar to someone else already posted and makes me look like a big twit ,maybe i am a big twit but i dont think so,an annoyed twit maybe ;-)
>maybe i am a big twit but

hmmmm... I feel so much like making a joke here... but I won't!

;)
Alex
Hay.  Nice of you guys to use my important, enthrawling thread to have a big bitch session in :)  IM ONLY KIDDING!

This didnt work.  Let me think of a way to reword the question and I'll get back to you.....


Stu.
Hay.  Nice of you guys to use my important, enthrawling thread to have a big bitch session in :)  IM ONLY KIDDING!

This didnt work.  Let me think of a way to reword the question and I'll get back to you.....


Stu.

Wahoo!!! Einstien.experts-exchange.com just went down <G>


Heres an idea Stuart

Make your child form a borderstyle=none form that resizes to the entire desktop and tile a pic on it to cover the offending application using

with yourform do
      setwindowpos(handle,HWND_TOPMOST,yourform.left,yourform.top,yourform.
                   width,yourform.height,SWP_NOMOVE);

then it is uppermost and no other form can be brought to front

Gabe
Ok.  Lets try this then.

What I really want to do is this:

I have a running program (which is our Mathematics Program).  I am writing an MPEG Video Server licencing program which prevents users from viewing videos from a partiular lesson if there is already too many people viewing that lesson (ie, licence has exceeded user count).

I have a service app which monitors what video they have requested and either allows or denies them access to that video.

Now, as the Mathematics program is bloody old, bloody disgusting and written in a bloody shitty langauge (Icon Author), I have NO control over how the internals work.  So, what I thought would nice other than giving them a GPF when there was no video stream for them, was to whack a dirty big window over the top of the form telling them they had to wait for a licence to be come available.

I wanted to make the newly created form OWNED by Maths, not by my application.  I guess this doesnt matter too much, but I wanted to make it as though Maths had created the form and then displayed modally so they couldnt press any buttons or move the form around.

So, there is a better explaination of what I want.  Does that help, or should I buy a bucket to stick my head into?

Cheers,

Stu.
Gabe,  you have to be ****ing kidding.  That is the crappiest answer I have ever gotten to any question.

Get a life.

Stu.
go %$#^@#$ yerself then you big prick....theres an answer for ya....

Gabe
Alex, Barry and Gabe.

I know this may looked totally rigged, but its not.  Gabe has provided me with a solution which actually does do what I want, but it just doesnt let Maths own the new Window.

If anyone can improve on his code, I'll give both of you 50 points.  Unfortunately, I need this for tomorrow, and if I cant get anything else by then, I'll just give Gabe the points (after all, the poor bastard does only have 802 expert points <G>).

Thanks for your help all.


Stu.
Nice answer, twit.

I will leave this question locked, but if you can provide me with a better solution, I'll be more than happy to give away some more points.


Cheers,

Stu.
dont suppose you'll get an "A Grade" for that one ;-)
Damnit Barry :P dont be giving him any ideas  lol

Gabe
lol
good day to all, im off for a snooze ;-)
Stuart,

After reading all that bla bla bla about MPEG, Math and stuff, here's my suggestion:

Create a TPanel instead of a TForm, on top of the Window with the video (or whatever window it is). Controling the parenting of a TPanel is easier than doing it for a TForm.

Alex
Alex,

Could you possibly whip something up code wise that you could post here?  Im quite happy to up the points by 50 or so if your solution works.  I like the panel suggestion as the form I was going to make would have been borderless and captionless anyway.

Thanks mate.


Stu.
Alex,

Here's what I tried, and it didnt work:

var MyPanel: TPanel;

begin
   QueryClient;{Procedure which, among other things,
            detects the Windows handle for Maths}          
   MyPanel := TPanel.CreateParented(FSHwnd);;
   With MyPanel do begin
      Width := 640;
      Height := 480;
      {Centre panel relative to screen}
      Top := (Screen.Height - Height) div 2;
      Left := (Screen.Width - Width) div 2;
      Caption := 'Hidden';
      Visible := True;
   End;
end;

Any suggestions?

Stu.

Came up with something:

ShowWindow(FSHwnd, SW_HIDE);
Display Dummy Form

Do all my processing then

Free Dummy Form

ShowWindow(FSHwnd, SW_SHOW);

This works really well!  BUT... I would be still interested to see if you can do something for me with the panel, Alex.

Stu.


Hello, Stuart!

I tested your panel code and it didn't work with me either. So, I did something different:

I created a panel in runtime as I normally would and then simply called

Windows.SetParent(panel1.handle, HParWnd);

In my tests, I used HParWnd as 0 (the Desktop window), and guess what? It worked! the only problem was getting the new position coordinates, so they were made absolute to the new window (the desktop in my example), and not the the previous owner. But that's a simple case of math, using ClientToScreen and ScreenToClient.

Try that and get back to me afterwards.

Yours,

Alex
Perfect!  Thanks Alex!

Also:  GetWindowRect(Hwnd, var Rect); works perfectly for the placement :)

Thanks a million mate.  Post me an answer will you.

Cheers,

Stu.

Gabe: Sorry dude, but this does it exactly :)
ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Alex.  Wonderful!

Now, just as a side issue.  If this is too indepth, I dont mind starting another question, but I just thought I would ask.  A simple yes or no will surfice.

And object has a handle, right.  OK.  Is it possible to find out what the object is that is the owner of that handle?  Like GetObjectNameFromHandle(Hwnd) (wouldnt that be nice)?

Stu.
>And object has a handle, right.  

Not quite true. Only descendants of TWinConttrol has the handle of type HWND.

>Is it possible to find out what the object is that is the
>owner of that handle?  
The GetParent function retrieves the handle of the specified child window's parent window.

The GetClassInfoEx function retrieves information about a window class, including the handle of the small icon associated with the window class. The GetClassInfo function does not retrieve the handle of the small icon.

Is this what you meant? If what you have in mind is something like WinSight, that it's pretty easy. All WinSight does is using recursive enumeration functions using simple API calls. No hacks are involved.

Yours,

Alex


Hi Alex,

What I mean is, if I know the handle of say a TEdit component on a form, is there a way I can refrence that TEdit component.  This is hard to explain cause I really dont what I am talking about, but here goes.

I want to be able to change, say the caption on a button on a form I dont own, or the text in a memo etc etc.  I know I can send certain messages to that application, but I dont want to do this.  I want to be able to refrence the component directly in my application.  Do you think that is possible or am I just wishing too much :)

This is only out of curiosity, so feel free to tell me to get buggered if you don't have time to answer.

Stu.
>if you don't have time to answer.

I was with Alicia Silvestone, but let her wait in my bed. After all, after four in a row I deserve a break!

Now, back to the question...

Technically, the answer is yes, BUT... but only if you're talking about another Delphi or C++ Builder application. What I mean is: in order for your application to retrieve a component for another application, that component's class must be recognized by your application. A button on a VC++ app is not of the same class of an identical button on a Delphi app. C++ Builder uses the same classes of a Delphi application.

I don't know where I'd start with it, although it makes a lotta sense to me that it's 100% possible. I don't know if an object, a pointer (object = pointer) can be addressed by two simultaneous processes without using messages or another kinda technology.

This is a very interesting issue, and I'd like to go further on this discussion, for it's also something I'd like to discover.

I guess my first steps would be using API calls to get the handle of the button, it's class name and it's name. After that I beleive there might be some functions buried deep inside VCL that will work like FindComponent, but in another thread.

Alex






Hi Alex,

>I was with Alicia Silvestone, but let her wait in my bed.
>After all, after four in a row I deserve a break!

Hahahaha.  Well, if young Alicia is still asking for more, can you e-mail her too me?  I promise to send her back when Im through <G>

Have a think about it and if you can figure something out, I'll post a question up for you.  Otherwise, its cool cause its only something I would liek to be able to do every now and then.

Stu.

OH! BTW!  I really love your Resource Explorer. It is probably one of the most useful tools I have in my 'toolbox'.  I would be totally lost with out it!  You should release it as shareware mate.  Its that good, I'd buy it!!
I'll think about it that "foreign object" (!) thing. I'll get back to you if have any news.

About Resource Explorer, thanks a lot for the feedback, Stu. Funniest thing happened last week: I got an e-mail from this guy who was really scared that Res Exp would allow other people to see his Delphi forms and find out what component he was using. He liked Res Exp a lot, but he hated the fact that his "Delphi know-how" wasn't as secure as he thought it was. He asked for a way to secure his app from Res Exp and, among other suggestion, I advised him to use ASPack to compress his EXEs and DLLs.

In March I got an e-mail from this guy who was really irritated. He had put all the SQL he uses in his application as resources. He said he digged deep inside Oracle SQL manuals and stuff, and he really put a lot of effort into writing those SQL scripts. He thought they'd be safe in the resources (poor bastard!). He got mad after one of his customers (who had Res Exp) was using and modifying his scripts in another application (in-house development)!!!!

I also think Res Exp is a great tool and I have even bigger plans for it, like letting it use all the resource features NT as to offer.

>Its that good, I'd buy it!!

Start sending the money ;))

YOurs,

Alex

Hahahahahaha.  You can't help feeling sorry for them :)  But in all seriousness, what the hell did that SQL guy expect?  Sticking stuff like that is about as safe as having it in a text file.  Hahahaha.  Sorry, I shouldn't laugh, but it is funny.

Do you have an 'announcement service' at all for updates on it?  I'm currently running version 1.0, and I have been too damn lazy to go to your web page to download an update (if one is available).

I honestly would buy it if you charged for it (so long as it wasnt too much, cause not only am I lazy, but I'm as tight as a fishes as well <G>).  But I shouldn't be filling your head with these sorts of ideas.  I should be saying "Alex - you should be paying US to use it!!" :)

All the best,

Stu.