Departure Posted November 18, 2007 Posted November 18, 2007 Just wondering if anyone has infomation about embedding your delphi app into another window, For example adding a richedit control from your delphi form into another app or even the whole form.I assume its done by using API calls but im not sure which ones, My guess is to find the handel of the control in other apps and set delphi form as child??
Pimp.exe Posted November 18, 2007 Posted November 18, 2007 I dont think you can embed it, but you can use api's (Like setwindowpos) to put your control over the other window and keep it there.
Departure Posted November 19, 2007 Author Posted November 19, 2007 (edited) Yeah when i said embed it I did'nt actually mean true embedding, I know how to do it with vb6, I wonder if anyone could translate for me to delphi or an example??Vb6: Private Sub Form_Load()Dim otherappwindowclass As LongDim XPos As Long, YPos As Longotherappwindowclass = FindWindow("dlggroupchat window class", vbNullString) Call SetParent(Form1.hwnd, otherappwindowclass) XPos = 360 YPos = 0 Call SetWindowPos(Form1.hwnd, 1, XPos, YPos, 100, 40, 1) If otherappwindowclass = 0 Then Exit Sub End Ifend sub Edited November 19, 2007 by Departure
Pimp.exe Posted November 19, 2007 Posted November 19, 2007 (edited) Well your if statement isnt right first off. You want to if before you attempt to setparent. But I think I get what are looking to do. Delphi isn't one of my strong languages, but I can provide you with a rough sketch in asm.invoke FindWindow,addr buffer,NULLmov ebx,eax;Do this as eax will be overwritten.if ebx!=0 invoke SetParent,ebx,hWin invoke SetWindowPos,ebx,HWND_TOPMOST,XPos,YPos,100,40,1.endifOf course you would have to set the variables, but thats the general idea. Edited November 21, 2007 by Pimp.exe
ante0 Posted November 19, 2007 Posted November 19, 2007 (edited) Just wrote this, and tested... Still needs some fixing But it will get you a bit on the way... procedure TForm1.Button1Click(Sender: TObject);varXPos: integer;YPos: integer;hWindow: hwnd;beginhWindow := FindWindow(nil,PChar('TranWin')); //Replace TranWin with what you want :)if hWindow <> 0 thenbeginForm1.ParentWindow := hWindow;XPos := 0;YPos := 30; SetWindowPos(Form1.ParentWindow, 100, XPos, YPos, 100, 40, SWP_SHOWWINDOW); end else ShowMessage('Window not found!'); end; Edited November 19, 2007 by ante0
Departure Posted November 19, 2007 Author Posted November 19, 2007 Thanks guys i'll try it out, the delphi code that ante0 did looks nearly the same as vb6, So this is exactly what i needed. P.s yes i just relized I put the if statment in the wrong spot should of benn at the begining...If otherappwindowclass = 0 Then Exit Sub ElseCall SetParent(Form1.hwnd, otherappwindowclass) XPos = 360 YPos = 0 Call SetWindowPos(Form1.hwnd, 1, XPos, YPos, 100, 40, 1) End ifEnd subI was half a sleep when writting that hehehe, Thanks again guys, Im new to delphi but im getting there.....
ante0 Posted November 19, 2007 Posted November 19, 2007 (edited) Just wrote this, and tested...Still needs some fixing But it will get you a bit on the way... procedure TForm1.Button1Click(Sender: TObject);varXPos: integer;YPos: integer;hWindow: hwnd;beginhWindow := FindWindow(nil,PChar('TranWin')); //Replace TranWin with what you want :)if hWindow <> 0 thenbeginForm1.ParentWindow := hWindow;XPos := 0;YPos := 30; SetWindowPos(Form1.ParentWindow, 100, XPos, YPos, 100, 40, SWP_SHOWWINDOW); end else ShowMessage('Window not found!'); end; Oh, in SetWindowPos Change Form1.ParentWindow to Form1.Handle otherwise it wont place itself on X,Y. It will move the Window that you captured. hehe. You can open up Delphi Help and search for SetWindowPos if you want to have some more options, and to understand it better. Though I guess it's pretty similar to VB6. Oh, and one more thing. Change SWP_SHOWWINDOW to SWP_NOSIZE or something else. SHOWWINDOW makes the Form unmovable. You could also add an Edit to the form, if you don't know what window you want to capture. hWindow := FindWindow(nil,PChar('TranWin')); to hWindow := FindWindow(nil,PChar(Edit1.Text)); Edited November 19, 2007 by ante0
Departure Posted November 19, 2007 Author Posted November 19, 2007 (edited) Okay the code you gave did'nt work correctly for me so I changed delphi setparent to windows.setparent (child,Parent), now it works fine, Thanks very much for the input procedure TForm1.Button1Click(Sender: TObject);varXPos: integer;YPos: integer;hWindow: hwnd;begin hWindow := FindPalWindowByCaption('- Voice Room'); //this here just calls another function to find the windowif hWindow <> 0 thenbeginwindows.SetParent(form1.WindowHandle,hWindow); //Here is where I changedXPos := 360;YPos := 0;SetWindowPos(Form1.WindowHandle, 1, XPos, YPos, 321, 25, SWP_SHOWWINDOW); //And ofcause here for the form handelendelseShowMessage('Window not found!');end; //Edit I just seen the post above this one, So yeah I did what you said before I read your post. Thanks again for all your help Edited November 19, 2007 by Departure
ante0 Posted November 19, 2007 Posted November 19, 2007 Ah, my bad. Thanks for adding Comments, they're really useful, and I tend to forget to add em. lol Oh btw, If you maximize Parent window after executing the code, is the child still movable for you? I can't move it when I maximize, if I restore it I can... I think I'll add the same as you, windows.SetParent(form1.WindowHandle,hWindow); Though I'm at work now, so I'll have to try it later Happy coding!
Departure Posted November 19, 2007 Author Posted November 19, 2007 actually windows.setparent seems to have no problem moving the child form around in the parent (other app) while maximized, So yes the child is still movable, I set my forms border style to none then ofcause the form is not movable in the parent window, but for testing puposes I did change it back to single border and toolbar border and both where movable...
ante0 Posted November 19, 2007 Posted November 19, 2007 actually windows.setparent seems to have no problem moving the child form around in the parent (other app) while maximized, So yes the child is still movable, I set my forms border style to none then ofcause the form is not movable in the parent window, but for testing puposes I did change it back to single border and toolbar border and both where movable... Ah good, I will add this later on to my sources Hmm, if you don't mind me asking, what are you going to use this for?
Departure Posted November 20, 2007 Author Posted November 20, 2007 I am making a text fader that "embeds" a richtext control into the toolbar of paltalk, Its all working good but I have one problem..If I close paltalk room window before I restore the embeded form I loose the form and can'nt get it back and some times gives errors, So i have close it by either task manger or the taskbar. I have tryed a couple of things but can'nt seem to get it..Example:Things to note here is that I change the borderstyle to none when i position it in the paltalk toolbar...procedure TForm1.Timer1Timer(Sender: TObject);varpalwin : Hwnd;beginpalwin := FindPalWindowByCaption('- Voice Room'); // just another function to find the correct windowif (palwin <> 1) and (form1.BorderStyle = bsNone) then //This was my plan until I relized it wont work because the form got killed with the paltalk room window :(beginwindows.SetParent(form1.WindowHandle,0); // take my form out of the paltalk windowform1.Height := 245; // reset my hightform1.Width := 332; // reset my widthform1.BorderStyle := bsSingle; // change the border style backendend;Anyway I think the only way to get around this is hooking the windows message to close the paltalk window, then you could "restore" the delphi form before the message got through..I dont really know but thats my theory, Hooking in delphi is something I need to read up on, It was hard enough in vb6 let alone delphi
ante0 Posted November 20, 2007 Posted November 20, 2007 (edited) Ah, yes, I have the same problem. Well, when I tried it in Delphi it's easy cause you can reset the program. Since the Parent is closed, the Child still stays in it. Then you'd have to force close it. I was thinking something like this... first set hWindow as a global variable. varForm1: TForm; //This will be ther already.hWindow: hwnd; and remove it in the other procedure as a variable in a timer you can use. if hWindow = 0 thenbeginForm1.Application.Terminate;end;end; I think this will do it... I don't have Delphi here so I can't try it out You could set the timer to go off every 5 seconds, and it could be enabled right after you set SetWindowPos(Form1.WindowHandle, 1, XPos, YPos, 321, 25, SWP_SHOWWINDOW); Timer1.Enabled := True; I'm not at all positive this will work, since the form is set as child... But it's no harm in trying it out Edited November 20, 2007 by ante0
Departure Posted November 21, 2007 Author Posted November 21, 2007 thats pretty much what I had in post before except I was tryingto restore the form not terminate it, Needs to be restored so i can use it in another window, Unless ofcause I could program it to creat a .bat file which then executes the delphi app exe then after deltes the .bat file ............ Lmao danmm thats the long way around but its easyer than hooking the close message from window and restoring before the actuall window recives the message.Thanks for all your help mann its greatly appreciated
ante0 Posted November 22, 2007 Posted November 22, 2007 thats pretty much what I had in post before except I was tryingto restore the form not terminate it, Needs to be restored so i can use it in another window, Unless ofcause I could program it to creat a .bat file which then executes the delphi app exe then after deltes the .bat file ............ Lmao danmm thats the long way around but its easyer than hooking the close message from window and restoring before the actuall window recives the message.Thanks for all your help mann its greatly appreciated I guess... var myFile : TextFile; text : string; File1 : string;beginCreateFile(pchar(ExtractFilePath(ParamStr(0))'Test.bat'),GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0); File1 := ExtractFilePath(ParamStr(0))+'Test.bat'; AssignFile(myFile, 'Test.bat); ReWrite(myFile); WriteLn(myFile, 'Hello'); WriteLn(myFile, 'World'); CloseFile(myFile); ShellExecute(Handle,'open', pChar(File1),nil, nil, SW_SHOWNORMAL); end;Remember to add ShellAPI; to Uses clause. Maybe that will help you with the .bat file I think it would be easier with just coding though. hehe
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now