Solved

How to drag a object like , but the object must move with the mouse. Like a form

Posted on 1998-12-17
5
154 Views
Last Modified: 2010-05-03
I want to drag ,by example, a button. And when I move my mouse, the button must move directly, like a form.

How?

0
Comment
Question by:graat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:graat
ID: 1450960
Edited text of question
0
 

Accepted Solution

by:
DPickering earned 70 total points
ID: 1450961
Create a new VB Project, add a command button to it, then paste the following code to the form...

Cheers,
Dave

<CODE STARTS HERE>

Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1

Private Const WM_SYSCOMMAND = &H112

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ReleaseCapture
    SendMessage Command1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
       
    ' Or use:
    'SendMessage Command1.hwnd, WM_SYSCOMMAND, &HF012&, 0&
End Sub

0
 

Author Comment

by:graat
ID: 1450962
If i want to drag the button, the message "sub or function not defined" pops up.

He thinks releasecapture doesn't excists. How can I solve this problem?

0
 

Expert Comment

by:DPickering
ID: 1450963
Who thinks ReleaseCapture doesn't exist? It does exist and should work as long as you're not using VB3 or VB4-16 bit. In that case you'll need to use the API browser to get the 16-bit declaration for it. It also requires Windows 95 or later or Windows NT 3.1 or later.

Also, why do you want the user to click a Command Button and have it move around the screen? Not exactly Windows standards. Regardless of that however, this works with any control, even a form. All controls and forms are simply Window objects (anything which has a hWnd property is a Window) and any Window object can be used for this example. You could for example have the same code in the Form_MouseDown event to move the form around without having to click on the title bar. ReleaseCapture needs to be called otherwise this whole thing won't work.

I've used this on Windows 95, 98 and Windows NT 4 and it works. Open a new project and then open the Code Pane for Form1. Then delete whatever code is in the Form (maybe Option Explicit or the Form_Load event) and then paste the code I supplied (after <CODE STARTS HERE>) into the Code Pane. Compile it and if this still doesn't work goto http://www.desertware.com/vbuniverse/moveform.html for the same example - just to show you that's the way its done.

Dave
0
 

Author Comment

by:graat
ID: 1450964
Fantastic,
THANX

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question