关于在窗体上写字的问题

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

我用的是drawtext 或 textout

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

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

可是我看见外挂在窗口上写的字却不闪啊。
...全文
92 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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
  • 打赏
  • 举报
回复
说详细点.或者随便什么例子也行..

我现在一头雾水啊
闲谈李 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 事件完毕后

再写上自己的处理代码

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧