子程序

今天看到个获取刺激战场的真实进程的代码,彻底看到了子程序的优势。并自己尝试写了个简单的子程序例子

tim 20180618162521 tim 20180618162529

tim 20180618162541

6\19 我对子程序进行了拓展,写了一个自动获取hprocess的子程序并且可以直接调用,方便我以后写游戏辅助

#include<stdio.h>
#include<Windows.h>


int GethProcess(char *tittle){
HWND jubing; //窗口句柄 
DWORD pid; // 进程 
HANDLE hProcess0;

	jubing=FindWindowA(NULL,tittle);
	if (jubing==0){
	printf("获取hProcess失败\n");
	

}
	else{
		GetWindowThreadProcessId(jubing,&pid);
        hProcess0=OpenProcess(PROCESS_ALL_ACCESS,0,pid);
		return hProcess0;
		
		
	}
}
int main(){
	HANDLE hProcess;
	hProcess = GethProcess("植物大战僵尸中文版");
	printf("%d\n",hProcess);
	system("pause");
}