main.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <flutter/dart_project.h>
  2. #include <flutter/flutter_view_controller.h>
  3. #include <windows.h>
  4. #include "flutter_window.h"
  5. #include "utils.h"
  6. #include <protocol_handler/protocol_handler_plugin.h>
  7. int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
  8. _In_ wchar_t *command_line, _In_ int show_command) {
  9. HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"naiyouwl");
  10. if (hwnd != NULL) {
  11. DispatchToProtocolHandler(hwnd);
  12. ::ShowWindow(hwnd, SW_NORMAL);
  13. ::SetForegroundWindow(hwnd);
  14. return EXIT_FAILURE;
  15. }
  16. /*
  17. *
  18. else {
  19. AllocConsole();
  20. ShowWindow(GetConsoleWindow(), SW_HIDE);
  21. }
  22. * */
  23. // https://github.com/flutter/flutter/issues/47891#issuecomment-708850435
  24. // https://github.com/flutter/flutter/issues/47891#issuecomment-869729956
  25. // https://github.com/dart-lang/sdk/issues/39945#issuecomment-870428151
  26. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
  27. CreateAndAttachConsole();
  28. }
  29. else {
  30. AllocConsole();
  31. ShowWindow(GetConsoleWindow(), SW_HIDE);
  32. }
  33. // Initialize COM, so that it is available for use in the library and/or
  34. // plugins.
  35. ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
  36. flutter::DartProject project(L"data");
  37. std::vector<std::string> command_line_arguments =
  38. GetCommandLineArguments();
  39. project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
  40. FlutterWindow window(project);
  41. Win32Window::Point origin(10, 10);
  42. Win32Window::Size size(1280, 720);
  43. if (!window.Create(L"naiyouwl", origin, size)) {
  44. return EXIT_FAILURE;
  45. }
  46. window.SetQuitOnClose(true);
  47. ::MSG msg;
  48. while (::GetMessage(&msg, nullptr, 0, 0)) {
  49. ::TranslateMessage(&msg);
  50. ::DispatchMessage(&msg);
  51. }
  52. ::CoUninitialize();
  53. return EXIT_SUCCESS;
  54. }