Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Controlling main window resizing/moving (Read 3764 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Controlling main window resizing/moving

So, I am trying to write my first plugin for foobar2000 - something that would snap the main window to the edge of the screen, when the window is, let's say, 10 pixels away from the edge.

I would like to get information about position and size of foobar2000's main window, whenever it is being moved or resized. I think this should work like processing WM_SIZING (or WM_MOVING) message in normal Win32 application, but I really don't know how to get this message in my plugin? (actually, I don't think it is possible that way)

Any hints on how could I get that sort of information?

PS. Oh, and many thanks to foosion for his 'Plugin development tutorial' - it made a lot of things really easier to understand!

Controlling main window resizing/moving

Reply #1
There are many ways of doing this.
I would do something like:

On startup, get the HWND of the main foobar window using core_api::get_main_window() and get the threadID of the main foobar thread using GetCurrentThreadId(). Install a hook to monitor the messages of the foobar thread using SetWindowsHookEx()  (and be careful, that can be dangerous).

You can then monitor when foobar moves, know it's new location and size, and then change just about anything with the window you want using the HWND you got.

Edit: Just wanted to say, this is pretty dirty  But I don't think that foobar exposes any cleaner methods.

Controlling main window resizing/moving

Reply #2
Thanks for your reply, it's very helpful!

But, may I ask, why do you call it 'dirty'? Is there any possibility that it could break stability of main application? Why this can be dangerous?

Controlling main window resizing/moving

Reply #3
Hooking main window events is not a part of documented API and is likely to break when more than one component does it, not to mention possible problems when user changes loaded UI module (which includes main window implementation) to something else. Components that do it will be added to offender list on first sight. Features you want to add should be implemented in UI module itself instead.
Microsoft Windows: We can't script here, this is bat country.