怎样获得别的应用程序的句柄?? (0分)

  • 主题发起人 主题发起人 Celestial dog
  • 开始时间 开始时间
C

Celestial dog

Unregistered / Unconfirmed
GUEST, unregistred user!
用一个listbox把当前运行的应用程序显示出来,然后实现隐藏和显示功能<br>隐藏时最好托盘区也不显示
 
没有分,就没人理??<br>
 
procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br>end;
 
这句话设么意思哑??<br>看样得买本win api的书啦
 
Windows API函数SetWindowLong()实现:程序在运行后不出现在任务栏上,参数意思可以看Help|Windows SDK<br>我看了一下,help很详细的~~
 
可是我怎么得到别的应用程序的handle妮??
 
22458868<br>
 
那怎么把所有运行的应用程序名显示到listbox里妮?<br>也就是怎么得到当前运行的程序名??
 
怎么关隐藏不了??<br>procedure TForm1.SpeedButton3Click(Sender: TObject);<br>var<br>&nbsp; wndHandle : THandle;<br>&nbsp; wndClass : array[0..50] of Char;<br>begin<br>&nbsp; StrPCopy(@wndClass[0], '我的文档');<br>&nbsp; wndHandle := FindWindow(@wndClass[0], nil);<br>&nbsp; ShowWindow(wndHandle, SW_HIDE);<br>end;
 
用回调技术及EnumWindows()函数来枚举所有的活动窗体,给你个思路:<br><br>function EnumWindowsProc(hWindow:hWnd; lParam:LongInt):Bool {$IFDEF Win32}stdcall;{$ELSE};export;{$ENDIF}<br>var<br>&nbsp; lpBuffer: PChar;<br>&nbsp; WindowCaptionFound: bool;<br>&nbsp; ClassNameFound: bool;<br>begin<br>&nbsp; GetMem(lpBuffer, 255);<br>&nbsp; Result := true;<br>&nbsp; WindowCaptionFound := false;<br>&nbsp; ClassNameFound := false;<br>&nbsp; try<br>&nbsp; &nbsp; //getwindowText复制指定窗体的标题或内容至buffer中<br>&nbsp; &nbsp; if GetWindowText(hWindow,lpBuffer, 255) &gt; 0 then<br>&nbsp; &nbsp; &nbsp; //判断是否为自己要查找的窗体<br>&nbsp; &nbsp; &nbsp; if Pos(PFindWindowStruct(lParam).caption, StrPas(lpBuffer)) &gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; WindowCaptionFound := true;<br>&nbsp; &nbsp; if PFindWindowStruct(lParam).ClassName = '' then<br>&nbsp; &nbsp; &nbsp; ClassNameFound := true<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; //将指定窗体的类名复制至buffer中<br>&nbsp; &nbsp; &nbsp; if GetClassName(hWindow, lpBuffer, 255) &gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; if Pos(PFindWindowStruct(lParam).ClassName, StrPas(lpBuffer))&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ClassNameFound := true;<br>&nbsp; &nbsp; //如果已经全部找到,则告诉调用函数停止枚举<br>&nbsp; &nbsp; if (WindowCaptionFound and ClassNameFound) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; PFindWindowStruct(lParam).WindowHandle := hWindow;<br>&nbsp; &nbsp; &nbsp; &nbsp; result := false;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; //释放所开辟的空间<br>&nbsp; &nbsp; FreeMem(lpBuffer, sizeof(lpBuffer^));<br>&nbsp; end;<br>end;<br><br>function FindAWindow(Caption: string; ClassName: string): THandle;<br>var<br>&nbsp; WindowInfo:TFindWindowStruct;<br>begin<br>&nbsp; //根据要查找的标题或类名给WindowInfo赋值<br>&nbsp; WindowInfo.Caption := Caption;<br>&nbsp; WindowInfo.ClassName := ClassName;<br>&nbsp; WindowInfo.WindowHandle := 0;<br>&nbsp; //开始枚举所有活动窗体,查找符合条件的<br>&nbsp; EnumWindows(@EnumWindowsProc, LongInt(@WindowInfo));<br>&nbsp; //返回要查找的窗体句柄<br>&nbsp; {FindAWindow}result := WindowInfo.WindowHandle;<br>end;<br><br>procedure TFormMain.Button2Click(Sender: TObject);<br>var<br>&nbsp; TheWindowHandle:THandle;<br>&nbsp; StartupInfo: TSTARTUPINFO;<br>&nbsp; ProcessInfo: TPROCESSINFORMATION;<br>begin<br>&nbsp; TheWindowHandle:=findwindow('浏览','');<br>&nbsp; if TheWindowHandle&lt;&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ListBox.Add..............<br>&nbsp; &nbsp; end<br>end;
 
可是我怎么得不到别的应用程序的handle妮??<br>为什么不能隐藏我的文档??
 
接受答案了.
 
后退
顶部