main.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. } else {
  29. AllocConsole();
  30. ShowWindow(GetConsoleWindow(), SW_HIDE);
  31. }
  32. // Initialize COM, so that it is available for use in the library and/or
  33. // plugins.
  34. ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
  35. flutter::DartProject project(L"data");
  36. std::vector<std::string> command_line_arguments =
  37. GetCommandLineArguments();
  38. project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
  39. FlutterWindow window(project);
  40. Win32Window::Point origin(10, 10);
  41. Win32Window::Size size(1280, 720);
  42. if (!window.Create(L"naiyouwl", origin, size)) {
  43. return EXIT_FAILURE;
  44. }
  45. window.SetQuitOnClose(true);
  46. ::MSG msg;
  47. while (::GetMessage(&msg, nullptr, 0, 0)) {
  48. ::TranslateMessage(&msg);
  49. ::DispatchMessage(&msg);
  50. }
  51. ::CoUninitialize();
  52. return EXIT_SUCCESS;
  53. }