高手快来拿分-->GetMenu为什么对Word无效(100分)

  • 主题发起人 主题发起人 quaver
  • 开始时间 开始时间
Q

quaver

Unregistered / Unconfirmed
GUEST, unregistred user!
<br>&nbsp; h:=FindWindow('OpusApp',nil); &nbsp;//OpusApp:Word类名<br>&nbsp; if h&lt;&gt;0 then<br>&nbsp; begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; GetWindowText(h,winName,SizeOf(winName));<br>&nbsp; &nbsp; SetForegroundWindow(h);<br>&nbsp; &nbsp; m:=GetMenu(h);//取主菜单句柄,但每次都是0,不知何故<br>&nbsp; &nbsp; m:=GetSubMenu(m,0);//取文件菜单句柄<br>&nbsp; &nbsp; //调'另存为'对话框<br>&nbsp; &nbsp; PostMessage(h,WM_COMMAND,MakeLong(GetMenuItemId(m,4),0),GetSubMenu(m,4));<br>&nbsp;
 
Word 的菜单不是直接存在于Word的主窗口中,而是在子窗口中,<br>下面的代码验证了这一点:<br>------------------------------------------------------<br>var<br>&nbsp; hWord, hCommandDock, hCommand: HWND;<br>begin<br>&nbsp; // Word 的窗口<br>&nbsp; hWord := FindWindow( 'OpusApp', nil ); <br>&nbsp; // 上部的菜单、工具栏部分<br>&nbsp; hCommandDock := FindWindowEx( hWord, 0, 'MsoCommandBarDock', 'MsoDockTop' );<br>&nbsp; // 菜单栏<br>&nbsp; hCommand := FindWindowEx( hCommandDock, 0, 'MsoCommandBar', '菜单栏' );<br>------------------------------------------------------<br><br>理论上GetMenu的参数应该是 hCommand, 但GetMenu不支持对子窗口的调用。<br>下面是MSDN原文:<br>The return value is a handle to the menu. If the specified window <br>has no menu, the return value is NULL. If the window is a child <br>window, the return value is undefined. <br>
 
接受答案了.
 
后退
顶部