Solutions to some problems encountered in vb6 borderless form development

In order to beautify or customize the form, the form is usually made into a borderless form. There will be some problems in using the borderless form. Taking VB as an example, when the form borderstyle is set to 0, the following problems will occur: 1 .The program icon no longer appears on the taskbar 2. The form cannot be dragged and moved 3. The form cannot be dragged and scaled . This article provides solutions to these problems.


Question one:

Problem description: The taskbar does not display the program icon

Problem analysis: This problem is because vb6 automatically changes the showintask attribute to false when the form borderstyle is set to 0.

Solution: Change the showintask attribute to true in the properties panel.


Question two:

Problem description: The form cannot be moved by dragging it

Solution: There are two solutions to this problem

Option 1: Native implementation

In the form_mousemove event, when the left button is pressed and dragged, the form automatically moves the X and Y of the mouse. The specific code is as follows

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then Me.Move Me.Left + X + 45, Me.Top + Y + 45
End Sub

If you fail to follow this method, you can refer to the API implementation of Plan 2.

'''声明API'''
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 Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ReleaseCapture
    SendMessage Me.hWnd, &HA1, 2, 0& 
End Sub

Question three:

Problem description: The form cannot be moved by dragging it

solution:

'''API声明'''
private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags 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_THICKFRAME = &H40000
private Const SWP_NOMOVE = &H2 '不移动窗体
private Const SWP_NOSIZE = &H1 '不改变窗体尺寸
private Const SWP_DRAWFRAME = &H20
private Const SWP_NOZORDER = &H4



Sub form_load()
    hwnd=me.hwnd
    dwStyle = GetWindowLong(hwnd, GWL_STYLE)
    If SetTrue Then dwStyle = dwStyle Or WS_THICKFRAME 
    dwStyle = SetWindowLong(hwnd, GWL_STYLE, dwStyle)
    SetWindowPos hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
End Sub

This method draws a border to the form through the Windows API.


  Developed by Fuzhou Mechanical and Electrical Engineering Vocational and Technical School wh

Email contact information: [email protected]

QQ contact information: 2151335401, 3135144152

Guess you like

Origin blog.csdn.net/m0_60277871/article/details/129109747