调用api Private Const SWP_NOOWNERZORDER = &H200 Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER Private Const HWND_TOP = 0 Private Const HWND_BOTTOM = 1 Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -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 '窗口置前置后 Public Function SetWindowsBack(hwnd As Long) SetWindowPos hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End Function Public Function SetWindowsFont(hwnd As Long) SetWindowPos hwnd, -2, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End Function
新建一个工程,在窗体上放一个按钮控件。 贴入下面的代码:Option ExplicitPrivate 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 LongPrivate Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _ (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, _ ByVal fuWinIni As Long) As Long
Private CanExit As BooleanPrivate Sub Command1_Click() CanExit = True Unload Me End SubPrivate Sub Form_Load() SetWindowPos Me.hwnd, -1&, 0&, 0&, 0&, 0&, 3& '使窗体在最上层。SystemParametersInfo 97&, 1&, "1", 0& '屏蔽Alt+Ctr+Del End SubPrivate Sub Form_LostFocus() '使程序始终有焦点 Me.SetFocus End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If CanExit = False Then '只允许通过单击Command1来关闭程序。这样可以防止其它程序通过发送消息的方式来关闭本窗体。 Cancel = 1 End If End Sub
对不起,前面的程序忘了在程序结束时恢复Alt+Ctr+Del。改后的如下:Option ExplicitPrivate 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 LongPrivate Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _ (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, _ ByVal fuWinIni As Long) As Long
Private CanExit As BooleanPrivate Sub Command1_Click() CanExit = True Unload Me End SubPrivate Sub Form_Load() SetWindowPos Me.hwnd, -1&, 0&, 0&, 0&, 0&, 3& '使窗体在最上层。SystemParametersInfo 97&, 1&, "1", 0& '屏蔽Alt+Ctr+Del End SubPrivate Sub Form_LostFocus() '使程序始终有焦点 Me.SetFocus End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If CanExit = False Then '只允许通过单击Command1来关闭程序。这样可以防止其它程序通过发送消息的方式来关闭本窗体。 Cancel = 1 Else SystemParametersInfo 97&, 1&, "1", 0& '取消屏蔽Alt+Ctr+Del End If End Sub
windowstate设为2用SetWindosPos将该窗口放在最上层。用SystemParametersInfo屏蔽掉Ctr+Alt+Del (在NT、2000中无效)
windowstate设为2用SetWindowPos将该窗口放在最上层。 '前面这里写错了。用SystemParametersInfo屏蔽掉Ctr+Alt+Del (在NT、2000中无效)
怎样把窗体用SetWindowPos将该窗口放在最前面和
用SystemParametersInfo屏蔽掉Ctr+Alt+Del
代码怎样写??
谢了.
Private Const SWP_NOOWNERZORDER = &H200
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -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
'窗口置前置后
Public Function SetWindowsBack(hwnd As Long)
SetWindowPos hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Function
Public Function SetWindowsFont(hwnd As Long)
SetWindowPos hwnd, -2, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Function
贴入下面的代码:Option ExplicitPrivate 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 LongPrivate Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Private CanExit As BooleanPrivate Sub Command1_Click()
CanExit = True
Unload Me
End SubPrivate Sub Form_Load()
SetWindowPos Me.hwnd, -1&, 0&, 0&, 0&, 0&, 3& '使窗体在最上层。SystemParametersInfo 97&, 1&, "1", 0& '屏蔽Alt+Ctr+Del
End SubPrivate Sub Form_LostFocus()
'使程序始终有焦点
Me.SetFocus
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If CanExit = False Then '只允许通过单击Command1来关闭程序。这样可以防止其它程序通过发送消息的方式来关闭本窗体。
Cancel = 1
End If
End Sub
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Private CanExit As BooleanPrivate Sub Command1_Click()
CanExit = True
Unload Me
End SubPrivate Sub Form_Load()
SetWindowPos Me.hwnd, -1&, 0&, 0&, 0&, 0&, 3& '使窗体在最上层。SystemParametersInfo 97&, 1&, "1", 0& '屏蔽Alt+Ctr+Del
End SubPrivate Sub Form_LostFocus()
'使程序始终有焦点
Me.SetFocus
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If CanExit = False Then '只允许通过单击Command1来关闭程序。这样可以防止其它程序通过发送消息的方式来关闭本窗体。
Cancel = 1
Else
SystemParametersInfo 97&, 1&, "1", 0& '取消屏蔽Alt+Ctr+Del
End If
End Sub