如何获得资源管理器的右键菜单Handle?(50分)

  • 主题发起人 主题发起人 clark
  • 开始时间 开始时间
C

clark

Unregistered / Unconfirmed
GUEST, unregistred user!
象PicaView那样,可以在右键菜单中显示略图。。。<br>谢谢
 
修改注册表,具体解决以答问题里面有!
 
我知道,改注册表,但是,当右键点击图象文件是,我的程序如何,得到Handle并<br>插入位图菜单项,具体一点好吗?谢谢
 
为什么不看看Delph demos/shellext/contmenu.dpr<br>的例子呢?那里好像全有了.
 
参见&lt;&lt;Windows 95程序员指南&gt;&gt;<br>好像有个类似IContextMenu的ole接口<br>我记不清了.<br>不过书名没错,我自己在程序中就得到过你要的右键菜单.<br>等我查一下书后再回答你.<br>
 
&nbsp; &nbsp;此段代码可获取任何窗口的Handle,类名,以及位置等旗帜。<br>任何右键快捷菜单也不例外。<br>&nbsp; &nbsp; 先在Form中放入一个Label及一个Timer,在Timer的OnTimer<br>事件中加入下面的代码:<br>&nbsp; &nbsp; &nbsp; &nbsp;<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; &nbsp; &nbsp;Tp &nbsp; &nbsp;:Tpoint;<br>&nbsp; &nbsp; &nbsp;Hnd &nbsp; :Hwnd;<br>&nbsp; &nbsp; &nbsp;Tx &nbsp; &nbsp;:Pchar;<br>&nbsp; &nbsp; &nbsp;Rect &nbsp;:TRect;<br>begin<br>&nbsp; GetCursorPos(Tp);<br>&nbsp; Hnd:=WindowFromPoint(Tp);<br><br>&nbsp; GetMem(Tx,255);<br><br>&nbsp; GetClassname(Hnd,Tx,255);<br>&nbsp; Windows.GetClientRect(Hnd,Rect);<br>&nbsp; MapWindowPoints(Hnd,0,Rect,2);<br><br>&nbsp; Label1.Caption:=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'(Handle:'+IntTostr(Hnd)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' ClassName:'+String(Tx)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+')Left:'+inttostr(Rect.Left)+';'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+'Top:'+inttostr(Rect.Top)+';'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+'Height:'+inttostr(Rect.Bottom-Rect.Top)+';'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+'Width:'+inttostr(Rect.right-Rect.Left);<br><br>&nbsp; FreeMem(Tx,255);<br><br>//if (OldHnd=Hnd) then Exit;<br><br>&nbsp;if not (Hnd=Form1.Handle) then<br>&nbsp; begin<br><br>&nbsp; &nbsp; if Tp.X+Width&lt;Screen.Width then<br>&nbsp; &nbsp; &nbsp; &nbsp;Left:=Tp.X+10 else<br>&nbsp; &nbsp; &nbsp; &nbsp;Left:=Screen.Width-Width;<br><br>&nbsp; &nbsp; if (string(Tx)=string('#32768')) then<br>&nbsp; &nbsp; &nbsp; &nbsp;Top:=Rect.Bottom+10 else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if Tp.Y+50&lt;Screen.Height then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Top:=Tp.Y+10 else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Top:=Screen.Height-50;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>// OldHnd:=Hnd;<br>end;<br>
 
用鼠标的HOOK不就行了吗.
 
大家扯远了。<br>要把自己的程序作为Ole Server,如Alan Jiang(他的english name 与我一样:)<br>所说,实现IContextMenu接口。<br>看看Inside OLE吧。
 
tgz 说得对。这跟菜单的句柄没有关系,要用到微软 com 模型来编写程序。不过如果要像PicView那样在菜单中显示一张图片的话,要用IContexMenu2接口,而不是IContexMenu接口。
 
多人接受答案了。
 
后退
顶部