在DLL中写入如下代码,目的是实现一个最简单的窗口顶置功能
Private Declare Function SetWindowPos Lib "user32.dll" (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
Private Const HWND_TOPMOST As Long = -1
Private Const SWP_NOSIZE As Long = &H1
Public Sub Sleep()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE
End Sub
完成后编译生成DLL,在主程序中调用的代码如下:
Private Sub Command1_Click()
Dim Mycom As Class1
Set Mycom = New Class1
mydog.Sleep
Set Mycom = Nothing
End Sub
结果提示错误..可能是因为窗体的名柄方面的问题.请问,要如何才能实现这个功能呢?谢谢!
Private Declare Function SetWindowPos Lib "user32.dll" (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
Private Const HWND_TOPMOST As Long = -1
Private Const SWP_NOSIZE As Long = &H1
Public Sub Sleep()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE
End Sub
完成后编译生成DLL,在主程序中调用的代码如下:
Private Sub Command1_Click()
Dim Mycom As Class1
Set Mycom = New Class1
mydog.Sleep
Set Mycom = Nothing
End Sub
结果提示错误..可能是因为窗体的名柄方面的问题.请问,要如何才能实现这个功能呢?谢谢!
Private Sub Command1_Click()
Dim Mycom As Class1
Set Mycom = New Class1
Mycom.Sleep
Set Mycom = Nothing
End Sub
结果提示"要求对象"
应该是这个FORM1不能代表当前窗口的句柄,请问应该用什么来表示调用者的窗口句柄呢?多谢
在DLL 中并不知道你调用的窗口句柄.应该写成这样才对.
Public Sub Sleep(hwnd as long)
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE
End Sub
'然后在代码中调用方法为
Private Sub Command1_Click()
Dim Mycom As Class1
Set Mycom = New Class1
Mycom.Sleep(me.hwnd)
Set Mycom = Nothing
End Sub