关于在窗体上写字的问题

whupyf 武汉大学 2003-05-17 03:38:35
我想写一个类似外挂的小程序
在游戏窗体上写字,当怪物出现时给出信息。

我用的是drawtext 或 textout

我想在另一个窗体上(一个游戏)写字由于游戏不停刷新

文字看起来很闪
即使用timer控件最快的时间间隔写(1/1000秒)仍然非常闪烁啊.

可是我看见外挂在窗口上写的字却不闪啊。
...全文
50 点赞 收藏 18
写回复
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
qingming81 2003-05-20
killTimer 的API示例:
'In a module
Public Const DT_CENTER = &H1
Public Const DT_WORDBREAK = &H10
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Global Cnt As Long, sSave As String, sOld As String, Ret As String
Dim Tel As Long
Function GetPressedKey() As String
For Cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Ret = GetPressedKey
If Ret <> sOld Then
sOld = Ret
sSave = sSave + sOld
End If
End Sub

'In a form
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Me.Caption = "Key Spy"
'Create an API-timer
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Paint()
Dim R As RECT
Const mStr = "Start this project, go to another application, type something, switch back to this application and unload the form. If you unload the form, a messagebox with all the typed keys will be shown."
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Draw the text on the form
DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
'Show all the typed keys
MsgBox sSave
End Sub
回复
qingming81 2003-05-20
'Settimer 的API示例:
'In a module
Public Const DT_CENTER = &H1
Public Const DT_WORDBREAK = &H10
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Global Cnt As Long, sSave As String, sOld As String, Ret As String
Dim Tel As Long
Function GetPressedKey() As String
For Cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Ret = GetPressedKey
If Ret <> sOld Then
sOld = Ret
sSave = sSave + sOld
End If
End Sub

'In a form
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Me.Caption = "Key Spy"
'Create an API-timer
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Paint()
Dim R As RECT
Const mStr = "Start this project, go to another application, type something, switch back to this application and unload the form. If you unload the form, a messagebox with all the typed keys will be shown."
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Draw the text on the form
DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
'Show all the typed keys
MsgBox sSave
End Sub
回复
whupyf 2003-05-20
关键是怎样做啊.不怕麻烦.给个例子或说明过程,

最少给个思路也行啊
回复
Muzhu 2003-05-19
写字和画画一样需要双缓冲。
回复
lxcc 2003-05-19
timer控件不好用,试试settimer和killtimer API
回复
whupyf 2003-05-19
麻烦倒不怕.

主要是为了学习
回复
whupyf 2003-05-19
getwindowtext,和setwindowtext

我要写字.不是要改字.没有字能改.
回复
laomao01 2003-05-19
gz
回复
whupyf 2003-05-19
怎么没人回答啊?
回复
whupyf 2003-05-19
另外我看了一下settimer和killtimer功能和timer差不多,
我想问题还是在和游戏的同步问题上
回复
whupyf 2003-05-19
说详细点.或者随便什么例子也行..

我现在一头雾水啊
回复
lwl0614 2003-05-18
你可以试一下api函数getwindowtext,和setwindowtext
回复
xfyxq 2003-05-18
同意Intelement(桂子)的方案

最好的解决方法就是截获它的 WM_PAINT 消息
回复
rainstormmaster 2003-05-18
呵呵,你没有理解 Intelement(桂子) 的意思,再好好体会一下,不过实现起来比较困难。
回复
whupyf 2003-05-18
可是游戏的画面是不停在动的.
也就是不停的在刷啊.

如果不循环字只是一闪就没了啊
回复
Intelement 2003-05-17
--- 即使用timer控件最快的时间间隔写(1/1000秒)仍然非常闪烁啊.

不是不够快,而是你的程序和别的程序协调的不好

你应该在那个窗口自己画完内容后
你再根据在画完的内容的基础上描绘你自己的东西
回复
whupyf 2003-05-17
具体应该怎样做呢?

我没有头绪
回复
Intelement 2003-05-17
截获其他应用程序窗口 WM_PAINT 消息

当这个应用程序窗口处理 WM_PAINT 事件完毕后

再写上自己的处理代码
回复
发动态
发帖子
API
创建于2007-09-28

1455

社区成员

VB API
申请成为版主
社区公告
暂无公告