🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Win32 Window Question

Started by
4 comments, last by DividedByZero 4 years, 1 month ago

Hi Guys,

Is there a way you can send all messages from a focused child window to the parent window?

I have a scenario where I don't have access to the parent windows callback function and only have the window handle (because of a somewhat locked out 3rd party API). The parent handle is in charge of any input etc. But if my child window is in focus no input is detected. So ideally, I'd like any windows messages the client receives be duplicated to the parent.

As a side question, is it possible to get a pointer to the parent windows callback given HWND alone?

Any advice on this would be awesome.

Thanks in advance.

Advertisement

SendMessage WINAPI function is your friend. You can post the messages to certain windows message queue by simply passing it's HWND to it

Also there are many functions in winapi for that ex: HWND GetActiveWindow();

Is your “child” actually a full sized overlay like in Steam or such?

SendMessage or PostMessage can be used to send messages to other windows, including the parent window.

In general you don't want to send all events to a parent, for example size events, paint events, etc. would probably cause trouble.

Also in the general case mouse events would cause issues, you would need to adjust the parameters as they are client coordinates, and in the general case, a child and parents client area is not the same.

For mouse events, if I recall for plain Win32 the general solution is to handle WM_NCHITTEST and return HTTRANSPARENT , for keyboard, I am not sure why you would take focus if you didn't want it.

DividedByZero said:
As a side question, is it possible to get a pointer to the parent windows callback given HWND alone?

Yes, the window procedure is stored as `GWLP_WNDPROC`. If you want to “override” a windows procedure, use `SetWindowLongPtr` to set it to a new value, the previous one will be returned (note, I believe not guaranteed to be a callable function pointer). If you just want to get it but not change, `GetWindowLongPtr`. You can then call it with `CallWindowProc`.

This is one of the ways to “subclass” a window to add additional functionality.

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-callwindowproca

Usually, all windows with the same class share one window procedure. A subclass is a window or set of windows with the same class whose messages are intercepted and processed by another window procedure (or procedures) before being passed to the window procedure of the class.

The other way to subclass windows is using `SetWindowSubclass`, which has some advantages, such as handling an extra DWORD_PTR sized data value which you can use for any purpose (e.g a pointer to your own class/struct), and calling the old window procedure properly using `DefSubclassProc` (you would otherwise need to store that old GWLP_WNDPROC value somewhere yourself!).

https://docs.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-setwindowsubclass​

_WeirdCat_ said:

Also there are many functions in winapi for that ex: HWND GetActiveWindow();

Yes, but in this case the primary window is hidden, so it will never be active, unless you set it to be active programmatically.

@syncviews might be on to something there though.

Thanks guys ?

This topic is closed to new replies.

Advertisement