我想在一些 HTML 元素上实现带有拖动逻辑的无边框窗口。我找到了一些工作示例(例如Chrome 的无框窗口),这就是我尝试过的:
.title-area
{
-webkit-app-region: drag;
}
<div class='title-area'>
A draggable area
</div>
然后,在 C# 代码中,我实现了 IDragHandler 类:
internal class PromtDragHandler : IDragHandler
{
bool IDragHandler.OnDragEnter(IWebBrowser browserControl, IBrowser browser, IDragData dragData, DragOperationsMask mask)
{
return false;
}
void IDragHandler.OnDraggableRegionsChanged(IWebBrowser browserControl, IBrowser browser, IList<DraggableRegion> regions)
{
}
}
方法 OnDraggableRegionsChanged 在开始时触发一次,当我拖动元素“标题区域”的某些文本时触发 OnDragEnter。但我不确定下一步该怎么做才能让我的窗口移动?
更新。正如评论中提到的,CefTestApp支持此拖动功能。在源代码中,我们有从 DragHandler 调用的方法 OnSetDraggableRegions:
void RootWindowWin::OnSetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) {
REQUIRE_MAIN_THREAD();
// Reset draggable region.
::SetRectRgn(draggable_region_, 0, 0, 0, 0);
// Determine new draggable region.
std::vector<CefDraggableRegion>::const_iterator it = regions.begin();
for (;it != regions.end(); ++it) {
HRGN region = ::CreateRectRgn(
it->bounds.x, it->bounds.y,
it->bounds.x + it->bounds.width,
it->bounds.y + it->bounds.height);
::CombineRgn(
draggable_region_, draggable_region_, region,
it->draggable ? RGN_OR : RGN_DIFF);
::DeleteObject(region);
}
// Subclass child window procedures in order to do hit-testing.
// This will be a no-op, if it is already subclassed.
if (hwnd_) {
WNDENUMPROC proc = !regions.empty() ?
SubclassWindowsProc : UnSubclassWindowsProc;
::EnumChildWindows(
hwnd_, proc, reinterpret_cast<LPARAM>(draggable_region_));
}
}
我还是不太明白,关于可拖动区域(在启动时只触发一次)的确切信息如何帮助移动窗口?有人可以向我解释这个逻辑或提供与此代码等效的 C# 吗?