Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function GetForegroundWindow Lib "user32" () As Long '可以通过查看前景窗口是否为指定窗口判断 hwd1 = FindWindow("#32770", "QQ用户登录") '获得指定窗口句柄 hwd2 = GetForegroundWindow'获得前森洞景窗口句柄 If hwd1 = hwd2 Then MsgBox "指定窗口为活动状态!"'判断是否相同'可以通过ModifyMenu修改系统菜单来禁止移动,但并不适用所有窗体,有的窗体不具有系统菜单(BorderStyle=0) '但通过子类化仍可以实现系统菜单具有的功能,新建窗体,添加command1,复制粘贴下段代码 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) 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 SC_MOVE = &HF010& Private Const MF_BYCOMMAND = &H0& Private Const MF_ENABLED = &H0& Private Const MF_GRAYED = &H1& Private Sub Command1_Click() hwind = FindWindow("#32770", "QQ用户登录") '获取窗体句柄 hMenu = GetSystemMenu(hwind, False)'获取该窗体系统菜单句柄 ModifyMenu hMenu, SC_MOVE, MF_BYCOMMAND Or MF_GRAYED, -10, "禁止移动"'设置移动菜单项不可用,并指定新ID为小于0的-10以防止系统重迅游新加载该菜单,新标题为“禁止移动”,成功返回非0,失败0 'ModifyMenu hMenu, -10, MF_BYCOMMAND + MF_ENABLED, SC_MOVE, "移动(&M)" '恢复移动菜单 SendMessage hwind, WM_NCACTIVATE, True, 0 '发送WM_NCACTIVE消息此昌枯到指定窗体刷新非客户区(标题栏) End Sub
相关文章
-
vb6.0视频教程(好的+100分)
2023-04-28 04:19 阅读(612) -
VB.NET中e.Cancel是什么意思
2023-04-20 08:10 阅读(588) -
vb 中 select case 是什么意思?
2023-04-19 09:18 阅读(588)
1 vb100表示的意思是什么?
633 阅读
2 VB如何链接数据库SQL
580 阅读
3 vb中cls是什么意思
607 阅读
4 VB 计算阶乘
632 阅读
5 VB中的FLAG是什么意思啊?
588 阅读