英文:
How can I inform the OS to position the Cloud Clipboard (or Emoji Panel) over my window?
问题
我有一个基于传统的Win32 C++的Windows桌面应用程序。在窗口中,我处理<kbd>Ctrl+V</kbd>以处理粘贴的内容。同一个窗口还处理键击,将键入的字符添加到我管理的内容中。所有这些都很正常!
然而,如果用户按下<kbd>Win+V</kbd>从云剪贴板粘贴,或按下<kbd>Win+.</kbd>使用表情面板键入,那些弹出窗口并没有出现在我的窗口附近,即使它是活动窗口并具有输入焦点。
是否有API我应该调用,或者我需要响应的Windows消息,以通知操作系统我的窗口希望附近打开面板,最好沿着其边界,或者我提供的矩形?
我尝试调用SetCaretPos()
,但这种行为不会影响任何事情。我看到周围有许多用于查看剪贴板内容更改的剪贴板查看器API,但那是用于希望监视剪贴板内容更改的窗口,而不是像我的这种普通接受输入的窗口。
我只是希望操作系统弹出窗口靠近我的窗口,就像普通的Edit
或Combo
控件在具有输入焦点时会发生的那样。
一些截图以说明:
所需位置,就像运行对话框一样:
使用MFC测试程序复制的错误:
要复制该错误,请创建一个支持标准Edit > Paste
菜单项的MFC应用程序,其中包含ID_EDIT_PASTE
加速键。将其映射到以下OnEditPaste
处理程序(只是在MessageBox中显示任何CF_TEXT
):
void TestView::OnEditPaste()
{
if (OpenClipboard()) {
if (auto hText = ::GetClipboardData(CF_TEXT); hText != NULL) {
if (auto pData = ::GlobalLock(hText); pData) {
std::string msg{(char*)pData, ::GlobalSize(hText)};
::MessageBoxA(GetSafeHwnd(), msg.c_str(), "Pasted", MB_OK);
::GlobalUnlock(hText);
}
}
CloseClipboard();
}
}
运行应用程序并激活视图。然后按<kbd>Win+V</kbd>,云剪贴板将远离窗口打开;这是我迫切希望解决的问题。
英文:
I have a traditional Win32 C++-based Windows desktop application. In the window, I handle <kbd>Ctrl+V</kbd> to process pasted content. The same window also handles keystrokes with the typed character added to the content I manage. All this works fine!
However, if the user presses <kbd>Win+V</kbd> to paste from the Cloud Clipboard, or presses <kbd>Win+.</kbd> to type using the Emoji panel, those popup windows are not positioned anywhere near my window, even though it is the active window with input focus.
Is there an API I should call, or a Windows message I need to be responding to, in order to inform the OS that my window wants the panel opened nearby, preferably along its border, or a rect I supply?
I have tried calling SetCaretPos()
, but the behavior doesn't affect anything. I see APIs all around being a Clipboard Viewer, but that's for windows which want to watch for clipboard content changes, and not a normal window accepting input like mine.
I just want the OS popup to be near to my window, as happens for the common Edit
or Combo
controls when they have input focus.
Some screenshots to illustrate:
Desired Location ala the Run dialog:
Bug replicated with a MFC test program:
To replicate the bug yourself, create an MFC app supporting the standard Edit > Paste
menu item with the ID_EDIT_PASTE
accelerator. Map that to an OnEditPaste
handler like below (just shows any CF_TEXT
in a MessageBox):
void TestView::OnEditPaste()
{
if (OpenClipboard()) {
if (auto hText = ::GetClipboardData(CF_TEXT); hText != NULL) {
if (auto pData = ::GlobalLock(hText); pData) {
std::string msg{(char*)pData, ::GlobalSize(hText)};
::MessageBoxA(GetSafeHwnd(), msg.c_str(), "Pasted", MB_OK);
::GlobalUnlock(hText);
}
}
CloseClipboard();
}
}
Run your app and activate the view. Then press <kbd>Win+V</kbd> and the Cloud Clipboard opens far away; that's the issue I'm desperate to solve.
答案1
得分: 3
我在这里找到了类似的情况:如何在Win32中设置Emoji弹出位置。
那个问题涉及到Emoji面板,但修复也影响了Cloud Clipboard的位置。看起来操作系统将它们都视为特殊的输入法编辑窗口。
关键是要响应WM_IME_REQUEST
消息,具体来说,是IMR_QUERYCHARPOSITION
查询。
如果你在使用MFC,你可能需要类似这样的代码。以下代码将提示符放置在窗口的左上角,但你应该能理解这个思路。
class TestView : public CView
{
. . .
afx_msg LRESULT OnImeRequest(WPARAM wParam, LPARAM lParam);
}
BEGIN_MESSAGE_MAP(TestView, CView)
. . .
ON_MESSAGE(WM_IME_REQUEST, OnImeRequest)
END_MESSAGE_MAP()
LRESULT TestView::OnImeRequest(WPARAM wParam, LPARAM lParam)
{
switch (wParam) {
case IMR_QUERYCHARPOSITION: {
RECT rcWindow{};
GetWindowRect(&rcWindow);
IMECHARPOSITION* charPos = (IMECHARPOSITION*)lParam;
charPos->dwSize = sizeof(IMECHARPOSITION);
charPos->pt.x = rcWindow.left;
charPos->pt.y = rcWindow.top;
charPos->cLineHeight = 10;
GetClientRect(&charPos->rcDocument);
return 1;
}
}
return 0;
}
英文:
I found a similar situation here: How to set Emoji popup position in Win32
That question is regarding the Emoji panel but the fix also affects the Cloud Clipboard location as well. It seems that the OS treats both as special IME windows.
The key is to respond to the WM_IME_REQUEST
message, specifically, the IMR_QUERYCHARPOSITION
query.
If you're using MFC, you'll want something like this. This just places the prompt in the top-left of the window but you should get the idea.
class TestView : public CView
{
. . .
afx_msg LRESULT OnImeRequest(WPARAM wParam, LPARAM lParam);
}
BEGIN_MESSAGE_MAP(TestView, CView)
. . .
ON_MESSAGE(WM_IME_REQUEST, OnImeRequest)
END_MESSAGE_MAP()
LRESULT TestView::OnImeRequest(WPARAM wParam, LPARAM lParam)
{
switch (wParam) {
case IMR_QUERYCHARPOSITION: {
RECT rcWindow{};
GetWindowRect(&rcWindow);
IMECHARPOSITION* charPos = (IMECHARPOSITION*)lParam;
charPos->dwSize = sizeof(IMECHARPOSITION);
charPos->pt.x = rcWindow.left;
charPos->pt.y = rcWindow.top;
charPos->cLineHeight = 10;
GetClientRect(&charPos->rcDocument);
return 1;
}
}
return 0;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论