{"id":33311625,"url":"https://github.com/sweetwisdom/electron-native-windows","last_synced_at":"2026-06-13T19:33:13.300Z","repository":{"id":322552673,"uuid":"1089955274","full_name":"sweetwisdom/electron-native-windows","owner":"sweetwisdom","description":"Electron comunicate with native process by grpc","archived":false,"fork":false,"pushed_at":"2025-11-05T03:32:41.000Z","size":2909,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-05T05:33:25.598Z","etag":null,"topics":["electron","node-gyp","win32"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sweetwisdom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-05T03:20:02.000Z","updated_at":"2025-11-05T05:31:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sweetwisdom/electron-native-windows","commit_stats":null,"previous_names":["sweetwisdom/electron-native-windows"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/sweetwisdom/electron-native-windows","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweetwisdom%2Felectron-native-windows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweetwisdom%2Felectron-native-windows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweetwisdom%2Felectron-native-windows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweetwisdom%2Felectron-native-windows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sweetwisdom","download_url":"https://codeload.github.com/sweetwisdom/electron-native-windows/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweetwisdom%2Felectron-native-windows/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285187921,"owners_count":27129352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-19T02:00:05.673Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electron","node-gyp","win32"],"created_at":"2025-11-19T05:01:37.397Z","updated_at":"2025-11-19T05:04:23.029Z","avatar_url":"https://github.com/sweetwisdom.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[中文文档](./REDME-zh.md)\n\n\n\n# BrowserWindowTool - Embedding Windows Application Windows in Electron\n\n## Project Overview\n\nBrowserWindowTool is an Electron project designed to embed other Windows applications (such as Notepad, Paint, Calculator, etc.) within an Electron application window. By leveraging Node.js native modules, this project achieves seamless integration and control of external Windows application windows within an Electron environment.\n\n## Project Structure\n\n```\n├── binding.gyp                  # Node.js native module build config\n├── electron-example             # Electron application\n│   ├── blank.html               # Blank template for embedded windows\n│   ├── index.html               # Main interface\n│   ├── main.js                  # Electron main process\n│   ├── preload.js               # Preload script\n│   └── render.js                # Renderer process script\n└── src                          # Native module source code\n    ├── main.cc                  # N-API module entry\n    ├── WindowManager.cc         # Window management implementation\n    └── WindowManager.h          # Header file\n```\n```tip\n\n├── release/BrowserWindowTool.node # This is the build product for nodegyp on Windows\n\nIf you don't have a Visual Studio environment, delete the binding.gyp file and copy `release/BrowserWindowTool.node` to `/build/Release/BrowserWindowTool.node`\n\n```\n\n## demo\n\nhttps://github.com/user-attachments/assets/3c634c98-b208-4e20-ae04-0f71c0c3653f\n\n\n\nembed cloudmusic\n\n\u003cimg src=\".imgs/image-20251105105003418.png\" alt=\"image-20251105105003418\" style=\"zoom:50%;\" /\u003e\n\n\n\nembed notepad++\n\n\u003cimg src=\".imgs/image-20251105104040297.png\" alt=\"image-20251105104040297\" style=\"zoom:50%;\" /\u003e\n\n##  bugs \n\n\n\u003cimg src=\".imgs/image-20251105104548437.png\" alt=\"image-20251105104548437\" style=\"zoom:50%;\" /\u003e\n\n\n## Core Principles\n\n### 1. Why Native Modules Are Required\n\nElectron, built on Chromium and Node.js, does not natively support embedding external Windows application windows. Due to incompatibilities between Chromium's rendering engine and Windows' native window management, native modules are necessary to bridge this gap.\n\n### 2. Embedding Technology Principles\n\nThe core implementation involves the following steps:\n\n1. **Container Window Creation**: A transparent child window (container window) is created in the Electron window to act as the \"canvas\" for embedding external applications.\n\n2. **Process Initialization**: Target applications are launched using Windows API.\n\n3. **Window Discovery**: Target application windows are identified through window enumeration.\n\n4. **Window Embedding**: The parent window of the target application is set to the container window, effectively embedding it.\n\n5. **Window Resizing**: Embedded windows are dynamically resized to match the container window.\n\n### 3. Key Technical Components\n\n#### a. GPU Acceleration Disabled\n\nTo avoid rendering conflicts, GPU acceleration is disabled with these command-line switches:\n\n```javascript\napp.commandLine.appendSwitch(\"in-process-gpu\");\napp.commandLine.appendSwitch(\"disable-gpu-sandbox\");\napp.commandLine.appendSwitch(\"disable-direct-composition\");\napp.commandLine.appendSwitch(\"disable-gpu\");\napp.commandLine.appendSwitch(\"no-sandbox\");\n```\n\n#### b. Native Module Integration\n\nA native module (BrowserWindowTool) using Node.js N-API provides critical functions:\n- `createEmbeddedWindow`: Creates embedded windows\n- `updateWindow`: Updates window properties\n- `destroyWindow`: Destroys embedded windows\n- `getAllWindowIds`: Retrieves all window IDs\n- `cleanupAll`: Cleans up resources\n\n#### c. Window Embedding Implementation\n\nKey logic in `WindowManager.cc`:\n\n```cpp\nHWND WindowManager::FindAndEmbedWindow(DWORD processId, HWND containerWindow)\n{\n    // Window discovery loop\n    HWND targetWindow = NULL;\n    for (int i = 0; i \u003c 50; ++i) {\n        EnumWindowsData data = {processId, NULL};\n        EnumWindows(EnumWindowsProc, reinterpret_cast\u003cLPARAM\u003e(\u0026data));\n        if (data.targetWindow) {\n            targetWindow = data.targetWindow;\n            break;\n        }\n        Sleep(100);\n    }\n    \n    // Style modification and embedding\n    LONG_PTR style = GetWindowLongPtr(targetWindow, GWL_STYLE);\n    style = (style \u0026 ~(WS_POPUP | WS_CAPTION | WS_THICKFRAME)) | WS_CHILD;\n    SetWindowLongPtr(targetWindow, GWL_STYLE, style);\n    \n    SetParent(targetWindow, containerWindow);\n    \n    // Size adjustment\n    RECT rect;\n    GetClientRect(containerWindow, \u0026rect);\n    SetWindowPos(targetWindow, HWND_TOP, 0, 0, \n                rect.right - rect.left, rect.bottom - rect.top, \n                SWP_SHOWWINDOW | SWP_FRAMECHANGED);\n    \n    return targetWindow;\n}\n```\n\n#### d. Window Event Handling\n\nCustom window procedure in `ContainerWndProc`:\n\n```cpp\nLRESULT CALLBACK WindowManager::ContainerWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)\n{\n    switch (msg) {\n    case WM_SIZE:\n        // Size adjustment logic\n        return 0;\n    case WM_NCCALCSIZE:\n        return 0;\n    }\n    return DefWindowProcW(hwnd, msg, wparam, lparam);\n}\n```\n\n\n\n## Key Interaction Flow\n\n1. **Container Window Creation**:\n   - Electron creates transparent container window\n   - Retrieves native window handle\n\n2. **Native Module Invocation**:\n   - IPC communication transfers window handle\n   - Native module creates container window\n   - Launches target process\n   - Embeds discovered window\n\n3. **Window Management**:\n   - IPC interface controls window lifecycle\n   - Native module maintains window state\n\n## Technical Challenges \u0026 Solutions\n\n### 1. Window Z-Order Issues\n\n**Solution**: \n```cpp\nSetWindowPos(targetWindow, HWND_TOP, ...);\nBringWindowToTop(targetWindow);\n```\n\n### 2. Window Style Compatibility\n\n**Solution**: \n```cpp\n// Modified window style\nstyle = (style \u0026 ~(WS_POPUP | WS_CAPTION | WS_THICKFRAME)) | WS_CHILD;\n```\n\n### 3. Dynamic Resizing\n\n**Solution**:\n```cpp\ncase WM_SIZE:\n    SetWindowPos(childWindow, NULL, 0, 0, \n                rect.right - rect.left, rect.bottom - rect.top, \n                SWP_NOZORDER | SWP_NOACTIVATE);\n```\n\n## Important Considerations\n\n1. **Windows-Only**: Relies on Windows API\n2. **Native Applications**: Only supports Windows-native applications\n3. **Style Customization**: May require special handling for different apps\n4. **Performance**: Resource-intensive applications may impact performance\n5. **Security**: Disabled security features require trusted environments\n\n### refer\n\n[xland/ElectronGrpc: Electron comunicate with native process by grpc](https://github.com/xland/ElectronGrpc)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsweetwisdom%2Felectron-native-windows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsweetwisdom%2Felectron-native-windows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsweetwisdom%2Felectron-native-windows/lists"}