菜鸟捉虫(7)
软件世界
上期正确答案:
在上期的代码中,不管你输入什么,所查询的结果都是一样,将ListBox1中的所有内容都搜索到ListBox2中去了,原因是Pos(SubStr,UpperCase(ListBox1.Items.Strings[i]))> -1这一句判断,Pos函数在没有找到指定字符串时返回值为0,如果写成-1,那么将会把找到的与没找到的都添加到ListBox2中去了。将这个Bug修正后,还有一个Bug,那就是这个程序要区分大小写字符,为了不让程序区分大小写字符,将SubStr:=Edit.Text改成SubStr:=UpperCase(Edit1.Text),再将if Pos(SubStr,ListBox1.Items.Strings[i])>0改成if Pos(SubStr,UpperCase(ListBox1.Items.Strings[i]))>0即可。
获奖名单:
北京 张琪
上海 周义昆
广州 程向东
海南 李翔
以上获奖读者将获得电脑报最新出品的电脑报系列配套光盘杂志一套。
本期题目:
从ActiveX控件列表中导入Windows Media Player控件。使用该控件播放音频、视频文件。但运行时,右击该控件会弹出控件本身的快捷菜单。现在要求屏蔽掉本身的菜单,显示自己的快捷菜单。下面是实现该功能的源代码,但所有不足,找出其中的Bug。(注:需要加入Additional面板中的ApplicationEvents控件及新建一个PopupMenu控件。另外注意的是,在从ActiveX控件列表中导入Windows Media Player控件时,Class Name改为TMplayer,然后点击“Install”按钮安装,安装好后,可以在ActiveX面板中找到MPlayer控件。)
……
var
Form1: TForm1;
mPoint: TPoint;
implementation
{$R *.DFM}
procedure TForm1.ApplicationEvents1Message(var Msg:tagMSG;var Handled:Boolean);
function IsOnPlayer:Boolean; //该函数用于判断鼠标是否在Media Player之上,以免在点击Form时也会弹出菜单
begin
Result:=False;
mPoint.x:=Mouse.CursorPos.x;
mPoint.y:=Mouse.CursorPos.y;
if PtInRect(MPlayer1.ClientRect,mPoint) then //PtInRect API函数用于判断是否在指定的区域内
Result:=True;
end;
begin
if (Msg.message = WM_RBUTTONDOWN) or (Msg.message = WM_RBUTTONUP) then
begin
if IsOnPlayer then
begin
PopupMenu1.Popup(Mouse.CursorPos.x,Mouse.CursorPos.y); //弹出自己的菜单
Handled:=True;
end;
end;
end;