关键词搜索

源码搜索 ×
×

关于vb6无边框的窗体开发遇到的部分问题的解决方案

发布2023-02-19浏览699次

详情内容

 

为了美化或自定义窗体,通常会把窗体做成无边框形式,使用无边框窗体会存在一些问题的,以vb为例,当窗体borderstyle设置为0时,会出现以下问题:1.任务栏不再出现程序图标   2.窗体无法拖行移动  3.窗体无法拖动缩放,此文针对这些问题给出解决方案


问题一:

问题描述: 任务栏不显示程序图标

问题分析:此问题是因为vb6在窗体borderstyle设置为0时,会自动将showintask属性改为false

解决方案:在属性面板将showintask属性改为true即可

 


问题二:

问题描述:窗体无法拖动实现移动

解决方案:此问题解决方案有两种

方案1:原生实现

在form_mousemove事件下,当按下左键并拖动时,窗体自行进行+鼠标移动的X和Y,具体代码如下

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

用此方法如果出现不跟手的情况,可以参考方案2的api实现

  1. '''声明API'''
  2. private Declare Function ReleaseCapture Lib "user32" () As Long
  3. 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
  4. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  5. ReleaseCapture
  6. SendMessage Me.hWnd, &HA1, 2, 0&
  7. End Sub

问题三:

问题描述:窗体无法拖动实现移动

解决方案:

  1. '''API声明'''
  2. 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
  3. private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  4. '''常量声明'''
  5. private Const GWL_STYLE = (-16)
  6. private Const WS_THICKFRAME = &H40000
  7. private Const SWP_NOMOVE = &H2 '不移动窗体
  8. private Const SWP_NOSIZE = &H1 '不改变窗体尺寸
  9. private Const SWP_DRAWFRAME = &H20
  10. private Const SWP_NOZORDER = &H4
  11. Sub form_load()
  12. hwnd=me.hwnd
  13. dwStyle = GetWindowLong(hwnd, GWL_STYLE)
  14. If SetTrue Then dwStyle = dwStyle Or WS_THICKFRAME
  15. dwStyle = SetWindowLong(hwnd, GWL_STYLE, dwStyle)
  16. SetWindowPos hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  17. End Sub

此方法是通过windows的api给form画一个边框

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载