简体   繁体   中英

Win32API How can my window follow to existing window

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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