[RESOLVED] Conflict between borderless form manual resize and borderless form drag and move code
In the notes app I am currently developing, I have a borderless form with manual resize code and manual 'drag and move' code.
The problem is that these two conflict with each other and I can't do both of them. I can either let the form be resizable or either moveable. If you try to resize it, it doesn't work. If I remove a couple of lines of code, will work only one of the functions as I said. I attached the sample file with both functions. I tried so many times to get around the problem,nothing worked. If you'd be so kind to help me with this one, I'd really appreciate it.
Thanks in advance. Kevin
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Re: Conflict between borderless form manual resize and borderless form drag and move
See if this will work for you instead. Just use a standard form and drop the code in.
Code:
Option Explicit
'API Calls Used To Remove The Title Bar From Window (Make A Sizeable Borderless Form)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_DLGFRAME = &H400000
'API Calls Used To Move A Form With The Mouse
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 Sub Form_Load()
'ERASE the Title Bar
SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + &H400000
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Move the form with the Left Mouse Button
If Button = vbLeftButton Then
Me.MousePointer = vbSizeAll
Call ReleaseCapture
Call SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
Me.MousePointer = vbArrow
End If
End Sub
Re: Conflict between borderless form manual resize and borderless form drag and move
Similar effect using different constants:
Code:
Option Explicit
Private Const GWL_STYLE As Long = (-16&)
Private Const WS_CAPTION As Long = &HC00000
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongW" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongW" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const HTCAPTION As Long = 2
Private Const SC_MOVE As Long = &HF010&
Private Const SC_DRAGMOVE As Long = (SC_MOVE + HTCAPTION)
Private Const WM_SYSCOMMAND As Long = &H112
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub ReleaseCapture Lib "user32.dll" ()
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then Unload Me
End Sub
Private Sub Form_Load()
KeyPreview = True
SetWindowLong hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) And Not WS_CAPTION
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
MousePointer = vbSizeAll
ReleaseCapture
SendMessage hWnd, WM_SYSCOMMAND, SC_DRAGMOVE, 0&
MousePointer = vbDefault
End If
End Sub
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Re: Conflict between borderless form manual resize and borderless form drag and move
Code above works great. But if you want to do without API calls here try this
First at design time, not run time, Set your Form ControlBox = False then simply put this in your form code
Code:
Option Explicit
Private LeftMouseDown As Boolean
Private StartX As Integer
Private StartY As Integer
Private Sub Form_Load()
Me.Caption = ""
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
LeftMouseDown = True
StartX = X
StartY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If LeftMouseDown Then Me.Move Me.Left + (X - StartX), Me.Top + (Y - StartY)
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
LeftMouseDown = False
End Sub