首页
社区
课程
招聘
编程有问:关于VB用findwindow
发表于: 2005-2-3 14:00 10062

编程有问:关于VB用findwindow

2005-2-3 14:00
10062
一般情况下,程序运行时程序的窗口名不变,但现在有些程序会因CPU使用率而变动.

VB,当程序的窗口名是个变量,从0%----100%动态变动时应怎样截获呢?

temp1=findwindow(vbnullstring,"程序的窗口名")

程序的窗口名由

software - 0%
<------------>
software - 100%
变动

thanks.

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (14)
雪    币: 300
活跃值: (412)
能力值: ( LV9,RANK:410 )
在线值:
发帖
回帖
粉丝
2
那就取相同的部分
2005-2-3 14:04
0
雪    币: 339
活跃值: (1510)
能力值: ( LV13,RANK:970 )
在线值:
发帖
回帖
粉丝
3
就按楼上说的

截获“software - * %”
2005-2-3 15:01
0
雪    币: 207
活跃值: (10)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
4
顺手检查类名好了
2005-2-3 15:09
0
雪    币: 208
活跃值: (376)
能力值: ( LV12,RANK:330 )
在线值:
发帖
回帖
粉丝
5
instr(窗口名,"software")>0
2005-2-3 15:11
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
不work............

class,类名是每次启动时变...........而窗口是在运行时以CPU占用率即时动态变..........

有无办法设定一变量是窗口名定在一个范围"software -0%"---------->"software -100%"             ?

或class.
thanks
2005-2-3 15:58
0
雪    币: 431
活跃值: (442)
能力值: ( LV12,RANK:530 )
在线值:
发帖
回帖
粉丝
7
你找窗口不久就是为了找他的进程ID吗?实在不行就枚举进程,找其进程名。
2005-2-4 12:24
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long

是用这几个吗?
但我怎样确定得那动态窗口的读写权限呢?

怎样用一个COMBOBOX和BUTTON为列,当COMBOBOX未选进程时按BUTTON出现"ERROR",当COMBOBOX选了进程时,并得到读写权限时,按BUTTON出现"OK",应怎写个列举当前活动的进程,并得到读写权限呢?请指教.

Form1.frm

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2
      Caption         =   "Command2"
      Height          =   495
      Left            =   2880
      TabIndex        =   2
      Top             =   1680
      Width           =   1215
   End
   Begin VB.ComboBox cmbProgram
      Height          =   315
      Left            =   1920
      TabIndex        =   1
      Text            =   "Combo1"
      Top             =   360
      Width           =   1695
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Left            =   1080
      TabIndex        =   0
      Top             =   1680
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private PIDs(1000) As Long
Private Sub RefreshProcessList()
Dim myProcess As PROCESSENTRY32
Dim mySnapshot As Long
cmbProgram.Clear
myProcess.dwSize = Len(myProcess)
mySnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
ProcessFirst mySnapshot, myProcess
cmbProgram.AddItem myProcess.szexeFile
PIDs(cmbProgram.ListCount - 1) = myProcess.th32ProcessID
While ProcessNext(mySnapshot, myProcess)
    cmbProgram.AddItem myProcess.szexeFile
    PIDs(cmbProgram.ListCount - 1) = myProcess.th32ProcessID
Wend
End Sub
Private Sub Command1_Click()
If pHandle > 0 Then
MsgBox "运行ing!", vbInformation, "OK"
Else
MsgBox "没有运行!", vbInformation, "警告"
End If
End Sub

Private Sub Command2_Click()
If InitProcess = True Then
    MsgBox "打开进程", vbCritical, "test"
Else
    MsgBox "不能打开进程", vbCritical, "test"
End If
End Sub
Private Sub Form_Load()
RefreshProcessList
End Sub

2005-2-4 20:20
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
Module1.bas

Attribute VB_Name = "Module1"
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Declare Function GetLastError Lib "kernel32" () As Long
Public Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public hProcess As Long

Type PROCESSENTRY32

    dwSize As Long

    cntUsage As Long

    th32ProcessID As Long

    th32DefaultHeapID As Long

    th32ModuleID As Long

    cntThreads As Long

    th32ParentProcessID As Long

    pcPriClassBase As Long

    dwFlags As Long

    szexeFile As String * 260

End Type
2005-2-4 22:08
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
Module2.bas

Attribute VB_Name = "Module2"
Public myHandle As Long
Function InitProcess() As Boolean
Dim pid As Long

hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (hProcess = 0) Then
  InitProcess = False
  myHandle = 0
Else
InitProcess = True
myHandle = hProcess
End If
End Function

一个COBOBOX,两个BUTTON

不能获取线程的读写权限,请帮帮忙,改写它使它能多所列线程有读写权限.......谢谢!
2005-2-4 22:11
0
雪    币: 431
活跃值: (442)
能力值: ( LV12,RANK:530 )
在线值:
发帖
回帖
粉丝
11
http://bbs.pediy.com/showthread.php?threadid=10522

打开进程并写内存的例子,搜索进程名为“games”的进程。我不太会VB,我想关于API的调用还是差不多的吧。
2005-2-5 11:31
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
char *szName="game.exe";//目标进程名
if((strncmp(strlwr(info->szExeFile), strlwr(szName), strlen(szName)) == 0)||(strncmp(strlwr(info->szExeFile), strlwr(OBJ_path), strlen(OBJ_path)) == 0))
{
PID=info->th32ProcessID;
//打开游戏进程
hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,PID);

VC方面受教了,thanks,但

在VB里该怎样查找了?有谁知到在VB里怎样查找进程EXE并打开读写权限呢?
2005-2-5 14:01
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
解决了窗口.............和这的问题了.现在有问,怎样单独列CLASSNAME呢?THANKS

搞定.................
2005-2-6 17:50
0
雪    币: 431
活跃值: (442)
能力值: ( LV12,RANK:530 )
在线值:
发帖
回帖
粉丝
14
如果在游戏已经运行的情况下不好打开他的进程的话,可以用自己的程序加载这个目标进程。

资料:
1。
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo; //This is an [in] parameter
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
if(CreateProcess("c:\\winnt\\notepad.exe", NULL,
    NULL,NULL,FALSE,0,NULL,
    NULL,&StartupInfo,&ProcessInfo))
{
    WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
}  
else
{
    MessageBox("The process could not be started...");
}

2。
ShellExecuteEx(&StartupInfo)
3。
ReadProcessMemory(StartupInfo.hProcess……)

VB实在不会,抱歉。
2005-2-6 22:33
0
雪    币: 194
活跃值: (25)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
15
晕咯,
用for循环100次嘛,生成一个字串,找到了就break
2005-2-7 07:49
0
游客
登录 | 注册 方可回帖
返回
//