关键在于对wm_enteridle消息的处理
在菜单状态下移动鼠标会产生wm_enteridle消息
这时用temppoint、windowfrompoint可以取得当前鼠标所指窗体的句柄
再用getclassname取得类名,与"#32768"(菜单窗体的类名)进行比较
再等待1秒钟,用keybd_event发送vk_escape取消菜单状态
但是还是有一个的缺点:无法在鼠标不移动的时候自动隐藏
这时需要timer控件的帮忙
将下列文件粘贴到记事本,并保存为相应文件
autohidepopupmenu.vbp
====================================================================
type=exe
form=form1.frm
reference=*\g{00020430-0000-0000-c000-000000000046}#2.0#0#..\..\..\..\..\..\windows\system\stdole2.tlb#ole automation
module=module1; module1.bas
startup="form1"
exename32="autohidepopupmenu.exe"
command32=""
name="autohidepopupmenu"
helpcontextid="0"
compatiblemode="0"
majorver=1
minorver=0
revisionver=0
autoincrementver=0
serversupportfiles=0
versioncompanyname="zyl910"
compilationtype=0
optimizationtype=0
favorpentiumpro(tm)=0
codeviewdebuginfo=0
noaliasing=0
boundscheck=0
overflowcheck=0
flpointcheck=0
fdivcheck=0
unroundedfp=0
startmode=0
unattended=0
retained=0
threadperobject=0
maxnumberofthreads=1
form1.frm
====================================================================
version 5.00
begin vb.form form1
borderstyle = 1 'fixed single
caption = "autohidepopupmenu"
clientheight = 3225
clientleft = 45
clienttop = 330
clientwidth = 4710
linktopic = "form1"
maxbutton = 0 'false
scaleheight = 3225
scalewidth = 4710
startupposition = 3 '窗口缺省
begin vb.timer timer1
interval = 1000
left = 2580
top = 360
end
begin vb.label lblnow
autosize = -1 'true
caption = "lblnow"
height = 180
left = 1410
tabindex = 1
top = 210
width = 540
end
begin vb.label lblclick
autosize = -1 'true
caption = "点击鼠标右键"
beginproperty font
name = "宋体"
size = 26.25
charset = 134
weight = 400
underline = 0 'false
italic = 0 'false
strikethrough = 0 'false
endproperty
height = 525
left = 720