Option Explicit Private Const SWP_NOMOVE = 2 Private Const SWP_NOSIZE = 1 Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2Private 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 Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long If Topmost = True Then 'Make the window topmost SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS) Else SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS) SetTopMostWindow = False End If End FunctionPrivate Sub Form_Load() Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2, 5000, 5000 SetTopMostWindow Me.hwnd, True Label1.Move 0, 0, Me.Width - 100, Me.Height - 100 'Label1.AutoSize = False Open "c:\1.txt" For Input As #1 Dim s As String s = StrConv(InputB(LOF(1), 1), vbUnicode) Label1.Caption = s End Sub
Option Explicit
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2Private 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 Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
If Topmost = True Then 'Make the window topmost
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
SetTopMostWindow = False
End If
End FunctionPrivate Sub Form_Load()
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2, 5000, 5000
SetTopMostWindow Me.hwnd, True
Label1.Move 0, 0, Me.Width - 100, Me.Height - 100
'Label1.AutoSize = False
Open "c:\1.txt" For Input As #1
Dim s As String
s = StrConv(InputB(LOF(1), 1), vbUnicode)
Label1.Caption = s
End Sub
-------------------
VB6 不太熟,能给出找句柄的相关代码吗? 谢谢SetForegroundWindow
--------------------------
用这个的话,光标是否还能切换到别的应用界面上,但是不影响文本的前置?