An adaptive synchronization method and system for cross-process window embedding
Patent Information
- Application Number
- CN202611341461.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-01
- Publication Date
- 2026-10-30
AI Technical Summary
然而,该机制存在一个系统级缺陷:当应用程序窗口移动到不同DPI的显示器时,Windows会遍历同一进程内的整个窗口树,向每个子窗口发送WM_DPICHANGED消息,但该通知仅在进程内传递,不跨进程转发
1、本发明通过多因子补偿算法,综合DPI缩放系数、物理尺寸补偿因子及偏差历史队列,实现从“属性同步”到“智能补偿”的跨越。算法内置自校准反馈闭环,每次同步后自动更新偏差历史,持续修正系统性偏移,使坐标换算精度达到像素级。同时,该方案不依赖外部进程配合,从根本上绕过了Windows系统不跨进程转发DPI通知的硬限制,确保宿主窗口在不同DPI显示器间移动时,嵌入窗口始终精确对齐、无坐标错位。
Smart Images

Figure CN123011392A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software and graphical user interface technology, and more specifically to an adaptive synchronization method and system for cross-process window embedding. Background Technology
[0002] Currently, in Windows application development, embedding the window of an external process into the container of the host application is a common technique for achieving unified integration of multiple tools. A common implementation method is to use the Windows API's `SetParent` function to reset the external process's main window as a child window of the host window. This technique is widely used in desktop applications that require the aggregation of multiple independent tools, such as embedded software testing platforms, IDE plug-in systems, and industrial monitoring software.
[0003] Windows provides a Per-Monitor DPI Aware mechanism for applications, allowing them to be aware of their current monitor and adjust their interface accordingly. However, this mechanism has a system-level flaw: when an application window moves to a monitor with a different DPI, Windows traverses the entire window tree within the same process, sending a WM_DPICHANGED message to each child window. This notification is only passed within the process and not across processes. In cross-process window embedding scenarios, this flaw leads to serious technical problems. When the host window is dragged from a 100% scaled monitor to a 150% scaled monitor: the host process receives the WM_DPICHANGED notification and correctly adjusts its layout; the embedded external process window receives no notification and continues to use the old DPI coordinate system; the result: the embedded window is misaligned, its content is blurry, and mouse clicks are off-target.
[0004] The SetParent function itself does not automatically synchronize the DPI-aware context of the parent and child windows. If the parent window is running in PROCESS_PER_MONITOR_DPI_AWARE mode while the child window is in UNAWARE mode, the system will force a DPI virtualization conversion, further exacerbating the display problem.
[0005] Besides DPI adaptation issues, cross-process window embedding also presents the following technical challenges:
[0006] (1) Visual flickering caused by asynchronous rendering. WPF applications use the DirectX rendering pipeline, while external embedded windows usually use the GDI / USER rendering pipeline. The refresh cycles of the two are not synchronized, which causes white flickering, tearing or screen distortion in the embedded area.
[0007] (2) The embedded window disappears after the external process crashes. After the external process crashes, the user needs to manually restart the process and reposition the window, which seriously affects the user experience in long-term continuous operation scenarios.
[0008] (3) The embedded window is visually and interactively disconnected. The embedded window retains the original title bar, border and system menu, which is inconsistent with the style of the host window.
[0009] Several related solutions already exist in the existing technology: CN201710471541.6, "Windows Cross-Process Window Management Method" (Wuhan Douyu), discloses a cross-process window management method: obtaining the target process PID → determining the target process window → creating a container to embed the target window → matching style attributes → synchronously modifying the corresponding attributes of the child window when the container's size, position, and show / hide attributes change. This solution solves the basic problem of position / size synchronization, but it does not address coordinate conversion between monitors with different DPIs, resulting in coordinate misalignment in mixed DPI environments; it does not address rendering synchronization, so flickering issues still exist; and it does not address process crash recovery.
[0010] CN119311438A, "Cross-Process Window Embedding Method" (China Merchants Bank), discloses a method for establishing a Socket connection between a parent process and a child process, setting a transparent area in the parent window, and embedding the child window into the transparent area based on its position information. This solution requires cooperation between the parent and child processes to establish a communication channel, and it cannot be implemented when embedding third-party closed-source programs.
[0011] CN117539582B, "Multi-process Interface Fusion Method and Apparatus," discloses a method for embedding multiple sub-process interfaces into a preset main container interface by obtaining the window handles of multiple sub-process interfaces. This solution only addresses "how to embed," without addressing DPI adaptation, rendering synchronization, and crash recovery after embedding.
[0012] US2014237421A1 (Google) discloses a method for determining the minimum DPI setting for displaying graphical content based on the display's native pixel density. This solution addresses DPI adaptation for multiple windows within the same process and does not involve cross-process window embedding scenarios.
[0013] Therefore, how to solve the problems of position synchronization, DPI adaptation, rendering synchronization and process crash recovery after cross-process window embedding without relying on the cooperation of external processes is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0014] In view of the above problems, the present invention proposes an adaptive synchronization method and system for cross-process window embedding to overcome or at least partially solve the above problems.
[0015] To achieve the above objectives, the present invention adopts the following technical solution: In a first aspect, embodiments of the present invention provide an adaptive synchronization method for cross-process window embedding, comprising the following steps: S1. The host process is aware of triggering events in real time. The triggering events include changes in the display environment of the monitor where the host process is located, changes in the window state of the container embedded in the host window, and changes in the health status of external processes. S2. In response to the triggering event perceived in the perception step, a multi-factor compensation algorithm is invoked to calculate the target position and target size of the embedding window of the external process in the physical coordinate system based on the logical coordinates and logical size of the embedded container, the DPI scaling factor of the display where the host process is located, the physical size compensation factor of the display, and the deviation history queue. S3. Based on the target position and target size output in the calculation step, call the window position setting function to adjust the position and size of the embedded window; S4. Dynamically adjust the execution frequency of the synchronization step according to the window state of the embedded container; S5. Based on the health status change event of the external process sensed in the sensing step, when the external process is detected to have exited, the external process is automatically restarted and the embedded state of the embedded window is restored.
[0016] Furthermore, the multi-factor compensation algorithm includes: Obtain the current DPI value of the display where the host process is located, calculate the DPI scaling factor, where the DPI scaling factor = current DPI value / N, and N is the base DPI of the Windows system; obtain the physical size and resolution of the display, calculate the actual PPI value, where the actual PPI value = resolution pixels / physical size inches, and calculate the physical size compensation factor, where the physical size compensation factor = actual PPI value / N; Obtain the deviation history queue, which records the deviation value between the actual position of the embedded window and the target position after the execution of the last n synchronization steps. When the deviation values in the deviation history queue accumulate in the same direction for more than a predetermined number of consecutive times, it is determined that there is a systematic offset, and the accumulated deviation is output as the position deviation compensation amount. The DPI scaling factor, the physical size compensation factor, and the position deviation compensation amount are combined to form the final physical coordinates.
[0017] Furthermore, the acquisition of the current DPI value of the display where the host process is located adopts a hierarchical acquisition mechanism: firstly, the accurate DPI scaling factor corresponding to the display is obtained through the native interface of the operating system; if the native interface call fails, it falls back to calculating the DPI scaling factor based on the rendering coordinate transformation parameters of the host window.
[0018] Furthermore, the synchronization step includes: Establish two parallel synchronous paths: an event-driven path and a timed polling path. The event-driven path responds to the size change event and / or position change event of the embedded container and triggers synchronization immediately. The timed polling path continuously performs synchronization at predetermined time intervals; The two paths converge at the arbitration convergence point, which then uniformly executes the calculation steps and the operation of adjusting the position and size of the embedded window by calling the window position setting function.
[0019] Furthermore, it also includes a rendering synchronization step: In each frame rendering event of the host window, a custom refresh request message is sent to the embedded window; If no confirmation response is received from the embedded window within the predetermined timeout period, the forced refresh function is invoked to refresh the display content of the embedded window.
[0020] Furthermore, the rendering synchronization step also includes: When the resizing of the embedded window begins, a pause redraw message is sent to the embedded window to pause the redrawing of the embedded window; After the size scaling is completed, a redraw message is sent to the embedded window, and a forced refresh function is called to trigger a full redraw of the embedded window.
[0021] Furthermore, in the management steps, the following dual detection mechanism is used to detect whether the external process has exited: Listen for the exit notification of the external process through the process exit event; and By sending a WM_NULL message to the embedded window of the external process and detecting the return result, it can be determined whether the embedded window is responsive. When the process exit event is triggered and the WM_NULL message returns a timeout or no response, it is confirmed that the external process has exited.
[0022] Furthermore, in the management steps, automatically restarting the external process and restoring the embedded state of the embedded window includes: Record the position and size of the embedded window at the moment the external process exits; Automatically launch a new instance of the external process based on the executable file path corresponding to the external process; After polling and waiting for the main window handle of the new external process instance to become valid, the window of the new external process instance is re-embedded into the embedding container of the host process. Based on the recorded position and size, the window position setting function is called to restore the position and size of the embedded window.
[0023] Furthermore, in the synchronization step, the target position output by the multi-factor compensation algorithm is compared with the actual position of the previous synchronization to calculate the position deviation. When the position deviation is less than or equal to a preset jitter threshold, the synchronization step skips the operation of calling the window position setting function to adjust the embedded window.
[0024] Secondly, embodiments of the present invention provide an adaptive synchronization system with cross-process window embedding, comprising: The perception module is used for the host process to perceive trigger events in real time. The trigger events include changes in the display environment of the monitor where the host process is located, changes in the window state of the container embedded in the host window, and changes in the health status of external processes. The calculation module is used to respond to the triggering event perceived by the perception module, call the multi-factor compensation algorithm, and calculate the target position and target size of the embedding window of the external process in the physical coordinate system according to the logical coordinates and logical size of the embedded container, the DPI scaling factor of the display where the host process is located, the physical size compensation factor of the display, and the deviation history queue. The synchronization module is used to call the window position setting function to adjust the position and size of the embedded window based on the target position and target size output by the calculation module; An adjustment module is used to dynamically adjust the execution frequency of the synchronization module according to the window state of the embedded container; The management module is used to automatically restart the external process and restore the embedded state of the embedded window when the external process exits, based on the health status change events of the external process sensed by the sensing module.
[0025] As can be seen from the above technical solutions, compared with the prior art, the present invention discloses an adaptive synchronization method and system for cross-process window embedding, which has the following beneficial effects: 1. This invention utilizes a multi-factor compensation algorithm, integrating DPI scaling factor, physical size compensation factor, and deviation history queue, to achieve a leap from "attribute synchronization" to "intelligent compensation." The algorithm incorporates a self-calibrating feedback loop, automatically updating the deviation history after each synchronization to continuously correct systematic offsets, achieving pixel-level coordinate conversion accuracy. Furthermore, this solution does not rely on external processes, fundamentally bypassing the Windows system's hard limitation of not forwarding DPI notifications across processes, ensuring that the embedded window remains precisely aligned and free of coordinate misalignment when the host window moves between different DPI displays.
[0026] 2. This invention achieves system self-recovery, self-optimization, and self-calibration through five closed-loop stages—"perception—synchronization—adjustment—rendering—management" and three feedback paths: when a process crashes, it automatically completes "dual detection → state saving → automatic restart → window restoration" without manual intervention, ensuring stability for long-term continuous operation; rendering cycle alignment and scaling rendering control eliminate flickering and tearing issues across the rendering pipeline, ensuring visual consistency; dynamic refresh adjustment automatically switches the refresh rate according to the window state, achieving a balance between real-time tracking and resource consumption, taking into account both high performance and low power consumption. Attached Figure Description
[0027] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0028] Figure 1 This is a flowchart of the adaptive synchronization method provided in the embodiments of the present invention; Figure 2 This is a schematic diagram of the overall architecture provided in an embodiment of the present invention; Figure 3 This is a flowchart of the multi-factor compensation algorithm provided in the embodiments of the present invention; Figure 4 This is a dynamic refresh adjustment three-state switching diagram provided in this embodiment of the invention; Figure 5 This is a timing diagram for process lifecycle management provided in an embodiment of the present invention; Figure 6 This is a schematic diagram of the rendering synchronization principle provided in an embodiment of the present invention; Figure 7 This is a structural diagram of the adaptive synchronization system provided in an embodiment of the present invention. Detailed Implementation
[0029] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0030] This invention discloses an adaptive synchronization method for cross-process window embedding, such as... Figure 1 As shown, it includes the following steps: S1. The host process is aware of triggering events in real time. The triggering events include changes in the display environment of the monitor where the host process is located, changes in the window state of the container embedded in the host window, and changes in the health status of external processes. S2. In response to the triggering event perceived in the perception step, a multi-factor compensation algorithm is invoked to calculate the target position and target size of the embedding window of the external process in the physical coordinate system based on the logical coordinates and logical size of the embedded container, the DPI scaling factor of the display where the host process is located, the physical size compensation factor of the display, and the deviation history queue. S3. Based on the target position and target size output in the calculation step, call the window position setting function to adjust the position and size of the embedded window; S4. Dynamically adjust the execution frequency of the synchronization step according to the window state of the embedded container; S5. Based on the health status change event of the external process sensed in the sensing step, when the external process is detected to have exited, the external process is automatically restarted and the embedded state of the embedded window is restored.
[0031] This embodiment provides an adaptive synchronization method and system for cross-process window embedding. Its core concept is to build a complete closed-loop control system from "perception" to "computation" and then to "synchronization", supplemented by "adjustment" and "management", so as to systematically solve problems such as position synchronization, DPI adaptation, rendering synchronization and process crash recovery after cross-process window embedding without relying on the cooperation of external processes.
[0032] The following is a detailed description of each of the above steps: Step S1: Perception Step; This step marks the starting point of closed-loop control and is executed by the sensing component. Figure 2 ② in the diagram is responsible for real-time sensing of triggering events. These triggering events mainly include three categories: display environment change events, window state change events, and external process health status change events.
[0033] S1.1 Display Environment Awareness: The system obtains the DPI scaling factor of the monitor where the host window is located in real time through the Windows API. Specifically, the current monitor's DPI value can be accurately obtained through the GetDpiForWindow API, or indirectly through the M11 and M22 properties of the WPF PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice matrix. When the host window is dragged and moved between monitors with different DPIs, this awareness mechanism will immediately capture the change event of the display environment.
[0034] S1.2 Window State Awareness: The system detects changes in window state by listening to WPF layout events of the embedded container. Specifically, this includes: detecting changes in the size of the embedded container through the SizeChanged event, detecting changes in the position of the embedded container through the LocationChanged event, and detecting changes in the visibility of the embedded container through the IsVisibleChanged event. Once these events are triggered, it indicates that the window state has changed.
[0035] S1.3 Process Health Awareness: The system monitors the health status of the external process in real time through a dual-detection mechanism. The first detection utilizes the Process.Exited event, which is triggered when the external process exits abnormally. The second detection uses SendMessageTimeout(WM_NULL) to send an empty message to the main window of the external process; if there is no response within the timeout period, the window is determined to be unresponsive. This dual-detection mechanism effectively avoids misjudgments from a single detection method, providing a reliable basis for subsequent crash recovery.
[0036] Step S2: Calculation steps; In response to the triggering event sensed in the sensing step S1, the system invokes the core algorithm, namely the multi-factor compensation algorithm, corresponding to... Figure 2 In step ①, calculate the target position and target size of the embedded window of the external process in the physical coordinate system.
[0037] The core of this step lies in the multi-factor compensation algorithm, which integrates four dimensions of input factors and achieves continuous self-calibration through an internal feedback loop. The specific calculation process is as follows: Figure 3 As shown, it includes the following sub-steps: S2.1 Receive input data in four dimensions using a multi-factor compensation algorithm: Logical coordinates: Obtain the logical position (X, Y) and logical size (Width, Height) of the embedded container in the WPF layout system, in device-independent pixels (1 / 96 inch).
[0038] DPI scaling factor: The DPI scaling factor is the current DPI value of the monitor where the host process is located divided by the base DPI value; the current DPI value is obtained in real time by the perception mechanism in step S1 (GetDpiForWindow is called first, and if it fails, it falls back to TransformToDevice for calculation). When the host window moves between monitors with different DPI values, the current DPI value changes, and the DPI scaling factor is updated dynamically accordingly. In one embodiment, the Windows system has a DPI baseline of 96 at 100% scaling.
[0039] Physical dimensions: Obtain the physical width and height of the display (in millimeters) through the GetDeviceCaps API, which is used to calculate the physical dimension compensation factor.
[0040] Deviation History Queue: This queue retrieves the actual deviation values recorded after the most recent n synchronization cycles. This queue forms the data foundation for the algorithm's internal feedback loop.
[0041] S2.2 Calculate sub-factors; The algorithm internally computes three key sub-factors in parallel: Sub-factor A: DPI scaling factor. This factor is the DPI scaling factor obtained in step S2-1. This invention employs a dual API guarantee mechanism: it prioritizes using the GetDpiForWindow API to obtain the accurate per-monitor DPI value; if the call fails, it automatically falls back to the WPF-based TransformToDevice method, ensuring the algorithm's compatibility across all versions of Windows 7 / 8.1 / 10 / 11.
[0042] Sub-factor B: Physical Size Compensation Factor. This factor is used to correct the impact of different physical sizes of monitors on the aspect ratio. The specific calculation method is: Actual PPI = Resolution Pixels / Physical Size (inches), Physical Size Compensation Factor = Actual PPI / 96. For example, monitors with the same 1920×1080 resolution may have different pixel densities on a 13-inch laptop and a 27-inch monitor. This compensation factor ensures that embedded windows maintain a consistent aspect ratio on monitors of different physical sizes.
[0043] Sub-factor C: Deviation Trend Determination. The algorithm analyzes the historical deviation queue. If the deviation value continues to accumulate in the same direction, a systematic shift is determined. In this case, the algorithm outputs the accumulated deviation as the compensation amount for this calculation.
[0044] S2.3, Synthesis and Output; The above three factors are combined to form the final physical coordinates: Final scaling factor = DPI scaling factor × physical size compensation factor; Deviation correction amount = f(deviation history queue, deviation threshold); Final physical coordinate X = Logical coordinate X × Final scaling factor + Deviation correction amount (when deviation > threshold); Final physical coordinate Y = Logical coordinate Y × Final scaling factor + Deviation correction amount (when deviation > threshold); Final physical width = logical width × final scaling factor; Final physical height = logical height × final scaling factor; The conversion result is calculated using double-precision floating-point arithmetic and rounded to the nearest integer pixel.
[0045] S2.4, Algorithm internal feedback update; After completing the calculation and outputting the result to the synchronization stage, the algorithm enqueues the actual deviation value after synchronization and updates the deviation history queue. This updated queue will be used for the deviation trend determination in the next round of calculation, i.e., the calculation of sub-factor C, thus forming a feedback loop within the algorithm and realizing the system's self-calibration capability.
[0046] Step S3: Synchronization Step; This step is performed by the synchronization mechanism, corresponding to... Figure 2 In step ③, the task is to translate the target position and target size calculated in step S2 into actual window operations.
[0047] To ensure the reliability of synchronization, this invention employs a dual-path guarantee mechanism: Path A (Event-driven path): In response to the SizeChanged or LocationChanged event triggered in step S1, a synchronous operation is triggered immediately, and its response delay can be controlled within 1 millisecond.
[0048] Path B (Timed Polling Path): The system continuously performs synchronization operations at dynamically adjustable intervals as a redundancy guarantee for the event-driven path, ensuring eventual consistency even in the event of a very small number of lost events.
[0049] The two paths converge at a unified arbitration convergence point. At this convergence point, the system performs the following operations: obtains the screen coordinates and actual rendering size of the embedded container; calls the multi-factor compensation algorithm described in step S2 to calculate the physical coordinates; and finally calls the window position setting function SetWindowPos to adjust the position and size of the external embedded window.
[0050] Furthermore, this step also involves coordination with the rendering process. To ensure visual consistency, before and after the synchronization step is executed, the system will pause the redrawing of the external window using SendMessage(WM_SETREDRAW, FALSE), and resume and trigger the redrawing using SendMessage(WM_SETREDRAW, TRUE) after the position adjustment is completed, in order to avoid visual tearing during the adjustment process.
[0051] Step S4: Adjustment steps; This step is performed by the adjustment mechanism, corresponding to... Figure 2 ④ in the example is used to dynamically adjust the execution frequency of the synchronization step S3 according to the window state of the embedded container.
[0052] like Figure 4 As shown, the adjustment mechanism defines a three-state switching mechanism, which automatically switches between the current window state and the target window state by analyzing the continuous triggering pattern of window state change events sensed in step S1: Static State: When the change in window position within 5 consecutive synchronization cycles is less than 1 pixel, it is determined to be in a static state. At this time, the system sends a frequency control signal to the synchronization stage via feedback path C, adjusting its execution frequency—that is, the interval of the timed polling path B—to 100-200ms. Taking 150ms (approximately 6.7 times / second) as an example, the theoretical number of calls to the timed polling path decreases from approximately 60 times / second in the high-frequency state to approximately 6.7 times / second, a reduction of approximately 89%. Each synchronization call involves operations such as obtaining PointToScreen coordinates, querying DPI scaling factors, and adjusting the SetWindowPos cross-process window. Under typical configurations, the measured CPU utilization reduction can reach approximately 70%. For multi-window embedded scenarios, based on the independent adjustment mechanism of each window, the overall reduction is even more significant, typically reaching 60%-80%.
[0053] Dragging: When the LocationChanged event is triggered consecutively, the window is considered to be in a dragging state. The system will adjust the synchronization execution frequency to approximately 16ms, corresponding to approximately 60fps, to achieve a real-time following effect when the window is dragged.
[0054] Scaling in progress: When the SizeChanged event is triggered consecutively, the window is considered to be in a scaling state. The system also adjusts the synchronization execution frequency to approximately 16ms to ensure that embedded content adapts without delay when the window is scaled.
[0055] Step S5: Management Steps This step is executed by the management team, corresponding to... Figure 2In step ⑥, the function is used to respond to the health status change event of the external process sensed in step S1, and automatically execute the crash recovery process when the external process is detected to have exited.
[0056] like Figure 5 As shown, the process specifically includes: Dual detection trigger: When an external process exits abnormally, the Process.Exited event in step S1 is triggered, and SendMessageTimeout(WM_NULL) times out. After double confirmation of process exit, the recovery process is started.
[0057] State saving: Immediately saves the position, size, and timestamp of the external process embedded window at the moment of the crash.
[0058] Automatic restart: Start a new instance of an external process based on the pre-stored original executable file path.
[0059] Window re-embedding: Poll and wait for the new process's main window handle to become valid, then re-embed it into the host container using APIs such as SetParent.
[0060] State restoration: The position and size information saved in step S2 is applied to the newly embedded window using SetWindowPos, restoring it to its state before the crash.
[0061] Feedback: After the recovery is completed, the management link transmits the recovery result back to the perception link through feedback path B, triggering a new round of synchronization loop to ensure the eventual consistency of the system state.
[0062] In one embodiment, during the synchronization process in step S3, a rendering synchronization operation is also performed in parallel to resolve the visual flickering problem caused by different rendering pipelines.
[0063] like Figure 6As shown, specifically, in the `CompositionTarget.Rendering` event of the host window, this event is triggered at a frequency of approximately 60fps. The system sends a custom refresh request message to the embedded external process window via `SendMessageTimeout`, with a timeout set to 100ms. This timeout duration balances the normal communication latency of cross-process message passing (typically 10-50ms) with the user's sensitivity to interface responsiveness (the human eye can perceive a latency threshold of approximately 100ms). This avoids misjudging the child window as unresponsive due to brief system busy periods, while ensuring that a forced refresh is triggered promptly when the child window is truly frozen, preventing visual stuttering. If no confirmation message is received from the child window within the 100ms timeout period, the `RedrawWindowAPI` is actively called to force a refresh of the child window area, ensuring that the parent and child windows are drawn within the same rendering frame, eliminating visual asynchrony.
[0064] In one implementation, step S4 further optimizes the rendering control of the scaling process, such as... Figure 6 As shown.
[0065] When window scaling begins, the system pauses the redrawing of the embedded window using SendMessage(WM_SETREDRAW, FALSE). During scaling, synchronization is continuously performed based on the target size calculated in step S2. Once scaling is complete, the system resumes the redrawing of the embedded window using SendMessage(WM_SETREDRAW, TRUE) and calls RedrawWindow to trigger a full redraw. This mechanism effectively avoids interface flickering and resource waste caused by frequent redrawing during scaling.
[0066] In one embodiment, before step S3 calls the window position setting function to adjust the position and size of the embedded window, a visual fusion step is also included.
[0067] Specifically, the system uses the SetWindowLong function to remove window styles such as WS_CAPTION (title bar), WS_THICKFRAME (border), and WS_SYSMENU (system menu) from the external process's embedded window, making it visually integrated with the host window and eliminating the sense of visual disjointedness.
[0068] Based on the same inventive concept, embodiments of the present invention also provide an adaptive synchronization system for cross-process window embedding, such as... Figure 7 As shown, it includes: The perception module is used for the host process to perceive trigger events in real time. The trigger events include changes in the display environment of the monitor where the host process is located, changes in the window state of the container embedded in the host window, and changes in the health status of external processes. The calculation module is used to respond to the triggering event perceived by the perception module, call the multi-factor compensation algorithm, and calculate the target position and target size of the embedding window of the external process in the physical coordinate system according to the logical coordinates and logical size of the embedded container, the DPI scaling factor of the display where the host process is located, the physical size compensation factor of the display, and the deviation history queue. The synchronization module is used to call the window position setting function to adjust the position and size of the embedded window based on the target position and target size output by the calculation module; An adjustment module is used to dynamically adjust the execution frequency of the synchronization module according to the window state of the embedded container; The management module is used to automatically restart the external process and restore the embedded state of the embedded window when the external process exits, based on the health status change events of the external process sensed by the sensing module.
[0069] The system adopts a "one core, five rings" architecture, which is organically connected through three closed-loop feedback paths, enabling the system to have self-adaptive, self-recovering, self-optimizing and self-calibrating capabilities.
[0070] In one preferred embodiment, when the host process needs to embed two or more external process windows simultaneously, the adaptive synchronization system maintains a complete context state instance independently for each embedded external process window. The context state instance includes at least: the window's specific multi-factor compensation algorithm input parameters, an independent deviation history queue, the current synchronization state identifier, and the corresponding embedding container handle.
[0071] Based on this, the perception stage listens to the independent window state events of each embedded container; the calculation stage independently calls the multi-factor compensation algorithm for each instance to calculate the target physical coordinates and size of each external window; and the synchronization stage calls the window position setting function (SetWindowPos) to perform independent position adjustment operations on each external window to ensure that each embedded window can accurately adapt to its corresponding container.
[0072] Meanwhile, to further optimize resource consumption in scenarios involving multiple embedded windows, the dynamic refresh adjustment method is also configured with a visibility-aware optimization strategy. Specifically, the adjustment step obtains the visibility state of each embedded container, i.e., the IsVisible attribute value. Only when the embedded container is currently visible is a high-frequency refresh synchronization operation performed on the external process window corresponding to that container. For invisible embedded containers, their corresponding timed polling synchronization tasks are paused. Through this differentiated refresh strategy, the system can effectively reduce overall CPU and GPU resource consumption, avoid main interface lag caused by maintaining synchronization tasks for a large number of invisible windows, and ensure the smoothness and responsiveness of the host application in multi-window embedded scenarios.
[0073] In one preferred embodiment, the management module is further configured with a persistent storage module to provide platform-level state saving and one-click recovery functionality. Specifically, when the host process is running normally and each external process window is successfully embedded, the management module writes the associated configuration information of each currently embedded external process window into the local persistent storage unit. The associated configuration information includes at least: the full path of the executable file corresponding to the external process, the startup command line parameters, the logical coordinates and logical size of the embedded window in the host container, the display identifier or DPI context information corresponding to the embedded window, and the window style blending parameters.
[0074] When the host process restarts due to user-initiated closure, operating system reboot, or abnormal crash, the perception stage automatically reads the associated configuration information stored in the persistent storage unit during the initialization phase. The management stage automatically starts all associated external process instances based on the read executable file path and command-line parameters, and waits for the main window handles of each new process instance to become effective through polling. After the main window handles become effective, the synchronization stage, based on the read logical coordinates, logical size, and display context information, calls the multi-factor compensation algorithm to recalculate the physical coordinates in the current display environment, and uses SetWindowPos to restore each external process window to its embedded position and size before the host process was closed.
[0075] Through the aforementioned persistence and automatic recovery mechanisms, the integrated platform of this invention can restore the complete working desktop state before shutdown with a single click, without any manual intervention, after system maintenance restarts, unexpected power outages, or version updates. This eliminates the need for users to reconfigure or manually drag and drop elements. This implementation is particularly suitable for scenarios requiring continuous 24 / 7 operation, such as industrial monitoring systems, automated testing platforms, and server-side remote control consoles, significantly improving system maintainability and user experience.
[0076] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. An adaptive synchronization method for cross-process window embedding, characterized in that, Includes the following steps: S1. The host process is aware of triggering events in real time. The triggering events include changes in the display environment of the monitor where the host process is located, changes in the window state of the container embedded in the host window, and changes in the health status of external processes. S2. In response to the triggering event perceived in the perception step, a multi-factor compensation algorithm is invoked to calculate the target position and target size of the embedding window of the external process in the physical coordinate system based on the logical coordinates and logical size of the embedded container, the DPI scaling factor of the display where the host process is located, the physical size compensation factor of the display, and the deviation history queue. S3. Based on the target position and target size output in the calculation step, call the window position setting function to adjust the position and size of the embedded window; S4. Dynamically adjust the execution frequency of the synchronization step according to the window state of the embedded container; S5. Based on the health status change event of the external process sensed in the sensing step, when the external process is detected to have exited, the external process is automatically restarted and the embedded state of the embedded window is restored.
2. The adaptive synchronization method for cross-process window embedding as described in claim 1, characterized in that, In the calculation steps, the multi-factor compensation algorithm includes: Obtain the current DPI value of the display where the host process is located, and calculate the DPI scaling factor, wherein the DPI scaling factor = current DPI value / N, and N is the base DPI of the Windows system; Obtain the physical size and resolution of the display, calculate the actual PPI value, where the actual PPI value = resolution pixels / physical size inches, and calculate the physical size compensation factor, where the physical size compensation factor = actual PPI value / N; Obtain the deviation history queue, which records the deviation value between the actual position of the embedded window and the target position after the execution of the last n synchronization steps. When the deviation values in the deviation history queue accumulate in the same direction for more than a predetermined number of consecutive times, it is determined that there is a systematic offset, and the accumulated deviation is output as the position deviation compensation amount. The DPI scaling factor, the physical size compensation factor, and the position deviation compensation amount are combined to form the final physical coordinates.
3. The adaptive synchronization method for cross-process window embedding as described in claim 2, characterized in that, The current DPI value of the monitor where the host process is located is obtained using a hierarchical acquisition mechanism: firstly, the accurate DPI scaling factor corresponding to the monitor is obtained through the native interface of the operating system; if the native interface call fails, the calculation of the DPI scaling factor is back based on the rendering coordinate transformation parameters of the host window.
4. The adaptive synchronization method for cross-process window embedding as described in claim 1, characterized in that, The synchronization steps include: Establish two parallel synchronous paths: an event-driven path and a timed polling path. The event-driven path is triggered to synchronize immediately in response to size change events and / or position change events of the embedded container; The timed polling path continuously performs synchronization at predetermined time intervals; The two paths converge at the arbitration convergence point, which then uniformly executes the calculation steps and the operation of adjusting the position and size of the embedded window by calling the window position setting function.
5. The adaptive synchronization method for cross-process window embedding as described in claim 1, characterized in that, It also includes the rendering synchronization step: In each frame rendering event of the host window, a custom refresh request message is sent to the embedded window; If no confirmation response is received from the embedded window within the predetermined timeout period, the forced refresh function is invoked to refresh the display content of the embedded window.
6. The adaptive synchronization method for cross-process window embedding as described in claim 5, characterized in that, The rendering synchronization step also includes: When the resizing of the embedded window begins, a pause redraw message is sent to the embedded window to pause the redrawing of the embedded window; After the size scaling is completed, a redraw message is sent to the embedded window, and a forced refresh function is called to trigger a full redraw of the embedded window.
7. The adaptive synchronization method for cross-process window embedding as described in claim 1, characterized in that, In the management steps, the following dual detection mechanism is used to detect whether the external process has exited: Listen for the exit notification of the external process through the process exit event; and By sending a WM_NULL message to the embedded window of the external process and detecting the return result, it can be determined whether the embedded window is responsive. When the process exit event is triggered and the WM_NULL message returns a timeout or no response, it is confirmed that the external process has exited.
8. The adaptive synchronization method for cross-process window embedding as described in claim 7, characterized in that, In the management steps, automatically restarting the external process and restoring the embedded state of the embedded window includes: Record the position and size of the embedded window at the moment the external process exits; Automatically launch a new instance of the external process based on the executable file path corresponding to the external process; After polling and waiting for the main window handle of the new external process instance to become valid, the window of the new external process instance is re-embedded into the embedding container of the host process. Based on the recorded position and size, the window position setting function is called to restore the position and size of the embedded window.
9. The adaptive synchronization method for cross-process window embedding as described in claim 1, characterized in that, In the synchronization step, the target position output by the multi-factor compensation algorithm is compared with the actual position of the previous synchronization to calculate the position deviation. When the position deviation is less than or equal to a preset jitter threshold, the synchronization step skips the operation of calling the window position setting function to adjust the embedded window.
10. An adaptive synchronization system with cross-process window embedding, characterized in that, include: The perception module is used for the host process to perceive trigger events in real time. The trigger events include changes in the display environment of the monitor where the host process is located, changes in the window state of the container embedded in the host window, and changes in the health status of external processes. The calculation module is used to respond to the triggering event perceived by the perception module, call the multi-factor compensation algorithm, and calculate the target position and target size of the embedding window of the external process in the physical coordinate system according to the logical coordinates and logical size of the embedded container, the DPI scaling factor of the display where the host process is located, the physical size compensation factor of the display, and the deviation history queue. The synchronization module is used to call the window position setting function to adjust the position and size of the embedded window based on the target position and target size output by the calculation module; An adjustment module is used to dynamically adjust the execution frequency of the synchronization module according to the window state of the embedded container; The management module is used to automatically restart the external process and restore the embedded state of the embedded window when the external process exits, based on the health status change events of the external process sensed by the sensing module.
Citation Information
Patent Citations
Windows cross-process window management methods, storage media, electronic devices and systems
CN109101298B
Multi-process interface fusion method and device
CN117539582B
Cross-process window embedding method and system, electronic equipment, storage medium and product
CN119311438A
Intelligent window placement with multiple windows using high DPI screens
US20140237421A1
