Important alert: (current site time 7/16/2013 2:49:24 AM EDT)
 

winzip icon

cMagneticWnd 1.0.8 (WinAmp's *behaviour* fully emulated)

Email
Submitted on: 11/4/2004 1:24:38 PM
By: Carles P.V. 
Level: Intermediate
User Rating: By 55 Users
Compatibility: VB 6.0
Views: 23535
 
     This little class provides basic window 'magnetic docking' (like WinAmp). Glueing is also supported. Simply, use AddWindow() method specifying handle of new window and its parent, if any. __________________________________________________ Based on original post by Benjamin Wilger. Thanks again to Paul Caton for the 'self-subclassing' template (IDE-safe). __________________________________________________ Update #1. Improved: hereditary glueing is now supported. __________________________________________________ Update #2. Improved: removed 'RemoveWindow()' method. Now, class processes WM_DESTROY message and automaticaly removes window. __________________________________________________ Update #3. Fixed: incorrect checking of 'hereditary glueing'. I hope it's working fine now! Sorry. __________________________________________________ Update #4 (last?): now, WinAmp's *behaviour* is fully emulated (I hope!). Hereditary magnetism, as well as glueing, is working for ALL child (connected) windows. __________________________________________________ Update #5. Never say final update: added CheckGlueing() method. Call in case repositioning manually a window and want to enable/check (glue) again, if any. This was only checked for first time when a new window was added to the collection. __________________________________________________ Update #6: Back to manual window destroying (problems on W9x). __________________________________________________ Update #7: Special cases: 1) Added processing of WM_SYSCOMMAND and WM_COMMAND messages. Thanks to LaVolpe for suggesting solution 2) Maximized windows (edge offset out of screen area).
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 53 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
11/4/2004 3:11:51 PMGandolf_The_GUI

A little more detail in the description would be nice.
(If this comment was disrespectful, please report it.)

 
11/4/2004 3:13:22 PMGandolf_The_GUI

Despite the description, this code is very well done. Works just like winamp.
(If this comment was disrespectful, please report it.)

 
11/4/2004 3:24:54 PMPhantom Man

Excellent Carles.
Works A Treat!

Gary
(If this comment was disrespectful, please report it.)

 
11/4/2004 3:34:56 PMquak

deserve my 5 globes
(If this comment was disrespectful, please report it.)

 
11/4/2004 3:41:19 PMCarles P.V.

OK, thank you :-)

Playing now with WinAmp, I think that 'glueing' should be hereditary... I will try to change this.
(If this comment was disrespectful, please report it.)

 
11/4/2004 3:51:33 PMPaul Caton

Rats, now I'll *have* to update the self-subclass submission (sat here with heavy cold) - I'm tempted to give you four stars for making me work :¬)

Excellent as ever!
(If this comment was disrespectful, please report it.)

 
11/4/2004 4:05:31 PMCarles P.V.

Oops! Sorry Paul, but your work has become an irresistible new tool :-)

Thanks!
(If this comment was disrespectful, please report it.)

 
11/4/2004 4:07:38 PMPaul Caton

I should say though that it took me a while to figure out what I was supposed to do here. Perhaps you could update the description a little.
(If this comment was disrespectful, please report it.)

 
11/4/2004 4:16:43 PMCarles P.V.

Yes. But, my poor English, and taking in account I already would have problems to explain 'what this class does' in my language...
(If this comment was disrespectful, please report it.)

 
11/4/2004 4:19:10 PMjeremyxtz

You should use DeferWindowPos when you move multiple windows.
(If this comment was disrespectful, please report it.)

 
11/4/2004 4:46:56 PMLight Templer

Works great! A fine tool, Carles.
Thx for and my ***** .
LiTe
(If this comment was disrespectful, please report it.)

 
11/4/2004 5:04:26 PMCarles P.V.

Thanks, Lite :-)
(If this comment was disrespectful, please report it.)

 
11/4/2004 6:41:03 PMMaverick

Wks great accept child forms can only connect to the main. For instance...like winamp you can connect and move eq and playlist.
(If this comment was disrespectful, please report it.)

 
11/5/2004 12:26:17 AMUnruled Boy

oops, u realy shooting new direction.
(If this comment was disrespectful, please report it.)

 
11/5/2004 12:30:13 AMUnruled Boy

if child can also attach & glue to another child, that will be fantastic. and the reaction seems to be not quite agile. maybe the distance between parent/child will be doubled before they are magnetic.
(If this comment was disrespectful, please report it.)

 
11/5/2004 5:19:27 AMCarles P.V.

Ok. Working now on 'hereditary magnetism'... Regarding to snap distance, you can change it (default is 10 pixels).
(If this comment was disrespectful, please report it.)

 
11/5/2004 9:01:32 AM

wow! another fine submission by the perfectionist programmer Carles! now if only he would reply to my emails :(

You are building up an amazing collection of controls and program's with your work here Carles, infact i use most of the control's now instead of the actual VB standard ones.

I always love downloading and studying your code!

5 Stars (as always) :)
(If this comment was disrespectful, please report it.)

 
11/5/2004 12:04:52 PM

wonderful and new direction shooting as said by someone here. thanks for sharing with us another nice piece.
(If this comment was disrespectful, please report it.)

 
11/5/2004 10:23:30 PMHeriberto Mantilla Santamaría

Carles you're the best of the best.

Te estado siguiendo los pasos y considero que eres de los mejores programadores que encontrado en esta exigente web junto con el amigo fred, felicidades Carles y mis reverencias al mejor de todos.
(If this comment was disrespectful, please report it.)

 
11/6/2004 9:00:21 AMMaverick

Thanx for the fix You got 5 globes from me.
(If this comment was disrespectful, please report it.)

 
11/6/2004 11:16:39 PMPaul Turcksin

Great, great, great.
(If this comment was disrespectful, please report it.)

 
11/7/2004 6:50:05 PMDiablo

Hi Carles,
I given you 5 globes for what
you have coded so far.

another revision ?
would be to:
when the main form loads on screen,
then you select to load child it
snaps to the main - so not to drag'n
snap. also,
once the child has snapped to the
main form, then it has been dragged
away, it automatically snaps back to the
main form, so to look magnetic.
Just a suggestion!
GT...
(If this comment was disrespectful, please report it.)

 
11/7/2004 6:58:55 PM

to overcome the "flickering" (Refresh) issue when moving skinned form's or windows it's advisable to override the WM_BACKGROUNDPAINT (or something) messages to provide smooth window movement with minimal flicker. This is what winamp does to avoid this issue...
(If this comment was disrespectful, please report it.)

 
11/8/2004 3:35:25 PMAvi

Great! Thanks! 5G
(If this comment was disrespectful, please report it.)

 
11/12/2004 10:57:00 AMGandolf_The_GUI

Charles - Lets say I have a form, and when I load the 2nd form, I want it to be positioned so the to forms are already touching, and magnetised to eachother. The positioning is no problem, but the 2nd form doesnt seem to magnatise unless you give it focus first.. which I dont want to do. Any suggestions (on how to invoke the magentise function).
(If this comment was disrespectful, please report it.)

 
11/12/2004 11:39:03 AMCarles P.V.

Ok, I suppose it's not the first time you manually set position of that form, so 'glueing' is not checked. Well, simply create a new public method, let's say, CheckGlueing(), and add next call to the private one: pvCheckGlueing(). I'll update zip adding this new method. Thanks for info :-)
(If this comment was disrespectful, please report it.)

 
11/13/2004 11:04:59 AMenmity

What will be your next work-of-art? any new direction? :)
(If this comment was disrespectful, please report it.)

 
11/15/2004 4:18:05 AMEric O''Sullivan

nice job. I have to say though that I re-arranged your code quite a bit. The class is now event driven rather then encapsulating all the code within the class, the class extends the event system of the vb forms to increase their functionality. Somewhat more re-usable. I love the machine code hack, but what exactly is it doing? The best guess I can come up with is getting the pointers to certain parts of the program but I'm not quite sure how you achieved this?
(If this comment was disrespectful, please report it.)

 
11/15/2004 5:23:31 AMCarles P.V.

Eric: Hi. Yes, this class is quite simple (interface). User is free to extend it by adding events or custom methods. Since this class is *sub-classing* windows, you can profit from this by processing new messages, and raising corresponding events. For example, passing window handle for each event, a unique routine could be used to control all windows.


*Machine code hack*: this excellent part of code is the work of Paul Caton, and sincerely, this is out of my scope :-) It was initialy designed for *IDE-safe-self-subclassing* usercontrols, that is, no extra modules.
(If this comment was disrespectful, please report it.)

 
11/17/2004 3:51:32 AMpao_francis

This is a cool class! nice work! 5 globes for me. :-)



(If this comment was disrespectful, please report it.)

 
11/23/2004 8:58:54 PMenmity

non win9x, auto, win9x, manual?
(If this comment was disrespectful, please report it.)

 
11/24/2004 7:49:48 AMCarles P.V.

Yes, and don't ask me why. Crash at time to stop subclassing for currently destroyed window in WM_DESTROY (before) message.
(If this comment was disrespectful, please report it.)

 
11/27/2004 1:21:12 PMChris Cochran

Very nice Carles, as usual. This will certainly come in handy.
(If this comment was disrespectful, please report it.)

 
11/28/2004 8:43:58 AMFunny Dog

Awesome Mr Carles.
All The Bells And Whistles For You.

Well 5 Balls Anyway.


(If this comment was disrespectful, please report it.)

 
5/7/2005 2:04:06 PMAly Hirani

The only Screen Docking code that actually works great, 5 stars. However I really do think that the nearest max value should be increased. I mean the range that after when should it glue itself to the screen (dock)... If u understand what I mean, then please consider over it.
(If this comment was disrespectful, please report it.)

 
5/7/2005 2:35:03 PMCarles P.V.

SnapWidth property.
(If this comment was disrespectful, please report it.)

 
5/11/2005 12:23:14 PM

Carles P.V. - further to your comment elsewhere (webbrowser control) I think you're too humble. This code is certainly of an advanced level, and is extremely good IMHO.

Many thanks, I use this code very often!

Vijay
(If this comment was disrespectful, please report it.)

 
2/27/2006 4:26:11 PMGINO

Well, i'm from spain and i added this code to the class:

'Declarations section
Private m_ptMOUSE As POINTAPI

'zSubclass_Proc sub
'this capture the mouse coords at any moment the mouse hit the non-client area of a window
Case WM_NCMOUSEMOVE
GetCursorPos m_ptMOUSE

'
Case WM_ENTERSIZEMOVE

...

If (m_uWndInfo(lc).hWnd = lng_hWnd) Then
'-- Get anchor-offset
Call GetCursorPos(m_ptAnchor)
'Call GetCursorPos(m_ptLast)
'Change the method to capture mouse coords when WM_ENTERSIZEMOVE is sended
m_ptLast.x1 = m_ptMOUSE.x1
m_ptLast.y1 = m_ptMOUSE.y1

m_ptOffset.x1 = m_rcWnd(lc).x1 - m_ptLast.x1
m_ptOffset.y1 = m_rcWnd(lc).y1 - m_ptLast.y1
End If

...

This makes the enter-move coords the real ones
(If this comment was disrespectful, please report it.)

 
5/12/2006 6:41:54 AMReiner S.

First..! This is a realy great Source Code. good work :-)
if i try project with borderless form
the docking functinon dosent´t work course borderless forms sends no WM_SYSCOMMAND - Messages ore other Messages. I tryed to send this messages with API-> SendMessage Me.hwnd, WM_MOVING, 0, 0 and the borderless Form become locate but the dock event dosent respond.
(If this comment was disrespectful, please report it.)

 
5/12/2006 9:39:18 PMReiner S.

OK... I have found the solution.
Borderless Forms can only detected if you use follow Sample Text in The Form:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
'Info :
Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const WM_SYSCOMMAND = &H112
(If this comment was disrespectful, please report it.)

 
6/15/2006 4:06:42 PMdjinks

Very nice sample program. Can this be used to dock the form to another window, for example notepad.exe? I have tried that without success. I changed the form_load sub to submit the target app's handle:
Call oMagneticWnd.AddWindow(hWndNotePad)

.., but that did not work. What else should be changed?
(If this comment was disrespectful, please report it.)

 
12/25/2006 10:28:49 PMTom Weber

YESSSSS!!!
(If this comment was disrespectful, please report it.)

 
12/25/2006 10:32:42 PMTom Weber

Sorry, I need to say so more:
It was the first time in many years when I was about to say: "Wow, magic!"
I have some forms glued together, and they were moving as a group. I really forgot to think: Nah, it's only code! :-)

(If this comment was disrespectful, please report it.)

 
7/1/2008 5:47:00 AMalvinwong

Great! I rated 5.
It's actually usefull, and I think I'll use it in my programs.
(It's also fun to fill the screen with different sizes of windows and move the main window)
Thanks for sharing!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.