用例
我想用Flutter构建一个virtual keyboard
。我的灵感来自windows虚拟键盘“osk”(只需在cmd中运行“osk”)。每当我在不同的窗口中键入内容时,我都不(!)想失去焦点。
问题
flutter-app(桌面,windows)总是抢着焦点,我假设它是在main.cpp
中配置的,但我还没有找到如何达到和osk
一样的效果。
如何严格禁止窗口获得任何焦点?
下面是main.cpp
代码:
#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <windows.h>
#include "flutter_window.h"
#include "utils.h"
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command)
{
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent())
{
CreateAndAttachConsole();
}
// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data");
std::vector<std::string> command_line_arguments =
GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project);
Win32Window::Point origin(0, 0);
Win32Window::Size size(1024, 768);
if (!window.CreateAndShow(L"windows", origin, size))
{
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}
1条答案
按热度按时间kzipqqlq1#
溶液1
感谢@Axalo,* 扩展窗口样式 *
WS_EX_NOACTIVATE
是正确答案。创建窗口时需要设置它。溶液2(Flutter)
实际上,在flutter中运行时也可以这样做,我使用的是win32和window_manager插件。
您可以恢复旧状态: