如何向 MDI 中的所有子窗口发送 KeyDown 消息

发布于 2024-09-28 08:23:11 字数 510 浏览 6 评论 0原文

我需要向 MDI 应用程序中的所有子窗口发送 WM_KEYDOWN 消息。这个想法是,特定的按键会刷新一个窗口,我想只需按一次按键即可刷新所有子窗口。除了刷新之外,还有更多这样的功能,例如右/左/上/下箭头键等,需要转到每个子窗口。

我正在 STL 列表中维护所有可用/合格子窗口的列表(在子窗口/视图创建期间完成)。现在,我可以在哪里捕获按键并将其传递到此列表中的所有子窗口?实施的一些细节也将受到赞赏。

经过一番灵魂搜索和互联网搜索后,我得出的结论是 SendMessageToDescendants 应该会有所帮助。现在: 1. 从哪里调用SendMessageToDescendants 2. 如何传递CView的OnKeyDown(UINT nChar, UINT nRepCnt、UINT nFlags) 至 无效发送消息到后代( UINT 消息, WPARAM wParam = 0, LPARAM lParam = 0, BOOL bDeep = TRUE, BOOL bOnlyPerm = FALSE );

I need to send a WM_KEYDOWN message to all the Child Windows in my MDI app. The idea being that a particular key press refreshes a window and I want to refresh all child wnds at just a single key press. Other than refresh there would be couple of more such functions like right/left/up/down arrow keys etc. that need to go to each of these child wnds.

I am maintaining a list of all the available/eligible Child Windows in an STL List (being done during child window/view creation). Now, where can I capture a key press and pass it on to ALL the child windows in this list? Some specifics of the implementation would be appreciated as well.

After some soul and internet searching, I have came to conclusion that SendMessageToDescendants should be helpful. Now:
1. Where to call SendMessageToDescendants from
2. How to pass the params required by CView's OnKeyDown(UINT nChar,
UINT nRepCnt, UINT nFlags) to
void SendMessageToDescendants(
UINT message,
WPARAM wParam = 0,
LPARAM lParam = 0,
BOOL bDeep = TRUE,
BOOL bOnlyPerm = FALSE
);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轮廓§ 2024-10-05 08:23:11

我假设您正在维护父窗口中子窗口的引用/指针列表,所以您不能简单地循环该列表,依次调用每个子窗口的 KeyDown 方法吗?

I'm assuming you're maintaining the list of references/pointers to child windows in the parent, so couldn't you simply loop through that list, calling the KeyDown method of each child window in turn?

森林迷了鹿 2024-10-05 08:23:11

我认为按键会转到具有输入焦点的窗口,因此如果所有窗口都可以获得焦点,则需要重新发送到其他窗口。我认为 PostMessage 是你最好的选择,而不需要更多地了解你在做什么。

更新:

每个视图如何区分来自用户的 WM_KEYDOWN 和转发到所有视图的假 WM_KEYDOWN?我认为您需要重新考虑您的解决方案 - 例如,在 WM_KEYDOWN 处,每个视图都会调用类似 MainFrame::FakeKeyDown() 的内容。然后,FakeKeyDown 为视图列表中的每个视图调用 View::OnFakeKeyDown(),然后您可以在视图中执行您需要执行的任何操作。

I think the key press goes to the window with the input focus, so if all the windows can have focus, you will need to resend to the other windows. I'm thinking PostMessage is your best bet here, without knowing a lot more about what you are doing.

UPDATE:

How will each View distinguish between a WM_KEYDOWN from the user, and the fake WM_KEYDOWN that is forwarded to all the Views? I'm thinking you need to re-think your solution - for instance, at WM_KEYDOWN, each View will call something like MainFrame::FakeKeyDown(). Then FakeKeyDown calls View::OnFakeKeyDown() for every view in your list of views, and you do whatever you need to do in the View.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文