再标准模块里写一段程序,如下:
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const WS_EX_TOPMOST = &H8&
Private Const GWL_EXSTYLE = (-20)
public TopMostWnd as long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
ret=GetWindowLong(hwnd,GWL_EXSTYLE )
if ret and WS_EX_TOPMOST <>0 THEN
'说明枚举出来的窗体是置顶窗体
topmostwnd=hwnd
'停止枚举
EnumWindowsProc=false
end if
'继续枚举
EnumWindowsProc = True
End Function
在窗体的Load里写如下程序
sub Form_Load()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
end sub
在窗体里定义变量,API声明
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
dim topDC as long
在窗体上放一个Timer,在OnTimer事件里写如下代码
if topmostwnd <>0 then
topDC=getdc(topmostwnd)
if topdc=0 then
msgbox "获取顶级窗口DC失败!"
timer1.enable=false
else
drawadtext topdc
end if
end if
定义写文字的程序
private sub DrawAdText(byval hDC as long)
dim memdc as long
dim bmp as long
memdc=CreateCompatibleDC(GetDc(0))
bmp=CreateCompatibleBitmap(GetDC(0),......
deleteobject selectobject(memdc,bmp)
setbkmode transparent
'定位写字,具体你自己去研究
TextOut memdc,坐标,文字..........
deleteobject bmp
deletedc memdc
end sub