Win32API 我的窗口如何跟随现有窗口

发布于 2024-10-08 08:24:50 字数 400 浏览 0 评论 0原文

致所有 Win32 专业人士。假设我们已经完成了带有 window 的现有应用程序。任务是用(我的)窗口编写另一个应用程序。当用户在屏幕上移动现有窗口时,我的窗口必须始终将其左边缘与现有窗口右边缘对齐(用户不允许移动我的窗口)。

前提条件: a) 现有窗口不能被子类化 b) Windows 挂钩不是一个案例。


是的,看起来不错。如果这不是一个问题,我不会问这个问题。忘了说操作系统是Vista 2,应用程序是IE。我尝试制作一个跟随 IE 主窗口的应用程序,将其边缘对齐。不允许 IE 子类化,并且 SetWindowsHook 在普通用户下无法正常工作(当用户具有管理员权限时应用程序可以正常工作)。你们所谈论的这种方式可以在 Vista 之前的 Windows 下运行。

看起来没有简单的方法可以解决这个任务。谢谢大家。

To all Win32 professionals. Let's say we have completed existing application with window. The task is to write another application with (my) window. My window must always align its left edge to existing window right edge while user moves existing window across the screen (my window not allowed to move by user).

Precondition: a) Existing window can not be subclassed b) Windows hooks are not a case.


Yes, looks right. I'd not asked this question if it not become a problem. Forgot to say that OS is Vista 2, application is IE. I try to make an application that follows IE main window, align it edge. Subclassing of IE not allowed, and SetWindowsHook not works correctly under regular user (when user have admin privileges application works normally). Such way as all of you talking about works under Windows prior to Vista.

And looks like there is no trivial way to solve this task. Thank you all.

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

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

发布评论

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

评论(2

冷月断魂刀 2024-10-15 08:24:50

我认为没有钩子就不行。 SetWindowLong 允许您设置 WndProc,但如果窗口属于不同的应用程序,则这将不起作用。

I think you can't without a hook. SetWindowLong allows you to set a WndProc, but this won't work if the window belongs to a different application.

乙白 2024-10-15 08:24:50

如果您不想/不能子类化或设置全局挂钩,您可以查看以下内容:

  • 在 DLL 中实现代码
  • 在 LoadLibrary 的地址和 DLL 的名称上调用 CreateRemoteThread 将 DLL 注入目标进程
  • 在 DLL 的 DllMain 中,您可以 SetWindowHook就在拥有该窗口的线程上。这是一个本地挂钩,不需要特殊权限,并且对系统非常好。
  • 在您的挂钩函数中,处理主窗口的 HWND 上的 WM_WINDOWPOSCHANGED 并相应地调整您的窗口。

If you dont want/cant subclass or set global hooks, you can look into the following:

  • Implement your code in a DLL
  • Call CreateRemoteThread on LoadLibrary's address and your DLL's name to inject your DLL into the target process
  • In the DLL's DllMain, you can SetWindowHook just on the thread that owns the window. This is a local hook and doesn't require special privileges and is very nice to the system.
  • In your hook function, process WM_WINDOWPOSCHANGED on the main window's HWND and adjust your window accordingly.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文