简体   繁体   English

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

[英]Win32API How can my window follow to existing window

To all Win32 professionals. 致所有Win32专业人士。 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. 前提:a)现有窗口不能被子类化b)Windows钩子不属于这种情况。


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. 忘了说OS是Vista 2,应用是IE。 I try to make an application that follows IE main window, align it edge. 我尝试制作一个遵循IE主窗口的应用程序,将其边缘对齐。 Subclassing of IE not allowed, and SetWindowsHook not works correctly under regular user (when user have admin privileges application works normally). 不允许IE的子类化,并且SetWindowsHook在普通用户下不能正常工作(当用户具有管理员权限时,应用程序可以正常工作)。 Such way as all of you talking about works under Windows prior to Vista. 大家谈论的这种方式在Vista之前的Windows下都可以使用。

And looks like there is no trivial way to solve this task. 并且看起来没有简单的方法可以解决此任务。 Thank you all. 谢谢你们。

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. SetWindowLong允许您设置WndProc,但是如果窗口属于其他应用程序,则此方法将无效。

If you dont want/cant subclass or set global hooks, you can look into the following: 如果您不想/不能子类或设置全局挂钩,则可以查看以下内容:

  • Implement your code in a DLL 在DLL中实现代码
  • Call CreateRemoteThread on LoadLibrary's address and your DLL's name to inject your DLL into the target process 在LoadLibrary的地址和DLL的名称上调用CreateRemoteThread,以将DLL注入目标进程
  • In the DLL's DllMain, you can SetWindowHook just on the thread that owns the window. 在DLL的DllMain中,您可以仅在拥有窗口的线程上使用SetWindowHook。 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. 在挂钩函数中,在主窗口的HWND上处理WM_WINDOWPOSCHANGED并相应地调整窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM