下面这段代码是查找当前系统运行的所有窗口名称的。窗口名称保存在MyStringList里。
Function My_RefreshForm(MyStringList:TStringList):Boolean; 
var
hCurrentWindow: HWnd;
szText: array[0..254] of char; 
begin 
MyStringList.Clear;
hCurrentWindow := GetWindow(application.Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if GetWindowText(hCurrentWindow, @szText, 255) > 0 then
MyStringList.Add(StrPas(@szText));
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
Result:=true;
end;现在的问题是,如果这个函数写在EXE文件里调用,没问题,但是如果写在DLL里调用,那么
返回空值。
调试中发现问题出在这一句代码:
hCurrentWindow := GetWindow(application.Handle, GW_HWNDFIRST);
在DLL中调用时,application.Handle也有值,但是返回值hCurrentWindow 为0。
请问产生问题的原因是什么,如何解决?  

解决方案 »

  1.   

    那你在調用dll時,將主程序的application.handle傳過去不就可以了,在dll中, 設置相應的application.handle.
      

  2.   

    呵呵。不好意思。
    to aiirii(aiirii) 
    请问如何传APPLICATION.HANDLE。是在DLL的入口吗?
      

  3.   

    该问题我已解决。查看delphibbs离线资料解决的。將主程序的application.handle传到DLL的HOOK,但是遍历窗口部分移到了EXE里。
    请看这两句代码:
    1
    hCurrentWindow := GetWindow(application.Handle, GW_HWNDFIRST);
    2
    hCurrentWindow := GetWindow(getactivewindow, GW_HWNDFIRST);1只在EXE里调用有效,2只在DLL里调用有效,请问原因
      

  4.   

    最好是使用 EnumWindows、EnumWindowsProc 函数查找
      

  5.   

    我用EnumWindows,加上getwindowlong做判断已经解决了。
    但是我想问问这个原因
      

  6.   

    都是borland的错!!在GOOGLE中搜一下,我见过,忘了那个网址了!