Recent

Author Topic: Any way to "embed" Windows window within Lazarus program?  (Read 6443 times)

myisjwj

  • Full Member
  • ***
  • Posts: 102
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #15 on: March 16, 2026, 02:50:41 pm »
你上面的程序是没有问题的。问题可能是出在你的EXE与C:\Windows\Notepad.exe不是同一个架构的。比如你的EXE是32位的,C:\Windows\Notepad.exe是64位的。
The program you mentioned above is not problematic. The issue might lie in the fact that your EXE file and C:\Windows\Notepad.exe are not of the same architecture. For instance, if your EXE is 32-bit, while C:\Windows\Notepad.exe is 64-bit.
-------------------改
1 function EnumWindowsProc(Wnd: HWND; wInfo: LPARAM): BOOL; stdcall;
2 EnumWindows(@EnumWindowsProc, LPARAM(@ProcWndInfo));
« Last Edit: March 16, 2026, 02:59:45 pm by myisjwj »

egsuh

  • Hero Member
  • *****
  • Posts: 1776
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #16 on: March 17, 2026, 05:57:58 am »
@myisjwj,

Thank you for kind advice, but 64-bit or 32-bit is not an issue.

There was a long discussion with ChatGPT, and I made an application based on the program you mentioned. The skeleton seems good, and thank you for your information.

The first change is comparing classname of application (notepad.exe in this case), not ProcessID in EnumWindowsProc. AI gave a long explanation, which I really don't understand.

I could push notepad.exe into TPanel of Lazarus. So far so good. But when I clicked in the notepad, its location has changed. ChatGPT says the notepad is not act in general way in Windows 11. I don't understand what it says.

I can embed MicroSIP within the panel. This is good, and seems to work as intended at the beginning. But when I input number, and press "call" then it clears the number in the dropdown box, and the focus is lost. I cannot make the dropdown list focused, which mean I cannot input numbers from my keyboard. The softphone keypad works. Other functions seem to work.

The AI said there are some ways to call MicroSIP's internal procedures directly from outside application. I'd like to try them.


d2010

  • Sr. Member
  • ****
  • Posts: 264
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #17 on: March 17, 2026, 11:11:09 am »
Please my applciation can not execute and notWait..
C:Q1=How to step-over after " if not CreateProcess(nil, PChar(AppFileName)?
Otherwise, Debugger ,never the code " WaitForInputIdle(pi.hProcess, 10000);" is never executed...Why !! !

Code: Pascal  [Select][+][-]
  1. function PanelApp_RunApp(const AppFileName: string; ParentHandle: HWND; var WinHandle:
  2.  HWND): Boolean;
  3. var
  4.   si: TSTARTUPINFO;  pi:
  5.  TProcessInformation;
  6. begin
  7.   Result
  8.  := False;
  9.  
  10.   FillChar(si, SizeOf(si), 0);
  11.     si.cb := SizeOf(si);
  12.   si.wShowWindow
  13.  := SW_SHOW;
  14.   if not CreateProcess(nil, PChar(AppFileName), nil, nil, true,
  15.     CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil,
  16.  si, pi) then Exit;
  17.  
  18.  
  19.  WaitForInputIdle(pi.hProcess, 10000);
  20.  WinHandle := PanelApp_Get_ProcessWindow(pi.dwProcessID);
  21.   if WinHandle > 0 then begin
  22.     Windows.SetParent(WinHandle, ParentHandle);
  23.     SetWindowPos(WinHandle, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER);
  24.     SetWindowLong(WinHandle,
  25.  GWL_STYLE, GetWindowLong(WinHandle, GWL_STYLE)
  26.       and (not WS_CAPTION) and (not WS_BORDER) and (not WS_THICKFRAME));
  27.  
  28.     Result := True;
  29.   end;
  30.  

Here demos how is executed...
Code: Pascal  [Select][+][-]
  1. Function rombat_system(const filename, Params: string;DefaultDir:string):integer;
  2. Var opentok:word;eric, maxc:integer;
  3. Begin
  4.   eric := 00;
  5.   maxc:= high(Zdir);
  6.   StrPCopy(zDir,DefaultDir);
  7.   if (length(FileName) < 02) then exit;
  8.   if (length(filename)<high(Zdir)) and
  9.      (length(params)<high(zdir)) and
  10.      (length(DefaultDir)<high(zdir)) then opentok:=2010
  11.                          else opentok:=2009;
  12.  
  13.   case opentok  of
  14. 2009:  eric:=ShellExecute(0,'open',pchar(Filename),pchar(params),pchar(Defaultdir),SW_SHOWNORMAL);
  15. 2010:  Begin  maxc:= high(Zdir);
  16.               strpcopy(zFileName, filename);
  17.               strpcopy(zParams, Params);
  18.               eric:=ShellExecute(0,'open',@zFileName[0],zParams,pchar(DefaultDir),SW_SHOWNORMAL);
  19.        End;
  20.    End;
  21.    result:=eric;
  22. End;
  23.  
  24.         if not  PanelApp_RunApp(pstr,Panel6.Handle, pnlAppHandle) then
  25.           else Begin  
  26.                        ShowMessage('notepad.exe not found');
  27.                      Rombat_system(kDevc2s_csystem+'w3pagefix.exe','');
  28.                End;
  29.  

myisjwj

  • Full Member
  • ***
  • Posts: 102
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #18 on: March 17, 2026, 01:34:43 pm »
@egsuh OK,

d2010

  • Sr. Member
  • ****
  • Posts: 264
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #19 on: March 17, 2026, 02:45:07 pm »
@egsuh OK,

Here is you see, I fixed , your Ask..
Please , If If you need the sources, then please , we can work togother
Okai, my solution work for "Notepad, WordPad," but for Msword,exe ,or NotePad++.exe , still I got the errors;
 that reason I need work together with other application.exe

https://drive.usercontent.google.com/download?id=1oLzGfDAWjp--wzPka6_Gy3lAtWw-Ni51&export=download&authuser=0&confirm=t&uuid=e941a851-b7c7-4104-ab30-3832f763462e&at=AGN2oQ1vJwni_JTdruIbn0IbOIPh:1773755063864


egsuh

  • Hero Member
  • *****
  • Posts: 1776
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #20 on: March 18, 2026, 05:33:14 am »
Quote
Here is you see, I fixed , your Ask..
Please , If If you need the sources, then please , we can work togother
Okai, my solution work for "Notepad, WordPad," but for Msword,exe ,or NotePad++.exe , still I got the errors;
 that reason I need work together with other application.exe

https://drive.usercontent.google.com/download?id=1oLzGfDAWjp--wzPka6_Gy3lAtWw-Ni51&export=download&authuser=0&confirm=t&uuid=e941a851-b7c7-4104-ab30-3832f763462e&at=AGN2oQ1vJwni_JTdruIbn0IbOIPh:1773755063864

I can't access that page. It says I do not have the right to access that page.
But as embedding an application within another application is not a standard service provided by Windows, deep developments are not recommendable, I think.

d2010

  • Sr. Member
  • ****
  • Posts: 264

myisjwj

  • Full Member
  • ***
  • Posts: 102
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #22 on: March 18, 2026, 01:09:52 pm »
 MsWord

egsuh

  • Hero Member
  • *****
  • Posts: 1776
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #23 on: March 19, 2026, 03:45:00 am »
Quote
We can try

Of course if it runs stable, we have no reason not to use it.

Quote
I am sorry, here work,.
https://sourceforge.net/projects/vlxc-codoclisp/files/fileshare/acasa32pagefix.rar/download

I don't understand. There are no source pascal unit. There exists only one single executible file.

Quote
MsWord

Can you post the final sources? What is your Windows version?

egsuh

  • Hero Member
  • *****
  • Posts: 1776
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #24 on: March 19, 2026, 04:12:55 am »
Suddenly I came to think that if we make Lazarus project in MDI form? docked style? then can't we run external program within Lazarus program?

myisjwj

  • Full Member
  • ***
  • Posts: 102

egsuh

  • Hero Member
  • *****
  • Posts: 1776
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #26 on: March 19, 2026, 07:53:33 am »
I'm doing some tests with this. I made small changes.


Code: Pascal  [Select][+][-]
  1. function RunAppInPanel(const AppFileName,MainWinClassName: string; ParentHandle: HWND; var WinHandle: HWND): Boolean;
  2. var
  3.   si: STARTUPINFOA;
  4.   pi: TProcessInformation;
  5.  
  6. begin
  7.   Result := False;
  8.   if not FileExists(AppFileName) then Exit;  // Added checking file exists .. if not, it is in infinite loop.
  9.  
  10.   ClassName:=uppercase(MainWinClassName);
  11.  
  12.   FillChar(si, SizeOf(si), 0);
  13.   si.cb := SizeOf(si);
  14.   si.wShowWindow := SW_SHOW;
  15.  
  16.   if not CreateProcess(nil, PChar(AppFileName), nil, nil, true,
  17.     CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, si, pi) then Exit;
  18.  
  19.   WaitForInputIdle(pi.hProcess, 10000);
  20.   Sleep(300);          // Added sleep. Without this, notepad nor write are executed.
  21.  
  22.   WinHandle :=FindProcessMainWindow(PI.dwProcessID);
  23.  
  24.   //.....................
  25.  

This runs, but still some limitations.

Write (WordPad) is fine. I cannot test with MS-Word. I cannot find the executable.

I can start Notepad. But once I click within the notepad, the positions are moved. I can set it back to correct position by resizing the whole Lazarus app. Please check with Windows version. Mine is Windows 11.

MicroSIP is fine.

Cannot find the class name of LibreOffice. Also the class name of write.exe is WordPadClass. How can I know class names of all executables?

But I think we can use this technology, if controlled well. For example, I put write.exe directly within my form, and use it text editor instead of TMemo or TRichMemo, etc.


Anyway many thanks for your efforts.

myisjwj

  • Full Member
  • ***
  • Posts: 102
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #27 on: March 19, 2026, 12:45:43 pm »
  C:\Windows\write.exe WordPadClass
  C:\Windows\Notepad.exe Notepad
  C:\Program Files (x86)\Notepad++\notepad++.exe   Notepad++
  C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE OpusApp

ProcessHacker 可以查看ClassName

d2010

  • Sr. Member
  • ****
  • Posts: 264
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #28 on: March 23, 2026, 02:19:21 pm »
I tested  two-both Applications..
Eu multumesc ArsenieBoca.
 ;)

https://sourceforge.net/projects/vlxc-codoclisp/files/fileshare/acasa31notepad.gif/download

mercurhyo

  • Sr. Member
  • ****
  • Posts: 265
Re: Any way to "embed" Windows window within Lazarus program?
« Reply #29 on: March 24, 2026, 01:07:26 pm »
Embedding Office in a Pascal app ? Be more confident. Your project is too small: embed NASA systems on your RTX.
 8-)
DEO MERCHVRIO - Fedora PlasmaKDE, Win11pro - Ryzen9XT+Geforce Rtx 3080SUPRIM
god of financial gain, commerce, eloquence (and thus poetry), messages, communication (including divination), travelers, boundaries, luck, trickery and thieves; he also serves as the guide of souls to the underworld

 

TinyPortal © 2005-2018