Some famous shareware software not only has outstanding function, but also often leads a kind of fashion in the design skill of the program interface, Winamp is one of them. Winamp has two unique skills, one can replace the appearance of the form, which is now commonly known as the software to change the "skin", another is the magnetic form technique.
A magnetic form is a form where several forms stick together when they are close to a certain distance, or they are adsorbed together, and then the other forms that stick on them move together as you drag the main form. The domestic MP3 player rookie Cdok also achieved this technique, and more absolutely, after several forms stick together, the form does not have the master and slave, drag any one of the forms will make other forms move together. On the csdn on how to design a magnetic form of a lot of posts, that this technique won the favor of the vast number of programmers.
This article first of several netizens to analyze the method slightly, and then give me a more feasible way to implement and source code.
Implementing a magnetic form is basically a two-step process, and the first step is to implement a paste operation between forms when two forms are close to a certain distance, and the second step is to move the form while moving the other forms that are glued to it.
To implement a form's paste
The difficulty of implementing pasting is when you do this, assuming that there are two forms Form1 and Form2, moving Form2 to Form1, and pasting together when FORM2 is less recent than Form1. Obviously, it should be in the process of moving Form2 to judge, the question is where to insert the judgment code in the program?
Some people on csdn think that you can use timers to check the position of each form at a certain time. This method has obvious drawbacks, does not say that the timer to waste system resources needlessly, its immediacy alone is difficult to guarantee. If you shorten the time limit, the waste of CPU resources more, so I will not say more.
The reasonable way is to use the information generated by the system, but what message? When a form is moved, it generates wm_windowposchanging and wm_moving messages, and wm_windowposchanged and wm_move messages are generated when the move is completed. The parameters of the wm_windowposchanging and wm_windowposchanged messages lparam are pointers to the structure windowpos, Windowpos defined as follows: