您的位置:程序门 -> delphi -> windows sdk/api



关于生成窗口中的hint


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


[向提问]关于生成窗口中的hint[已结贴,结贴人:liuyangsl]
发表于:2008-01-02 16:52:55 楼主
在application工程中,新建了一个tform2,

tform2中:
procedure   tform2.createparams(var   params:   tcreateparams);
begin
    inherited;
    params.exstyle:=params.exstyle   or   ws_ex_appwindow;
    params.wndparent   :=   getdesktopwindow;      
end;
为的是能在任务栏上显示form2窗口的按钮。

tform2中定义一个lable1,设置hint。
tform1中定义一个按钮,单击后创建一个form2,
将form2移动到form1的上方,
鼠标移到form2中的lable1上,试图显示hint,
但不知道为什么这时候form1突然跳到最前面来了。

虚心求教。
发表于:2008-01-02 17:26:501楼 得分:0
用delphi6测试没有出现,用turbo   delphi测试出现。
先标记一下,有时间看看。
发表于:2008-01-02 17:53:542楼 得分:0
我用的delphi7
发表于:2008-01-02 19:18:163楼 得分:0
delphi6/controls.pas
delphi(pascal) code
procedure thintwindow.activatehint(rect: trect; const ahint: string); type tanimationstyle = (atslideneg, atslidepos, atblend); const animationstyle: array[tanimationstyle] of integer = (aw_ver_negative, aw_ver_positive, aw_blend); var animate: bool; style: tanimationstyle; begin factivating := true; try caption := ahint; inc(rect.bottom, 4); updateboundsrect(rect); if rect.top + height > screen.desktopheight then rect.top := screen.desktopheight - height; if rect.left + width > screen.desktopwidth then rect.left := screen.desktopwidth - width; if rect.left < screen.desktopleft then rect.left := screen.desktopleft; if rect.bottom < screen.desktoptop then rect.bottom := screen.desktoptop; setwindowpos(handle, hwnd_topmost, rect.left, rect.top, width, height, swp_noactivate); if (gettickcount - flastactive > 250) and (length(ahint) < 100) and assigned(animatewindowproc) then begin systemparametersinfo(spi_gettooltipanimation, 0, @animate, 0); if animate then begin systemparametersinfo(spi_gettooltipfade, 0, @animate, 0); if animate then style := atblend else if mouse.getcursorpos.y > rect.top then style := atslideneg else style := atslidepos; animatewindowproc(handle, 100, animationstyle[style] or aw_slide); end; end; showwindow(handle, sw_shownoactivate); invalidate; finally flastactive := gettickcount; factivating := false; end; end;


turbodelphi/controls.pas
delphi(pascal) code
procedure thintwindow.activatehint(rect: trect; const ahint: string); type tanimationstyle = (atslideneg, atslidepos, atblend); const animationstyle: array[tanimationstyle] of integer = (aw_ver_negative, aw_ver_positive, aw_blend); var animate: bool; style: tanimationstyle; begin factivating := true; try caption := ahint; inc(rect.bottom, 4); updateboundsrect(rect); if rect.top + height > screen.desktopheight then rect.top := screen.desktopheight - height; if rect.left + width > screen.desktopwidth then rect.left := screen.desktopwidth - width; if rect.left < screen.desktopleft then rect.left := screen.desktopleft; if rect.bottom < screen.desktoptop then rect.bottom := screen.desktoptop; setwindowpos(handle, hwnd_topmost, rect.left, rect.top, width, height, swp_noactivate); if (gettickcount - flastactive > 250) and (length(ahint) < 100) and assigned(animatewindowproc) then begin systemparametersinfo(spi_gettooltipanimation, 0, @animate, 0); if animate then begin systemparametersinfo(spi_gettooltipfade, 0, @animate, 0); if animate then style := atblend else if mouse.getcursorpos.y > rect.top then style := atslideneg else style := atslidepos; animatewindowproc(handle, 100, animationstyle[style] or aw_slide); end; end; parentwindow := application.handle; //<<<<<<<<<<<<<<<<<<<< showwindow(handle, sw_shownoactivate); invalidate; finally flastactive := gettickcount; factivating := false; end; end;

发表于:2008-01-02 19:21:554楼 得分:100
比较两个版本的区别,就是多了
delphi(pascal) code
parentwindow := application.handle;
的代码
重载一下thintwindow,将activatehint中的那句话屏蔽掉。解决方案:
delphi(pascal) code
unit unit1; interface uses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; type tform1 = class(tform) button1: tbutton; label1: tlabel; procedure button1click(sender: tobject); private { private declarations } procedure wmwindowposchanging(var msg: tmessage); message wm_windowposchanging; public { public declarations } end; var form1: tform1; implementation uses unit2; {$r *.dfm} type thintwindowex = class(thintwindow) public procedure activatehint(rect: trect; const ahint: string); override; end; thintwindowaccess = class(tcustomcontrol) private factivating: boolean; flastactive: cardinal; end; procedure thintwindowex.activatehint(rect: trect; const ahint: string); type tanimationstyle = (atslideneg, atslidepos, atblend); const animationstyle: array[tanimationstyle] of integer = (aw_ver_negative, aw_ver_positive, aw_blend); var animate: bool; style: tanimationstyle; begin thintwindowaccess(self).factivating := true; try caption := ahint; inc(rect.bottom, 4); updateboundsrect(rect); if rect.top + height > screen.desktopheight then rect.top := screen.desktopheight - height; if rect.left + width > screen.desktopwidth then rect.left := screen.desktopwidth - width; if rect.left < screen.desktopleft then rect.left := screen.desktopleft; if rect.bottom < screen.desktoptop then rect.bottom := screen.desktoptop; setwindowpos(handle, hwnd_topmost, rect.left, rect.top, width, height, swp_noactivate); if (gettickcount - thintwindowaccess(self).flastactive > 250) and (length(ahint) < 100) and assigned(animatewindowproc) then begin systemparametersinfo(spi_gettooltipanimation, 0, @animate, 0); if animate then begin systemparametersinfo(spi_gettooltipfade, 0, @animate, 0); if animate then style := atblend else if mouse.cursorpos.y > rect.top then style := atslideneg else style := atslidepos; animatewindowproc(handle, 100, animationstyle[style] or aw_slide); end; end; //parentwindow := application.handle; showwindow(handle, sw_shownoactivate); invalidate; finally thintwindowaccess(self).flastactive := gettickcount; thintwindowaccess(self).factivating := false; end; end; procedure tform1.button1click(sender: tobject); begin hintwindowclass := thintwindowex; application.showhint := false; application.showhint := true; form2 := tform2.create(self); form2.show; end; procedure tform1.wmwindowposchanging(var msg: tmessage); begin inherited; end; end.
发表于:2008-01-02 19:27:055楼 得分:0
这里有个小技巧特别说明一下:如何访问其他类的私有字段
delphi(pascal) code
thintwindowaccess = class(tcustomcontrol) private factivating: boolean; flastactive: cardinal; end;

比较
delphi(pascal) code
thintwindow = class(tcustomcontrol) private factivating: boolean; flastactive: cardinal; //....

类继承相同的父类,其私有字段首地址相同
通过强制转换可以访问。
delphi(pascal) code
thintwindowaccess(self).factivating := true;
发表于:2008-01-02 21:16:326楼 得分:0
orz
发表于:2008-01-02 21:38:027楼 得分:0
zswang用这个方法够偏门的,呵呵
发表于:2008-01-04 10:12:018楼 得分:0
可以用,多谢。


快速检索

最新资讯
热门点击