I believe everyone has used WinAmp, which will be very surprised to her with the window with adsorption effect. In fact, it is not difficult to achieve such an effect. Here I use BCB to make such an effect. In order to simplify the problem, the window is only generated on the top of the screen.
Open BCB6.0, create a new project, change the properties of Form1's BorderStyle to BSnone, make a form without a title bar, borderless form. Under normal circumstances, we cannot move such a form. We must send a mobile message to the window, add the following code in the Form1 mousedown event:
Releasecapture ();
SendMessage (this-> Handle, WM_SYSCOMMAND, SC_MOVE HTCAPTION, 0);
In fact, the reason is very simple, I believe everyone will this, I don't say much, :)
In order to have a magnetic effect when the window is close to the top of the screen, we must make a judgment before the window movement, the top value of the new location to be reached is less than a certain range (this range I call it magnetic distance, the size can be I define myself, I will be 20 here for convenience. However, there is no form mobile event in BCB, we must intercept the form mobile message in the program, for this, we want to overrun the WndProc this function:
Void __fastcall tform1 :: WndProc (TMESSAGE & Message) {switch (message.msg) {/ * Before the window moves, the top value of the new position in the window is not in the magnetic range, if, let it return 0, indicating that Generate form movements to avoid moving windows in the magnetic range * / case wm_windowposchanging: if ((LPWindowPos (MSSAGE.LPARAM)) -> Y <20) -> y = 0; Break; default: Break;} TForm :: WndProc (Message); // If you handle the message, let the system do the rest of the thing} OK, the code is so much, is it very simple? Running a program, see if it is? :)
Maybe someone will ask why not intercept the message of WM_MOVE, in fact, as long as you try, if you intercept this message, the window will flash when moving within the magnetic range. The reason is very simple, wm_windowposchanging is a judgment before the window moves, and if the window will move within the magnetic range (this is not moving), the window will not allow the window to move. And WM_MOVE is judged after the window moves, so that the result is constantly reset to 0, of course, will cause the window to flash.
In addition, everyone knows that according to the settings of the system itself, the window has two display effects during the mobile, one is to display the dotted line box, one is the display window content. Careful friends may have discovered that in WinAmp, the window content will always be displayed in the process of moving WINAMP window regardless of the system settings. In fact, the reason is very simple, because when you show the dashed box, the adsorption effect of the magnetic window is not good, you can try it in person. How do you do it as WinAmp? In fact, as long as an API function is getting it, :), the code is as follows:
SystemParametersInfo (SPI_SETDRAGFULLWINDOWS, TRUE, NULL, SPIF_SENDCHANGE);
Before the window moves, by calling the above function, it can achieve the same effect as WINAMP. For the specific usage of the function and parameters of SystemParametersInfo, please see MSDN, no more clear than the MSDN explanation.
The above code is passed under Win2k Professional BCB6.0.
Call, finally finished, this is my first time, please advise, :)
Let the bricks have more violent!