首页 C#利用句柄操作窗口

C#利用句柄操作窗口

举报
开通vip

C#利用句柄操作窗口C#HYPERLINK写个类操作窗口(句柄操作)实现过程:过程一:找到当前鼠标位置的句柄您的使用2个WinAPI(俺喜欢自己封装下来用):ViewCode[DllImport("user32.dll",EntryPoint="GetCursorPos")]publicstaticexternboolGetCursorPos(outPointpt);[DllImport("user32.dll",EntryPoint="WindowFromPoint")]publicstaticexternIntPtrWind...

C#利用句柄操作窗口
C#HYPERLINK写个类操作窗口(句柄操作)实现过程:过程一:找到当前鼠标位置的句柄您的使用2个WinAPI(俺喜欢自己封装下来用):ViewCode[DllImport("user32.dll",EntryPoint="GetCursorPos")]publicstaticexternboolGetCursorPos(outPointpt);[DllImport("user32.dll",EntryPoint="WindowFromPoint")]publicstaticexternIntPtrWindowFromPoint(Pointpt);//鼠标位置的坐标publicstaticPointGetCursorPosPoint(){Pointp=newPoint();if(GetCursorPos(outp)){returnp;}returndefault(Point);}//////找到句柄//////坐标///publicstaticIntPtrGetHandle(Pointp){returnWindowFromPoint(p);}过程二:改变窗口的Text您的使用1个WinAPI:ViewCode[DllImport("user32.dll",EntryPoint="SendMessage")]privatestaticexternintSendMessage(IntPtrhWnd,intMsg,IntPtrwParam,stringlParam);//////给窗口发送内容//////句柄///要发送的内容publicstaticvoidSetText(IntPtrhWnd,stringlParam){SendMessage(hWnd,WM_SETTEXT,IntPtr.Zero,lParam);}privateconstintWM_SETTEXT=0x000C;通过这个方法就能改变Text的值了。思考:如果俺把这个窗口的句柄记录下来,下次不用鼠标获取,直接就能改变值不蛮好的嘛。例如:我有个桌面系统老叫我输入用户名,密码。我记录用户名和密码的窗口句柄,然后改变他们的输入值,这样多省事。(只是举例,不考虑安全性)问题:你会告诉我,窗口句柄的每次重建会变的呀,咋办。回答:类名不变呀。过程三:您的准备一些工具吧,例如:句柄找类名呀,类名找句柄什么的等等,下面会用到一些WinAPIViewCode[DllImport("user32.dll",EntryPoint="FindWindow")]privatestaticexternIntPtrFindWindow(stringIpClassName,stringIpWindowName);[DllImport("user32.dll",EntryPoint="FindWindowEx")]privatestaticexternIntPtrFindWindowEx(IntPtrhwndParent,IntPtrhwndChildAfter,stringlpszClass,stringlpszWindow);[DllImport("user32.dll",EntryPoint="GetParent")]publicstaticexternIntPtrGetParent(IntPtrhWnd);[DllImport("user32.dll",CharSet=CharSet.Auto)]publicstaticexternintGetClassName(IntPtrhWnd,StringBuilderlpClassName,intnMaxCount);//////找到句柄//////类名///publicstaticIntPtrGetHandle(stringIpClassName){returnFindWindow(IpClassName,null);}//////子窗口句柄//////父窗口句柄///前一个同目录级同名窗口句柄///类名///publicstaticIntPtrGetChildHandle(IntPtrhwndParent,IntPtrhwndChildAfter,stringlpszClass){returnFindWindowEx(hwndParent,hwndChildAfter,lpszClass,null);}//////全部子窗口句柄//////父窗口句柄///类名///publicstaticListGetChildHandles(IntPtrhwndParent,stringclassName){ListresultList=newList();for(IntPtrhwndClient=GetChildHandle(hwndParent,IntPtr.Zero,className);hwndClient!=IntPtr.Zero;hwndClient=GetChildHandle(hwndParent,hwndClient,className)){resultList.Add(hwndClient);}returnresultList;}//////找类名//////句柄///publicstaticstringGetClassName(IntPtrhWnd){StringBuilderlpClassName=newStringBuilder(128);if(GetClassName(hWnd,lpClassName,lpClassName.Capacity)==0){thrownewException("notfoundIntPtr!");}returnlpClassName.ToString();}思考:遍历桌面上所有的窗口,然后找类名,然后改他的Text,扯淡嘛,相同的类名太多了,找毛呀。实现:不仅记录类名,而且记录类名在父窗口出现的位置,然后通过桌面一层层找下来,最后找到这个句柄。(虽然不是太准,但是一般的还是能解决了,如果你有什么好方式一起研究)。过程四:实现一个WinHWND的类,可以把他的规则,他的父窗口类名,以及在父窗口中同类名出现的顺序记录下来,然后通过这些记录的信息还原句柄。ViewCodepublicclassWinHWND{publicIntPtrHWND{get;set;}publicstringClassName{get;set;}publicWinHWNDParent{get;set;}publicintInParentSequence{get;set;}privateWinHWND(){}publicWinHWND(IntPtrhWnd){this.HWND=hWnd;this.ClassName=GetClassName();this.Parent=GetParent();this.InParentSequence=GetInParentSequence();}privatestringGetClassName(){returnWinAPI.GetClassName(this.HWND);}privateWinHWNDGetParent(){if(WinAPI.GetParent(this.HWND)==null){thrownewException("notfoundIntPtr!");}if(WinAPI.GetParent(this.HWND)==IntPtr.Zero){returnnull;}returnnewWinHWND(WinAPI.GetParent(this.HWND));}privateintGetInParentSequence(){IntPtrIntprtParent=this.Parent==null?IntPtr.Zero:this.Parent.HWND;returnWinAPI.GetChildHandles(IntprtParent,this.ClassName).IndexOf(this.HWND);}publicoverridestringToString(){StringBuilderresult=newStringBuilder();for(WinHWNDwinHandle=this;winHandle!=null;winHandle=winHandle.Parent){result.Append(string.Format("{0}:{1};",Escape(winHandle.ClassName),winHandle.InParentSequence.ToString()));if(winHandle.InParentSequence==-1)break;}returnresult.ToString().TrimEnd(';');}privatestaticstringGetBaseMark(stringsMark){string[]sMarks=sMark.Split(';');returnsMarks[sMarks.Length-1].Split(':')[0];}privatestaticstring[]GetChildMarks(stringsMark){string[]sMarks=sMark.Split(';');string[]sChildMarks=newstring[sMarks.Length-1];for(inti=0;ibaseHwnds=WinAPI.GetChildHandles(IntPtr.Zero,GetBaseMark(sMark));string[]sChildMarks=GetChildMarks(sMark);//由于主窗口在桌面出现所以很可能同名,所以要看看他的儿子和孙子...是不是都匹配foreach(IntPtrbaseHwndinbaseHwnds){IntPtrhandle=baseHwnd;for(inti=sChildMarks.Length-1;i>=0;i--){string[]sChildMark=sChildMarks[i].Split(':');try{handle=WinAPI.GetChildHandles(handle,UnEscape(sChildMark[0]))[int.Parse(sChildMark[1])];}catch{break;}if(i==0)returnnewWinHWND(handle);}continue;}returnnull;}#region转义privatestaticstringEscape(stringarg){returnarg.Replace(":","\\:").Replace(";","\\;");}privatestaticstringUnEscape(stringarg){returnarg.Replace("\\:",":").Replace("\\;",";");}#endregionpublicstaticWinHWNDGetWinHWND(){returnnewWinHWND(WinAPI.GetHandle(WinAPI.GetCursorPosPoint()));}}上全部代码,里面加了窗口的部分属性,扩展其他的属性,自己发挥吧,就是搞WinAPIViewCodeusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Runtime.InteropServices;usingSystem.Drawing;usingSystem.Collections;namespaceInformationCollectionDataFill{publicclassWinAPI{#regionWinodwsAPI[DllImport("user32.dll",EntryPoint="FindWindow")]privatestaticexternIntPtrFindWindow(stringIpClassName,stringIpWindowName);[DllImport("user32.dll",EntryPoint="FindWindowEx")]privatestaticexternIntPtrFindWindowEx(IntPtrhwndParent,IntPtrhwndChildAfter,stringlpszClass,stringlpszWindow);[DllImport("user32.dll",EntryPoint="SendMessage")]privatestaticexternintSendMessage(IntPtrhWnd,intMsg,IntPtrwParam,stringlParam);[DllImport("user32.dll",EntryPoint="GetParent")]publicstaticexternIntPtrGetParent(IntPtrhWnd);[DllImport("user32.dll",EntryPoint="GetCursorPos")]publicstaticexternboolGetCursorPos(outPointpt);[DllImport("user32.dll",EntryPoint="WindowFromPoint",CharSet=CharSet.Auto,ExactSpelling=true)]publicstaticexternIntPtrWindowFromPoint(Pointpt);[DllImport("user32.dll",CharSet=CharSet.Auto)]publicstaticexternintGetClassName(IntPtrhWnd,StringBuilderlpClassName,intnMaxCount);[DllImport("user32.dll",CharSet=CharSet.Auto)]publicstaticexternintGetWindowText(IntPtrhWnd,[Out,MarshalAs(UnmanagedType.LPTStr)]StringBuilderlpString,intnMaxCount);[DllImport("user32.dll",CharSet=CharSet.Auto)]publicstaticexternintGetWindowRect(IntPtrhwnd,refRectanglerc);[DllImport("user32.dll",CharSet=CharSet.Auto)]publicstaticexternintGetClientRect(IntPtrhwnd,refRectanglerc);[DllImport("user32.dll",CharSet=CharSet.Auto)]publicstaticexternintMoveWindow(IntPtrhwnd,intx,inty,intnWidth,intnHeight,boolbRepaint);[DllImport("user32.dll",CharSet=CharSet.Auto,SetLastError=true,ExactSpelling=true)]publicstaticexternintScreenToClient(IntPtrhWnd,refRectanglerect);#endregion#region封装API方法//////找到句柄//////类名///publicstaticIntPtrGetHandle(stringIpClassName){returnFindWindow(IpClassName,null);}//////找到句柄//////坐标///publicstaticIntPtrGetHandle(Pointp){returnWindowFromPoint(p);}//鼠标位置的坐标publicstaticPointGetCursorPosPoint(){Pointp=newPoint();if(GetCursorPos(outp)){returnp;}returndefault(Point);}//////子窗口句柄//////父窗口句柄///前一个同目录级同名窗口句柄///类名///publicstaticIntPtrGetChildHandle(IntPtrhwndParent,IntPtrhwndChildAfter,stringlpszClass){returnFindWindowEx(hwndParent,hwndChildAfter,lpszClass,null);}//////全部子窗口句柄//////父窗口句柄///类名///publicstaticListGetChildHandles(IntPtrhwndParent,stringclassName){ListresultList=newList();for(IntPtrhwndClient=GetChildHandle(hwndParent,IntPtr.Zero,className);hwndClient!=IntPtr.Zero;hwndClient=GetChildHandle(hwndParent,hwndClient,className)){resultList.Add(hwndClient);}returnresultList;}//////给窗口发送内容//////句柄///要发送的内容publicstaticvoidSetText(IntPtrhWnd,stringlParam){SendMessage(hWnd,WM_SETTEXT,IntPtr.Zero,lParam);}privateconstintWM_SETTEXT=0x000C;//////获得窗口内容或标题//////句柄///publicstaticstringGetText(IntPtrhWnd){StringBuilderresult=newStringBuilder(128);GetWindowText(hWnd,result,result.Capacity);returnresult.ToString();}//////找类名//////句柄///publicstaticstringGetClassName(IntPtrhWnd){StringBuilderlpClassName=newStringBuilder(128);if(GetClassName(hWnd,lpClassName,lpClassName.Capacity)==0){thrownewException("notfoundIntPtr!");}returnlpClassName.ToString();}//////窗口在屏幕位置//////句柄///publicstaticRectangleGetWindowRect(IntPtrhWnd){Rectangleresult=default(Rectangle);GetWindowRect(hWnd,refresult);returnresult;}//////窗口相对屏幕位置转换成父窗口位置////////////publicstaticRectangleScreenToClient(IntPtrhWnd,Rectanglerect){Rectangleresult=rect;ScreenToClient(hWnd,refresult);returnresult;}//////窗口大小/////////publicstaticRectangleGetClientRect(IntPtrhWnd){Rectangleresult=default(Rectangle);GetClientRect(hWnd,refresult);returnresult;}#endregion}publicclassWinHWND{publicIntPtrHWND{get;set;}publicstringClassName{get;set;}publicWinHWNDParent{get;set;}publicintInParentSequence{get;set;}privateRectangle_currentRect;privatestring_Text;privateint_Left;privateint_Top;privateint_Width;privateint_Height;publicstringText{get{return_Text==default(string)?WinAPI.GetText(this.HWND):_Text;}set{_Text=value;WinAPI.SetText(this.HWND,value);}}publicintLeft{get{return_Left==default(int)?_currentRect.Left:_Left;}set{_Left=value;WinAPI.MoveWindow(this.HWND,value,this.Top,this.Width,this.Height,true);}}publicintTop{get{return_Top==default(int)?_currentRect.Top:_Top;}set{_Top=value;WinAPI.MoveWindow(this.HWND,this.Left,value,this.Width,this.Height,true);}}publicintWidth{get{return_Width==default(int)?_currentRect.Width:_Width;}set{_Width=value;WinAPI.MoveWindow(this.HWND,this.Left,this.Top,value,this.Height,true);}}publicintHeight{get{return_Height==default(int)?_currentRect.Height:_Height;}set{_Height=value;WinAPI.MoveWindow(this.HWND,this.Left,this.Top,this.Width,value,true);}}privateWinHWND(){}publicWinHWND(IntPtrhWnd){this.HWND=hWnd;this.ClassName=GetClassName();this.Parent=GetParent();this.InParentSequence=GetInParentSequence();this._currentRect=GetRect();}privatestringGetClassName(){returnWinAPI.GetClassName(this.HWND);}privateWinHWNDGetParent(){if(WinAPI.GetParent(this.HWND)==null){thrownewException("notfoundIntPtr!");}if(WinAPI.GetParent(this.HWND)==IntPtr.Zero){returnnull;}returnnewWinHWND(WinAPI.GetParent(this.HWND));}privateintGetInParentSequence(){IntPtrIntprtParent=this.Parent==null?IntPtr.Zero:this.Parent.HWND;returnWinAPI.GetChildHandles(IntprtParent,this.ClassName).IndexOf(this.HWND);}privateRectangleGetRect(){if(this.Parent==null)returndefault(Rectangle);RectangleclientSize=WinAPI.GetClientRect(this.HWND);RectangleclientPoint=WinAPI.ScreenToClient(this.Parent.HWND,WinAPI.GetWindowRect(this.HWND));returnnewRectangle(clientPoint.X,clientPoint.Y,clientSize.Width,clientSize.Height);}publicstaticWinHWNDGetWinHWND(){returnnewWinHWND(WinAPI.GetHandle(WinAPI.GetCursorPosPoint()));}publicoverridestringToString(){StringBuilderresult=newStringBuilder();for(WinHWNDwinHandle=this;winHandle!=null;winHandle=winHandle.Parent){result.Append(string.Format("{0}:{1};",Escape(winHandle.ClassName),winHandle.InParentSequence.ToString()));if(winHandle.InParentSequence==-1)break;}returnresult.ToString().TrimEnd(';');}privatestaticstringGetBaseMark(stringsMark){string[]sMarks=sMark.Split(';');returnsMarks[sMarks.Length-1].Split(':')[0];}privatestaticstring[]GetChildMarks(stringsMark){string[]sMarks=sMark.Split(';');string[]sChildMarks=newstring[sMarks.Length-1];for(inti=0;ibaseHwnds=WinAPI.GetChildHandles(IntPtr.Zero,GetBaseMark(sMark));string[]sChildMarks=GetChildMarks(sMark);//由于主窗口在桌面出现所以很可能同名,所以要看看他的儿子和孙子...是不是都匹配foreach(IntPtrbaseHwndinbaseHwnds){IntPtrhandle=baseHwnd;for(inti=sChildMarks.Length-1;i>=0;i--){string[]sChildMark=sChildMarks[i].Split(':');try{handle=WinAPI.GetChildHandles(handle,UnEscape(sChildMark[0]))[int.Parse(sChildMark[1])];}catch{break;}if(i==0)returnnewWinHWND(handle);}continue;}returnnull;}#region转义privatestaticstringEscape(stringarg){returnarg.Replace(":","\\:").Replace(";","\\;");}privatestaticstringUnEscape(stringarg){returnarg.Replace("\\:",":").Replace("\\;",";");}#endregion}}HYPERLINKDemo.rar效果:Postsubject:DllInjectionThisismyoldtutorialondllinjection...peoplehavebeenaskingaboutthistopicabitrecently,so...hereitis:DllInjectionTutorialbyDarawkIntroductionTheCreateRemoteThreadmethodTheSetWindowsHookExmethodThecodecavemethodAppendixA-MethodsofobtainingaprocessIDAppendixB-MethodsofobtainingathreadIDAppendixC-CompleteCreateRemoteThreadexamplesourcecodeAppendixD-CompleteSetWindowsHookExexamplesourcecodeAppendixE-CompletecodecaveexamplesourcecodeIntroductionInthistutoriali'lltrytocoveralloftheknownmethods(oratleast,thosethatIknow=p)ofinjectingdll'sintoaprocess.DllinjectionisincrediblyusefulforTONSofstuff(gamehacking,functionhooking,codepatching,keygenning,unpacking,etc..).Thoughtherearescatteredtutorialsonthesetechniquesavailablethroughouttheweb,Ihaveyettoseeanycompletetutorialsdetailingallofthem(theremayevenbemoreouttherethanIhavehere,ofcourse),andcomparingtheirrespectivestrength'sandweakness's.Thisispreciselywhati'llattempttodoforyouinthispaper.Youarefreetoreproduceorcopythispaper,solongaspropercreditisgivenandyoudon'tmodifyitwithoutspeakingtomefirst.TheCreateRemoteThreadmethodI'veusedthisintonsofstuff,andIonlyrecentlyrealizedthatalotofpeoplehaveneverseenit,orknowhowtodoit.Ican'ttakecreditforthinkingitup...Igotitfromanarticleoncodeproject,butit'saneattrickthatIthinkmorepeopleshouldknowhowtouse.Thetrickissimple,andelegant.ThewindowsAPIprovidesuswithafunctioncalledCreateRemoteThread().Thisallowsyoutostartathreadinanotherprocess.Forourpurposes,i'llassumeyouknowhowthreadingworks,andhowtousefunctionslikeCreateThread(ifnot,youcangohere).ThemaindisadvantageofthismethodisthatitwillworkonlyonwindowsNTandabove.Topreventitfromcrashing,youshouldusethisfunctiontochecktomakesureyou'reonanNT-basedsystem(thankstoCatIDforpointingthisout):boolIsWindowsNT(){//checkcurrentversionofWindowsDWORDversion=GetVersion();//parsereturnDWORDmajorVersion=(DWORD)(LOBYTE(LOWORD(version)));DWORDminorVersion=(DWORD)(HIBYTE(LOWORD(version)));return(version<0x80000000);}TheMSDNdefinitionforCreateRemoteThreadisasfollows:HANDLECreateRemoteThread(HANDLEhProcess,LPSECURITY_ATTRIBUTESlpThreadAttributes,SIZE_TdwStackSize,???????????????LPTHREAD_START_ROUTINElpStartAddress,LPVOIDlpParameter,DWORDdwCreationFlags,???????????????LPDWORDlpThreadId);So,it'sessentiallyCreateThread,withanhProcessargument,sothatwecantellitinwhichprocesstocreatethenewthread.Now,normallywewouldwanttostartthethreadexecutingonsomeinternalfunctionoftheprocessthatweareinteractingwith.However,toinjectadll,wehavetodosomethingalittlebitdifferent.BOOLInjectDLL(DWORDProcessID){??HANDLEProc;??charbuf[50]={0};??LPVOIDRemoteString,LoadLibAddy;??if(!ProcessID)????returnfalse;??Proc=OpenProcess(CREATE_THREAD_ACCESS,FALSE,ProcessID);??if(!Proc)??{????sprintf(buf,"OpenProcess()failed:%d",GetLastError());????MessageBox(NULL,buf,"Loader",NULL);????returnfalse;??}??LoadLibAddy=(LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"),"LoadLibraryA");??RemoteString=(LPVOID)VirtualAllocEx(Proc,NULL,strlen(DLL_NAME),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);??WriteProcessMemory(Proc,(LPVOID)RemoteString,DLL_NAME,strlen(DLL_NAME),NULL);??CreateRemoteThread(Proc,NULL,NULL,(LPTHREAD_START_ROUTINE)LoadLibAddy,(LPVOID)RemoteString,NULL,NULL);??????CloseHandle(Proc);??returntrue;}HYPERLINKHHOOKSetWindowsHookEx(??????intidHook,??HOOKPROClpfn,??HINSTANCEhMod,??DWORDdwThreadId);HYPERLINKLRESULTCALLBACKCBTProc(intnCode,WPARAMwParam,LPARAMlParam){??returnCallNextHookEx(0,nCode,wParam,lParam);};HYPERLINKHMODULEhDll;unsignedlongcbtProcAddr;hDll????=LoadLibrary("injected.dll");cbtProcAddr=GetProcAddress(hDll,"CBTProc");HYPERLINKBOOLInjectDll(char*dllName){??HMODULEhDll;??unsignedlongcbtProcAddr;??hDll????=LoadLibrary(dllName);??cbtProcAddr=GetProcAddress(hDll,"CBTProc");???SetWindowsHookEx(WH_CBT,cbtProcAddr,hDll,GetTargetThreadIdFromWindow("targetApp"));????returnTRUE;}__declspec(naked)loadDll(void){??_asm{????//??Placeholderforthereturnaddress????push0xDEADBEEF????//??Savetheflagsandregisters????pushfd????pushad????//??PlaceholderforthestringaddressandLoadLibrary????push0xDEADBEEF????moveax,0xDEADBEEF????//??CallLoadLibrarywiththestringparameter????calleax????//??Restoretheregistersandflags????popad????popfd????????//??Returncontroltothehijackedthread????ret??}}HYPERLINKvoid*dllString,*stub;unsignedlongwowID;HANDLEhProcess??//SeeAppendixAfor?//thisfunctionwowID??=GetTargetProcessIdFromProcname(PROC_NAME);????hProcess=OpenProcess((PROCESS_VM_WRITE|PROCESS_VM_OPERATION),false,wowID);dllString=VirtualAllocEx(hProcess,NULL,(strlen(DLL_NAME)+1),MEM_COMMIT,PAGE_READWRITE);stub???=VirtualAllocEx(hProcess,NULL,stubLen,MEM_COMMIT,PAGE_EXECUTE_READWRITE);WriteProcessMemory(hProcess,dllString,DLL_NAME,strlen(DLL_NAME),NULL);?HYPERLINKunsignedlongthreadID;HANDLEhThread;threadID=GetTargetThreadIdFromProcname(PROC_NAME);hThread??=OpenThread((THREAD_GET_CONTEXT|THREAD_SET_CONTEXT|THREAD_SUSPEND_RESUME),false,threadID);SuspendThread(hThread);ctx.ContextFlags=CONTEXT_CONTROL;GetThreadContext(hThread,&ctx);oldIP??=ctx.Eip;//SettheEIPofthecontexttotheaddressofourstubctx.Eip=(DWORD)stub;ctx.ContextFlags=CONTEXT_CONTROL;//RightnowloadDlliscode,whichisn'twritable.?Weneed//tochangethat.VirtualProtect(loadDll,stubLen,PAGE_EXECUTE_READWRITE,&oldprot);??//Patchthefirstpushinstructionmemcpy((void*)((unsignedlong)loadDll+1),&oldIP,4);??//Patchthe2ndpushinstructionmemcpy((void*)((unsignedlong)loadDll+8),&dllString,4);??//Patchthemoveax,0xDEADBEEFtomoveax,LoadLibrarymemcpy((void*)((unsignedlong)loadDll+13),&loadLibAddy,4);?WriteProcessMemory(hProcess,stub,loadDll,stubLen,NULL);??????//Writethestubintothetarget//Setthenewcontextofthetarget'sthreadSetThreadContext(hThread,&ctx);//Letthetargetthreadcontinueexecution,startingatourstubResumeThread(hThread);HYPERLINKSleep(8000);VirtualFreeEx(hProcess,dllString,strlen(DLL_NAME),MEM_DECOMMIT);VirtualFreeEx(hProcess,stub,stubLen,MEM_DECOMMIT);CloseHandle(hProcess);CloseHandle(hThread);HYPERLINKunsignedlongGetTargetProcessIdFromWindow(char*className,char*windowName){??unsignedlongprocID;??HWNDtargetWnd;??targetWnd=FindWindow(className,windowName);  GetWindowThreadProcessId(targetWnd,&procId);?????returnprocID;}unsignedlongGetTargetProcessIdFromProcname(char*procName){??PROCESSENTRY32pe;??HANDLEthSnapshot;??BOOLretval,ProcFound=false;??thSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);??if(thSnapshot==INVALID_HANDLE_VALUE)??{???MessageBox(NULL,"Error:unabletocreatetoolhelpsnapshot","Loader",NULL);???returnfalse;??}??pe.dwSize=sizeof(PROCESSENTRY32);  retval=Process32First(thSnapshot,&pe);??while(retval)??{???if(StrStrI(pe.szExeFile,procName))???{?????ProcFound=true;?????break;???}   retval  =Process32Ne
本文档为【C#利用句柄操作窗口】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: ¥11.0 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
木子与
暂无简介~
格式:doc
大小:37KB
软件:Word
页数:0
分类:
上传时间:2020-02-22
浏览量:9