以下代码中fbhandle和gothandle均为全局变量,可是,在使用中发现,fbhandle:=hd这一句是起作用的,而gothandle:='True';却不起作用,表现为每次按下热键时显示的gothandle值都是空的,而如果在FormCreate中加上gothandle:=‘false’的话显示的就是False,请问这是为什么?还有一小问:Boolean型如何转成String呢?function getw(hd:HWND;aform:TForm1):Boolean;stdcall;
var
pid:dWord;
classname,title:array[0..255] of char;
begin
GetWindowText(hd,title,254);
if Pos('MyForm',title)<>0 then
begin
gothandle:='True';
fbhandle:=hd;
end
else
gothandle:='False';
Result:=True;
end;procedure tform1.ONHotkey(var message:Tmessage);
begin
ShowMessage(gothandle);
if gothandle='False' then
begin
EnumWindows(@getw,0);
//……
end
else
begin
//……
end;
end;
var
pid:dWord;
classname,title:array[0..255] of char;
begin
GetWindowText(hd,title,254);
if Pos('MyForm',title)<>0 then
begin
gothandle:='True';
fbhandle:=hd;
end
else
gothandle:='False';
Result:=True;
end;procedure tform1.ONHotkey(var message:Tmessage);
begin
ShowMessage(gothandle);
if gothandle='False' then
begin
EnumWindows(@getw,0);
//……
end
else
begin
//……
end;
end;
解决方案 »
- 如何实现框架模式?
- KeiKi作错事,小小没有分,先要我垫付~~~ 哎~~这事道呀,小小记的还哈
- 国庆散分------非常久没来看看了,兄弟们有谁还在? zdcnow
- 求救:在查询分析器中运行一个使用openrowset()函数从DBF导入到SQL Server表中的存储过程,执行期间强行关闭之后,无法再次执行!!
- 两个很简单的问题,请帮忙解答。
- 请教获取IE版本号和office版本号的方法?
- 请问在什么地方有好的delphi控件下载
- 请教高手,本人想请教通过串口发送UNICODE的问题,急!!!在线等待
- 两个小问题。
- Exit,Abort都是退出本程序,其区别是什么?
- 两个TREEVIEW控件的树节点之间如何画线
- 请问下列代码哪里有问题?编译没问题,但折线画不出来
GetWindowText(hd, title, SizeOf(title));
if Pos('MyForm', title) <> 0 then
begin
gothandle := 'True';
fbhandle := hd;
end else gothandle := 'False';
Result := gothandle <> 'True'; //<<<<<<<<<如果窗体找到则,停止扫描
end;两对函数的用法参考
if StrToBoolDef(gothandle, False) then
//BoolToStr()
Boolean型如何转成String:BoolToStr(B: Boolean; UseBoolStrs: Boolean = False)
var
vBoolean: Boolean;
vBOOL: BOOL;
begin
vBoolean := True; //1
vBOOL := True; //-1
ShowMessage(Format('%d,%d', [Ord(vBoolean), Ord(vBOOL)]));
end;
BOOL CALLBACK EnumWindowsProc(
HWND hwnd, // handle to parent window
LPARAM lParam // application-defined value
);
C里的类型和Pascal的类型并不一样
考虑兼容,Delphi也增加了BOOL,声明的函数要和回调函数原型一致
BOOL是4个字节
Caption := Format('%d,%d', [SizeOf(Boolean), SizeOf(BOOL)]);你的函数使用Boolean
当返回False时,只把1个字节赋直为0,但后面3个字节没改变,这3个字节中只要有一个不为0,就会使返回值非0(True)