'原理是不处理窗体的WM_NCACTIVATE消息,可以参考下面的的例子把下面的内容复制到记事本保存为Form1.frmVERSION 5.00
Begin VB.Form Form1
BackColor = &H00FFFFFF&
Caption = "Form1"
ClientHeight = 1440
ClientLeft = 60
ClientTop = 345
ClientWidth = 4305
LinkTopic = "Form1"
ScaleHeight = 1440
ScaleWidth = 4305
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "显示"
Height = 375
Left = 1440
TabIndex = 1
Top = 600
Width = 1455
End
Begin VB.PictureBox Picture1
AutoRedraw = -1 'True
Height = 2055
Left = 240
ScaleHeight = 133
ScaleMode = 3 'Pixel
ScaleWidth = 117
TabIndex = 0
Top = 1920
Visible = 0 'False
Width = 1815
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate Sub Form_Load()
m_Hwnd = Me.hwnd
End SubPrivate Sub Command1_Click()
Dim rc As RECT
Call Hook
GetWindowRect Command1.hwnd, rc
SetWindowLong Picture1.hwnd, GWL_STYLE, WS_POPUP Or WS_BORDER Or WS_THICKFRAME
SetWindowLong Picture1.hwnd, GWL_EXSTYLE, WS_EX_TOPMOST Or WS_EX_TOOLWINDOW
SetParent Picture1.hwnd, 0
Picture1.Move (rc.Right + 2) * Screen.TwipsPerPixelX, rc.Top * Screen.TwipsPerPixelY, Picture1.Width, Picture1.Height
Call Picture1_KeyDown(189, 0)
Picture1.Visible = True
Call SetCapture(Picture1.hwnd)
Picture1.SetFocus
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Visible = False
Call ReleaseCapture
Call Unhook
End Sub
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim rc As RECT
Dim i As Integer
Picture1.Cls
rc.Left = 1
rc.Top = 20
rc.Right = Picture1.ScaleWidth - 1
rc.Bottom = Picture1.ScaleHeight - 1
DrawEdge Picture1.hdc, rc, BDR_SUNKENOUTER, BF_RECT
Picture1.CurrentY = 22
If KeyCode = 187 Then '"+"
For i = 1 To 9
Picture1.CurrentX = 5
Picture1.Print i & " " & String(i, "A")
Next i
Else
For i = 1 To 9
Picture1.CurrentX = 5
Picture1.Print i & " " & String(i, "B")
Next i
End If
Picture1.Refresh
End Sub
Begin VB.Form Form1
BackColor = &H00FFFFFF&
Caption = "Form1"
ClientHeight = 1440
ClientLeft = 60
ClientTop = 345
ClientWidth = 4305
LinkTopic = "Form1"
ScaleHeight = 1440
ScaleWidth = 4305
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "显示"
Height = 375
Left = 1440
TabIndex = 1
Top = 600
Width = 1455
End
Begin VB.PictureBox Picture1
AutoRedraw = -1 'True
Height = 2055
Left = 240
ScaleHeight = 133
ScaleMode = 3 'Pixel
ScaleWidth = 117
TabIndex = 0
Top = 1920
Visible = 0 'False
Width = 1815
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate Sub Form_Load()
m_Hwnd = Me.hwnd
End SubPrivate Sub Command1_Click()
Dim rc As RECT
Call Hook
GetWindowRect Command1.hwnd, rc
SetWindowLong Picture1.hwnd, GWL_STYLE, WS_POPUP Or WS_BORDER Or WS_THICKFRAME
SetWindowLong Picture1.hwnd, GWL_EXSTYLE, WS_EX_TOPMOST Or WS_EX_TOOLWINDOW
SetParent Picture1.hwnd, 0
Picture1.Move (rc.Right + 2) * Screen.TwipsPerPixelX, rc.Top * Screen.TwipsPerPixelY, Picture1.Width, Picture1.Height
Call Picture1_KeyDown(189, 0)
Picture1.Visible = True
Call SetCapture(Picture1.hwnd)
Picture1.SetFocus
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Visible = False
Call ReleaseCapture
Call Unhook
End Sub
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim rc As RECT
Dim i As Integer
Picture1.Cls
rc.Left = 1
rc.Top = 20
rc.Right = Picture1.ScaleWidth - 1
rc.Bottom = Picture1.ScaleHeight - 1
DrawEdge Picture1.hdc, rc, BDR_SUNKENOUTER, BF_RECT
Picture1.CurrentY = 22
If KeyCode = 187 Then '"+"
For i = 1 To 9
Picture1.CurrentX = 5
Picture1.Print i & " " & String(i, "A")
Next i
Else
For i = 1 To 9
Picture1.CurrentX = 5
Picture1.Print i & " " & String(i, "B")
Next i
End If
Picture1.Refresh
End Sub
Option ExplicitPublic Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function DrawEdge Lib "user32" (ByVal hdc As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As LongPublic Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePublic Type POINTAPI
X As Long
Y As Long
End TypePublic Const GWL_EXSTYLE = (-20)
Public Const GWL_STYLE = (-16)
Public Const GWL_HWNDPARENT = (-8)
Public Const GWL_WNDPROC = (-4)Public Const WS_THICKFRAME = &H40000
Public Const WS_VISIBLE = &H10000000
Public Const WS_POPUP = &H80000000
Public Const WS_BORDER = &H800000Public Const WS_EX_TOPMOST = &H8
Public Const WS_EX_TOOLWINDOW = &H80Public Const WM_NCACTIVATE = &H86
Public Const WM_ACTIVATEAPP = &H1CPublic Const BF_TOP = &H2
Public Const BF_LEFT = &H1
Public Const BF_RIGHT = &H4
Public Const BF_BOTTOM = &H8
Public Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)Public Const BDR_RAISEDINNER = &H4
Public Const BDR_RAISEDOUTER = &H1
Public Const BDR_SUNKENINNER = &H8
Public Const BDR_SUNKENOUTER = &H2
Public Const BDR_SUNKEN = &HA
Public Const BDR_RAISED = &H5Public m_Hwnd As Long
Public m_Hook As Boolean
Private m_PrevWndProc As LongPublic Sub Hook()
If Not m_Hook Then
m_PrevWndProc = SetWindowLong(m_Hwnd, GWL_WNDPROC, AddressOf WindowProc)
m_Hook = True
End If
End SubPublic Sub Unhook()
If m_Hook Then
Call SetWindowLong(m_Hwnd, GWL_WNDPROC, m_PrevWndProc)
m_Hook = False
End If
End SubPrivate Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_NCACTIVATE
WindowProc = CallWindowProc(m_PrevWndProc, hw, uMsg, 1, lParam)
Case Else
WindowProc = CallWindowProc(m_PrevWndProc, hw, uMsg, wParam, lParam)
End Select
End Function
Thank you very very very very much!!!!!!!!!!!!!!
Thank you very very much!