In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to embed the window of a third-party program in SWT program". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to embed a window of a third-party program in a SWT program.
When developing a system, we often need to embed external programs, such as integrating the original system of the enterprise into our system, and it looks like our program to be embedded in our system, so we have to rely on Win32. In the past, when using VC, Delphi, C# development, you can directly call the API of Win32 to operate, fortunately, SWT provides the encapsulation of Win32API, and the encapsulation is better, most of them are in the org.eclipse.swt.internal.win32.OS class. The core principle is to call the API SetParent to set a control in our program as the parent window of the nested program.
The core code is as follows:
Private void execute (String fileName) throws Exception {
Int hHeap = OS.GetProcessHeap ()
TCHAR buffer = new TCHAR (0, fileName, true)
Int byteCount = buffer.length () * TCHAR.sizeof
Int lpFile = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount)
OS.MoveMemory (lpFile, buffer, byteCount)
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO ()
Info.cbSize = SHELLEXECUTEINFO.sizeof
/ / hide startup
Info.lpFile = lpFile
Info.nShow = OS.SW_HIDE
Boolean result = OS.ShellExecuteEx (info)
If (lpFile! = 0) {
OS.HeapFree (hHeap, 0, lpFile)
}
If (result==false) {
Throw new Exception ("Startup failed!")
}
}
Protected void startThirdExe () throws Exception {
/ / "notepad.exe" is the name of the program to be started
Execute ("notepad.exe")
/ / wait for NotePad.exe to start and initialize. You need to adjust the sleep time according to the actual situation.
Thread.sleep (1000)
/ / "Notepad" is the ClassName (Win32 level) of the nested program window, which can be viewed using tools such as Spy++.
Int notepadHwnd = OS.FindWindow (new TCHAR (0, "Notepad", true), null)
/ / & ~ WS_BORDER removes the embedded program border so that it looks more like an embedded program. If you need to display the border, delete the two lines of code
Int oldStyle = OS.GetWindowLong (notepadHwnd, OS.GWL_STYLE)
OS.SetWindowLong (notepadHwnd, OS.GWL_STYLE, oldStyle&~OS.WS_BORDER)
/ / composite is the control that hosts the started program
OS.SetParent (notepadHwnd, composite.handle)
/ / window maximization
OS.SendMessage (notepadHwnd, OS.WM_SYSCOMMAND, OS.SC_MAXIMIZE, 0)
}
At this point, I believe you have a deeper understanding of "how to embed the window of third-party programs in SWT programs". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.