VB无输入焦点窗体 拖动时卡顿,如何解决?
【要求】窗体无输入焦点(也就是运行时不会影响其他窗口的输入焦点);拖动窗体时不要出现下面代码中的卡顿现象。希望能求到正确的代码,谢谢!下面是代码:OptionExplic...
【要求】
窗体无输入焦点(也就是运行时不会影响其他窗口的输入焦点);
拖动窗体时不要出现下面代码中的卡顿现象。
希望能求到正确的代码,谢谢!
下面是代码:
Option Explicit
' 转移输入焦点的声明
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
' 禁止本窗体拥有输入焦点的常数
Private Const HWND_NOTOPMOST = -2
Private Const WS_DISABLED = &H8000000
Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)
'禁止拥有输入焦点
Private Sub Form_Load()
SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_DISABLED Or GetWindowLong(Me.hwnd, GWL_EXSTYLE)
End Sub
生成可执行文件之后,运行程序会卡。 展开
窗体无输入焦点(也就是运行时不会影响其他窗口的输入焦点);
拖动窗体时不要出现下面代码中的卡顿现象。
希望能求到正确的代码,谢谢!
下面是代码:
Option Explicit
' 转移输入焦点的声明
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
' 禁止本窗体拥有输入焦点的常数
Private Const HWND_NOTOPMOST = -2
Private Const WS_DISABLED = &H8000000
Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)
'禁止拥有输入焦点
Private Sub Form_Load()
SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_DISABLED Or GetWindowLong(Me.hwnd, GWL_EXSTYLE)
End Sub
生成可执行文件之后,运行程序会卡。 展开
展开全部
只能做成无标题栏的然后利用 mouse_move事件:
Option Explicit
Private hwnd_Avtive As Long '前台窗口句柄变量
'移动窗体声明
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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'转换前台窗口声明
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
'窗体无焦点风格常数
Private Const WS_DISABLED = &H8000000
Private Const GWL_EXSTYLE = (-20)
'移动窗体常数
Private Const WM_SYSCOMMAND = &H112 '查下
Private Const SC_MDIMOVE = &HF012& '?网上的这个为什么是这个数SC_MOVE = &HF012; API浏览器上为什么又是这个数Public Const SC_MOVE = &HF010&?
'载入时设为无焦点
Private Sub Form_Load()
SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_DISABLED '? 为什么要用EXSTYLE
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
hwnd_Avtive = GetForegroundWindow '获取前台窗口句柄
SetForegroundWindow Me.hwnd '激活本窗体
ReleaseCapture '移动窗体(MousePointer = 0--鼠标形状缺省)
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MDIMOVE, 0
SetForegroundWindow hwnd_Avtive '重新激活前台窗口
End Sub
Option Explicit
Private hwnd_Avtive As Long '前台窗口句柄变量
'移动窗体声明
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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'转换前台窗口声明
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
'窗体无焦点风格常数
Private Const WS_DISABLED = &H8000000
Private Const GWL_EXSTYLE = (-20)
'移动窗体常数
Private Const WM_SYSCOMMAND = &H112 '查下
Private Const SC_MDIMOVE = &HF012& '?网上的这个为什么是这个数SC_MOVE = &HF012; API浏览器上为什么又是这个数Public Const SC_MOVE = &HF010&?
'载入时设为无焦点
Private Sub Form_Load()
SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_DISABLED '? 为什么要用EXSTYLE
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
hwnd_Avtive = GetForegroundWindow '获取前台窗口句柄
SetForegroundWindow Me.hwnd '激活本窗体
ReleaseCapture '移动窗体(MousePointer = 0--鼠标形状缺省)
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MDIMOVE, 0
SetForegroundWindow hwnd_Avtive '重新激活前台窗口
End Sub
展开全部
VB最大的缺点就是运行速度慢,在程序功能等价下,VB程序确实比C/C++慢许多,但是。。。
由于现在的计算机配置都比较高,这些差距还是不算什么的 !
如果感觉长期运行速度慢,可能是您的计算机的配置太低,建议对内存做些优化!
由于现在的计算机配置都比较高,这些差距还是不算什么的 !
如果感觉长期运行速度慢,可能是您的计算机的配置太低,建议对内存做些优化!
追问
晕了,希望你能够运行一下再回答,问题出在那个API上,和你说的无关的...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
实在没有看到你说的卡顿现象
一切正常~ 能具体说说现象吗?
一切正常~ 能具体说说现象吗?
追问
你好! 生成可执行文件之后,运行程序,在打开多个窗口的情况下,拖动窗体。
能拖动,但是拖动过程中窗体不跟随鼠标移动,就是我说的卡顿...
太难描述了...
追答
我用VB生产了你的程序 还真没理解了你和所的卡顿是什么样子
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询