main.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
  7. _In_ wchar_t *command_line, _In_ int show_command) {
  8. if (wcsstr(command_line, L"--runas-admin") != NULL) {
  9. }
  10. else {
  11. HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"wl_base_help_example");
  12. if (hwnd != NULL) {
  13. //DispatchToProtocolHandler(hwnd);
  14. ::ShowWindow(hwnd, SW_NORMAL);
  15. ::SetForegroundWindow(hwnd);
  16. return EXIT_FAILURE;
  17. }
  18. }
  19. // Attach to console when present (e.g., 'flutter run') or create a
  20. // new console when running with a debugger.
  21. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
  22. CreateAndAttachConsole();
  23. }
  24. else {
  25. AllocConsole();
  26. ShowWindow(GetConsoleWindow(), SW_HIDE);
  27. }
  28. // Initialize COM, so that it is available for use in the library and/or
  29. // plugins.
  30. ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
  31. flutter::DartProject project(L"data");
  32. std::vector<std::string> command_line_arguments =
  33. GetCommandLineArguments();
  34. project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
  35. FlutterWindow window(project);
  36. Win32Window::Point origin(10, 10);
  37. Win32Window::Size size(1280, 720);
  38. if (!window.Create(L"wl_base_help_example", origin, size)) {
  39. return EXIT_FAILURE;
  40. }
  41. window.SetQuitOnClose(true);
  42. ::MSG msg;
  43. while (::GetMessage(&msg, nullptr, 0, 0)) {
  44. ::TranslateMessage(&msg);
  45. ::DispatchMessage(&msg);
  46. }
  47. ::CoUninitialize();
  48. return EXIT_SUCCESS;
  49. }