Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Docking using hWnd, is it possible?

6 views
Skip to first unread message

Matthe...@gmail.com

unread,
Feb 8, 2006, 10:37:33 PM2/8/06
to
Hello,

I am interested in creating a winamp like docking experience with my
program. I'm only interested in docking the main form to the edge of
the screen (not docking forms to each other, although that'd be nice).
I have posted before, but now I'm thinking that hWnd can be used
somehow:
http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/1a6101384e44a017/


Any input would be awesome. Or if someone knows of another method that
works, that'd be great too!


Thanks,

Matt

Veign

unread,
Feb 8, 2006, 11:56:29 PM2/8/06
to
Here is a drop-in class to provide that:
http://www.veign.com/vrc_codeview.asp?type=app&id=149

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


<Matthe...@gmail.com> wrote in message
news:1139456253.4...@o13g2000cwo.googlegroups.com...

Matthe...@gmail.com

unread,
Feb 9, 2006, 7:41:13 AM2/9/06
to
Thanks! I'll check it out.

Matthe...@gmail.com

unread,
Feb 9, 2006, 7:59:00 AM2/9/06
to
I'm not to familiar with using classes (i'm a beginner). Do you know
of any example code that uses this class? Or can you write up a quick
call?


Thanks a lot! I'm really excited as this is really simple;
cMagneticwnd always kept crashing on me.


Thanks,

Matt

Veign

unread,
Feb 9, 2006, 12:35:43 PM2/9/06
to
Download the newer version (there was something missing from the class) and
paste this code into a new form. I should add this works when the form is
dragged around by clicking on the client area of the form.

'-----------------------Start Code-----------------
Option Explicit

Dim oDock As cDockingHandler

Private Sub Form_Load()

Set oDock = New cDockingHandler
Set oDock.ParentForm = Me

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)

If Button = vbLeftButton Then
oDock.StartDockDrag X, Y
End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)

If Button = vbLeftButton Then
oDock.UpdateDockDrag X, Y
End If

End Sub

Private Sub Form_Unload(Cancel As Integer)
Set oDock = Nothing
End Sub
'-----------------------End Code-------------------------------

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


<Matthe...@gmail.com> wrote in message
news:1139489940.1...@z14g2000cwz.googlegroups.com...

Matthe...@gmail.com

unread,
Feb 9, 2006, 8:11:00 PM2/9/06
to
OH HELL YEA!

eh chem... sorry. That's exactly what I need. I'm not using a border
on the main form either so this is absolutely positively [insert
exaggerated positive emotional adjective here] p e r f e c t. I am
equally as grateful.


Is there a way to have this work with different windows, even if
they're not children?


Thanks!!!

Matt

Veign

unread,
Feb 9, 2006, 8:18:56 PM2/9/06
to
Please don't hold back and tell us how you really feel <bg>.

Different windows? Just include the code in the form and it will work with
any form in your project. is that what you mean?

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


<Matthe...@gmail.com> wrote in message
news:1139533860.1...@g47g2000cwa.googlegroups.com...

Veign

unread,
Feb 9, 2006, 8:25:39 PM2/9/06
to
To clear it up: Include the code within any form that you want to have that
effect..

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


"Veign" <NOSPAM...@veign.com> wrote in message
news:%23kHVQCe...@TK2MSFTNGP14.phx.gbl...

Matthe...@gmail.com

unread,
Feb 9, 2006, 8:44:25 PM2/9/06
to
Nice!

I was using the method that Randy stated on this post:
http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/1a6101384e44a017/


I'm actually interested in moving the form when a picturebox is clicked
and dragged currently here is code:


'global decs
Private Const HTCAPTION As Long = 2
Private Const WM_NCLBUTTONDOWN = &HA1

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X


As Single, Y As Single)

If Button = vbLeftButton Then

If CTRLClick = True Then

If (Shift And vbCtrlMask) = vbCtrlMask Then

ReleaseCapture
SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End If

ElseIf CTRLClick = False Then 'just a left-click, no keys

ReleaseCapture
SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End If

End If


End Sub


I tried to put oDock.UpdateDockDrag X, Y and oDock.StartDockDrag X, Y
in there and obviously it just wasn't working (since the
.updatedockdrag property would produce the original location only in
mousedown).


Thanks!

I'm seriously excited!

Matthe...@gmail.com

unread,
Feb 9, 2006, 9:49:35 PM2/9/06
to
Sorry... got a little giddy. I figured it out:

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)

If Button = vbLeftButton Then
If CTRLClick = True Then

If (Shift And vbCtrlMask) = vbCtrlMask Then

oDock.StartDockDrag X, Y
End If

ElseIf CTRLClick = False Then 'just a left-click, no keys

oDock.StartDockDrag X, Y
End If

End If


End Sub


Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X


As Single, Y As Single)
If Button = vbLeftButton Then
If CTRLClick = True Then

If (Shift And vbCtrlMask) = vbCtrlMask Then

oDock.UpdateDockDrag X, Y
End If

ElseIf CTRLClick = False Then 'just a left-click, no keys

oDock.UpdateDockDrag X, Y

Veign

unread,
Feb 9, 2006, 11:07:51 PM2/9/06
to
Looks like you got it all now...

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


<Matthe...@gmail.com> wrote in message
news:1139539775.7...@g14g2000cwa.googlegroups.com...

Matthe...@gmail.com

unread,
Feb 10, 2006, 6:58:24 AM2/10/06
to
Good Morning,

I got stuck last night, then figured i'd sleep on it.

How can I set the default pixels? Since it normally gets set in class
initialize, you really can't set it after the project has loaded
(right?).

I was attempting to set mSnapDistance (and convert it to twips) before
every function call, but that doesn't seem to work.
Any ideas?


Thanks,

Matt

Veign

unread,
Feb 10, 2006, 9:46:13 AM2/10/06
to
Class initialize occurs when the class is first instantiated. This is a
common location for setting default values of properties. As long as its
coded properly the value will be over-written when the user sets the
property at run-time.

All you had to do was change the value in the form load event. Add a line
after setting the ParentForm and set it to a value like:
700 * Screen.TwipsPerPixelX

(with such a large value you will see the change).

I uploaded a newer version so you won't have to convert to twips. You would
be able to pass a value in pixels to the SnapDistance property.

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


<Matthe...@gmail.com> wrote in message
news:1139572704.3...@g44g2000cwa.googlegroups.com...

Matthe...@gmail.com

unread,
Feb 10, 2006, 7:51:29 PM2/10/06
to
Thanks for all the help.

I set the DEFAULT_SNAP_DISTANCE as a public variable in a module.


Thanks again man, I'll be the first to say that this is the first
docking class i've seen that functions properly.

Are hope for docking windows to each other (like the winamp's eq,
playlist, etc.)?

Is there any serious documentation on the class anywhere?


Thanks,

Matt

Veign

unread,
Feb 10, 2006, 7:56:45 PM2/10/06
to
www.pscode.com has some code for magnetic forms. Actually there may even be
a sample at http://vb.mvps.org

Honestly if you play with the class a bit more you will find that it doesn't
really need any documentation.

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


<Matthe...@gmail.com> wrote in message
news:1139619089.1...@o13g2000cwo.googlegroups.com...

Matthe...@gmail.com

unread,
Feb 10, 2006, 10:52:19 PM2/10/06
to
I'll check it out.


Thanks for keeping with this post. I really appreciate it.


Take care,

Matt

0 new messages