当我调用完EnumChildWindows后,当前程序给Form里的任何控件赋值操作都会产生错误 why? ( 积分: 100 )

  • 主题发起人 主题发起人 willyxia
  • 开始时间 开始时间
W

willyxia

Unregistered / Unconfirmed
GUEST, unregistred user!
例如:

Procedure TForm1.Button1Click(Sender: TObject);
function EnumChildWindowsProc(h: Integer): Boolean; stdcall;
begin
...
end;
begin
h := findWindow('TFormTest',nil);
EnumChildWindows(h,@EnumChildWindowsProc,Integer(@h));
//showImage在Form1上,下面一句就会报错
ShowImage.Picture.BitMap.LoadFromFile('c:/333.bmp');
end;
 
例如:

Procedure TForm1.Button1Click(Sender: TObject);
function EnumChildWindowsProc(h: Integer): Boolean; stdcall;
begin
...
end;
begin
h := findWindow('TFormTest',nil);
EnumChildWindows(h,@EnumChildWindowsProc,Integer(@h));
//showImage在Form1上,下面一句就会报错
ShowImage.Picture.BitMap.LoadFromFile('c:/333.bmp');
end;
 
要看帮助!EnumChildWindowsProc定义不对。
BOOL CALLBACK EnumChildProc(
HWND hwnd, // handle to child window
LPARAM lParam // application-defined value
);

function EnumChildWindowsProc(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
begin
...
end;

Procedure TForm1.Button1Click(Sender: TObject);
begin
h := findWindow('TFormTest',nil);
EnumChildWindows(h,@EnumChildWindowsProc,Integer(@h));
//showImage在Form1上,下面一句就会报错
ShowImage.Picture.BitMap.LoadFromFile('c:/333.bmp');
end;
 
To lichengbin,
按照你的意思,还是不行哦。
是不是回调函数的问题?
 
你怎么写的?贴出来看看。下面的代码测试没有任何问题。
function EnumChildWindowsProc(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
begin
Result := True;
Form1.Memo1.Lines.Add(IntToHex(hwnd, 8));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
h: HWND;
begin
h := FindWindow(nil, '无标题 - 记事本');
EnumChildWindows(h, @EnumChildWindowsProc, 0);
end;
 
谢谢lichengbin
问题出在EnumChildWindowsProc定义不对。

 
后退
顶部