| 39 | /////////////////////////////////////////// |
| 40 | |
| 41 | void demo_windows_init() { |
| 42 | mirror_mesh = mesh_find (default_id_mesh_quad); |
| 43 | |
| 44 | DwmGetDxSharedSurface = (fn_GetDxSharedSurface)GetProcAddress(LoadLibrary("user32.dll"), "DwmGetDxSharedSurface"); |
| 45 | |
| 46 | ID3D11DeviceContext *context; |
| 47 | render_get_device((void**)&mirror_device, (void**)&context); |
| 48 | |
| 49 | EnumWindows([](HWND hwnd, LPARAM) { |
| 50 | if (hwnd == nullptr) return TRUE; |
| 51 | if (hwnd == GetShellWindow()) return TRUE; |
| 52 | if (!IsWindowVisible(hwnd)) return TRUE; |
| 53 | if (GetAncestor(hwnd, GA_ROOT) != hwnd) return TRUE; |
| 54 | |
| 55 | LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE); |
| 56 | if (style & WS_DISABLED) return TRUE; |
| 57 | |
| 58 | //int hrTemp = DwmGetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE.Cloaked, out bool cloaked, Marshal.SizeOf<bool>()); |
| 59 | //if (hrTemp == 0 && cloaked) return false; |
| 60 | |
| 61 | char text[256]; |
| 62 | GetWindowText(hwnd, text, sizeof(text)); |
| 63 | if (strcmp(text, "") == 0) return TRUE; |
| 64 | |
| 65 | HANDLE surface = nullptr; |
| 66 | LUID luid = { 0, }; |
| 67 | ULONG format = 0; |
| 68 | ULONG flags = 0; |
| 69 | ULONGLONG update_id = 0; |
| 70 | if (!DwmGetDxSharedSurface(hwnd, &surface, &luid, &format, &flags, &update_id)) { |
| 71 | log_warn("Failed to get surface!"); |
| 72 | return TRUE; |
| 73 | } |
| 74 | |
| 75 | ID3D11Texture2D *shared_tex = nullptr; |
| 76 | if (FAILED(mirror_device->OpenSharedResource(surface, __uuidof(ID3D11Texture2D), (void**)(&shared_tex)))) { |
| 77 | log_warn("Failed to get shared surface!"); |
| 78 | return TRUE; |
| 79 | } |
| 80 | |
| 81 | window_t win = {}; |
| 82 | win.window = hwnd; |
| 83 | win.material = material_copy_id(default_id_material_unlit); |
| 84 | win.texture = tex_create(); |
| 85 | win.pose = pose_t{ vec3{0,0,-0.5f} + vec3{0.04f, 0.04f, -0.04f} * (float)mirror_windows.size(), quat_lookat(vec3_zero, {0,0,1}) }; |
| 86 | strncpy(win.name, text, sizeof(win.name)); |
| 87 | tex_set_surface(win.texture, shared_tex, tex_type_image_nomips, format, 0, 0, 1); |
| 88 | tex_set_address(win.texture, tex_address_clamp); |
| 89 | material_set_texture(win.material, "diffuse", win.texture); |
| 90 | mirror_windows.push_back(win); |
| 91 | |
| 92 | return TRUE; |
| 93 | }, 0); |
| 94 | } |
| 95 | |
| 96 | /////////////////////////////////////////// |
| 97 |
nothing calls this directly
no test coverage detected