Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2427|回复: 9

[已解决]请教各位高手,如何利用代码来限制窗体关闭功能呢?

[复制链接]
发表于 2010-3-26 12:22 | 显示全部楼层 |阅读模式

请教各位高手,如何利用代码来限制窗体自带的关闭功能呢?谢谢!

 

请教各位高手,如何利用代码来限制窗体关闭功能呢?

请教各位高手,如何利用代码来限制窗体关闭功能呢?

最佳答案
2010-3-26 12:56

简化一下楼上的代码

Private Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Sub UserForm_Initialize()
    SetWindowLong FindWindow(vbNullString, Me.Caption), -16, &H6C10000
End Sub

发表于 2010-3-26 12:29 | 显示全部楼层

我曾经见过怎样使窗体的关闭按钮不可用。貌似要用到复杂的API函数

回复

使用道具 举报

 楼主| 发表于 2010-3-26 12:30 | 显示全部楼层
回复

使用道具 举报

发表于 2010-3-26 12:30 | 显示全部楼层

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = 1
End Sub
回复

使用道具 举报

 楼主| 发表于 2010-3-26 12:34 | 显示全部楼层

谢谢蝶.舞,真的能实现。请问又如何设置让那个按钮变成灰色的呢或者说不显示这个按钮?
[此贴子已经被作者于2010-3-26 12:41:35编辑过]
回复

使用道具 举报

发表于 2010-3-26 12:46 | 显示全部楼层

Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION As Long = &HC00000

Private Sub UserForm_Initialize()
    Dim hwnd
    Dim rng As Range
    If Val(Application.Version) < 9 Then
        hwnd = FindWindow("ThunderXFrame", Me.Caption)
    Else
        hwnd = FindWindow("ThunderDFrame", Me.Caption)
    End If
    SetWindowLong hwnd, GWL_STYLE, iStyle
    DrawMenuBar hwnd
End Sub

回复

使用道具 举报

发表于 2010-3-26 12:56 | 显示全部楼层    本楼为最佳答案   

简化一下楼上的代码

Private Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Sub UserForm_Initialize()
    SetWindowLong FindWindow(vbNullString, Me.Caption), -16, &H6C10000
End Sub

回复

使用道具 举报

 楼主| 发表于 2010-3-26 12:57 | 显示全部楼层

蝶.舞,谢谢,好像不行哟,只是取消“关闭”这个按钮,其他的不变。
回复

使用道具 举报

 楼主| 发表于 2010-3-26 13:00 | 显示全部楼层

就是amulee老师这个效果,谢谢!
回复

使用道具 举报

发表于 2010-3-26 13:02 | 显示全部楼层

学习学习。。。看的晕晕乎乎的~~~~~~~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-16 13:31 , Processed in 0.307549 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表