leanflutter / window_manager

This plugin allows Flutter desktop apps to resizing and repositioning the window.
https://pub.dev/packages/window_manager
MIT License
701 stars 193 forks source link

Desktop embed mode support! #433

Closed badwei closed 8 months ago

badwei commented 8 months ago

Recently, I encountered the need to pin the window to the desktop. It looks like it's embedded in the desktop, but it's not. It will block the Windows+D shortcut key, or display the desktop and other user operations. However, it will always be displayed on the desktop until the user closes it. 微信图片_20240125100536 hope support it !

lijy91 commented 8 months ago

You can try setAlwaysOnBottom

badwei commented 8 months ago

You can try setAlwaysOnBottom

I tried the method you provided and it's a good option. It has met most of my needs, but one problem is that when I press the Windows+d shortcut key, it will still be minimized by the Windows system. I want it to stay on the desktop forever unless the user actively closes it or ends the process, just like the windows7 sidebar does.

lijy91 commented 8 months ago

Or you can listen to the hide event and let it reshow after receiving the hide event

badwei commented 8 months ago

Or you can listen to the hide event and let it reshow after receiving the hide event

Thank you for your quick response. I will try this method and hope it helps. At the same time, I also found some methods on the Internet, which is a program that sets the parent handle of the current win32 handle to SHELLDLL_DefView, which can do what I said earlier. The biggest difficulty at the moment is that I need to learn win32 programming. Can you help me see if this code will help me?


bool Win32Window::CheckAndSetParent(HWND hWnd){
       HWND s_hWndOldParent;
       HWND hWndProgram;
       HWND hWndShellDLL;
       hWndProgram = FindWindow(TEXT("Progman"), TEXT("Program Manager"));
       if(hWndProgram != NULL)
       {
           hWndShellDLL = FindWindowEx(hWndProgram, NULL, TEXT("SHELLDLL_DefView"), NULL);
       }

       if(hWndShellDLL != NULL
           && hWndShellDLL != s_hWndOldParent)
       {  
            printf("hllo");
            SetWindowLong(hWnd, 0, (LONG)hWndShellDLL);
            s_hWndOldParent = hWndShellDLL;
            return true;
       }
       return false;
   }
badwei commented 8 months ago

Or you can listen to the hide event and let it reshow after receiving the hide event

I just tried the method you told me. First: I listen for the minimize event and when the window is minimized, I restore it. Indeed it works, but one problem is that it has a minimize to restore process, and we can see this process directly. Secondly: I listen to windows events and block the WN_SYSCOMMAND command, which also prevents the application icon minimization program from clicking on the status bar. ` win32_window.cpp method Win32Window::MessageHandler

add code case WM_SYSCOMMAND: return 0; `

But neither method prevents pressing windows+d or minimizing applications when the desktop is displayed.

badwei commented 8 months ago

I solved my problem by adding the following code in the CreateAndShow method in the win32_window.cpp file. But I don't know of any bad effects yet. However, I still hope to add it to the window_manager library, hoping to help others. ` bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, const Size& size) { Destroy();

const wchar_t* window_class = WindowClassRegistrar::GetInstance()->GetWindowClass();

const POINT target_point = {static_cast(origin.x), static_cast(origin.y)}; HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); double scale_factor = dpi / 96.0;

HWND window = CreateWindow( window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this);

if (!window) { return false; }

// i added the below code **HWND hWndProgram = FindWindowW(L"Progman", L"Program Manager"); HWND hWndShellDLL = FindWindowExW(hWndProgram, NULL, L"SHELLDLL_DefView", NULL);

if(hWndShellDLL != NULL && hWndShellDLL != window){ SetParent(window,hWndShellDLL); window = hWndShellDLL; }** return OnCreate(); } `