Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows & Parents

Posted on 1999-07-13
39
Medium Priority
?
395 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:Stuart_Johnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 11
  • 6
  • +1
39 Comments
 

Expert Comment

by:GabeinOZ
ID: 1388361
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
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388362
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
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388363
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Expert Comment

by:inthe
ID: 1388364
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
0
 
LVL 17

Expert Comment

by:inthe
ID: 1388365
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???
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388366
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.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388367
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.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1388368
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 ..
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388369
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
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388370
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.
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388371
>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
0
 

Expert Comment

by:GabeinOZ
ID: 1388372
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
0
 
LVL 17

Expert Comment

by:inthe
ID: 1388373
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 ;-)
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388374
>maybe i am a big twit but

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

;)
Alex
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388375
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.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388376
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>


0
 

Expert Comment

by:GabeinOZ
ID: 1388377
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
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388378
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.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388379
Gabe,  you have to be ****ing kidding.  That is the crappiest answer I have ever gotten to any question.

Get a life.

Stu.
0
 

Expert Comment

by:GabeinOZ
ID: 1388380
go %$#^@#$ yerself then you big prick....theres an answer for ya....

Gabe
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388381
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.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388382
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.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1388383
dont suppose you'll get an "A Grade" for that one ;-)
0
 

Expert Comment

by:GabeinOZ
ID: 1388384
Damnit Barry :P dont be giving him any ideas  lol

Gabe
0
 
LVL 17

Expert Comment

by:inthe
ID: 1388385
lol
good day to all, im off for a snooze ;-)
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388386
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
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388387
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.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388388
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.

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388389
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.


0
 
LVL 15

Expert Comment

by:simonet
ID: 1388390
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
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388391
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 :)
0
 
LVL 15

Accepted Solution

by:
simonet earned 200 total points
ID: 1388392
Glad I could help you, 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.

Antoher thing: who you set as the owner of the runtime-created panel is also very important. In my case, I created the panel as being owned by the Application object. So, when my app was exited, even though the panel was in the Desktop, it's be destroyed as well. If you create the panel with Owner=nil, then the Panel will just stand there until you restart Winblows.

Yours,

Alex

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388393
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.
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388394
>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


0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388395
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.
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388396
>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






0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388397
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!!
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388398
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

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1388399
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question