鼠标单击时不显示菜单。 [英] Menus not displaying on mouse click.

查看:91
本文介绍了鼠标单击时不显示菜单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正在开发一个标签式多进程应用程序(如chrome)。我的子进程包含上下文菜单和菜单栏。

我的问题是,对于加载的子进程,菜单栏中的菜单不会在鼠标单击时显示,其中菜单上的上下文菜单和热键没有任何问题。

当加载记事本作为子进程时,鼠标点击显示菜单没有任何问题。



我的代码 -

Dear All,
I am working on a tabbed multi-process application(like chrome). My child process contains both context menu as well as menu bar.
My problem is, for a loaded child process, menus in menu bar are not shown on mouse click, where as context menus and hot keys on menus work without any issues.
When loading Notepad as child process, menus are displayed on mouse click without any problem.

My code -

Process p = Process.Start( @"myexe" );
p.WaitForInputIdle();
IntPtr value = SetParent( p.MainWindowHandle, pan.Handle );            
Rectangle rec = tabPage1.ClientRectangle;
MoveWindow( p.MainWindowHandle, rec.X, rec.Y, rec.Width, rec.Height, true );



等待你的回答。 />
预先感谢您的回答。



问候

Vk Mallaya


Awaiting your answers.
Thanks in advance for your answers.

Regards
Vk Mallaya

推荐答案

感谢您的澄清和代码示例。



我明白了。我认为你正在努力做坏事:操纵不是为进程间协作而设计的外部进程。而且,为了弥补这一点,您尝试使用Windows消息传递机制,这是一种奇怪的仅使用Windows的传统类IPC机制,在Windows不是操作系统时创建,并且当进程未被隔离时创建。



他们现在被隔离了;你的方法过于人为。这是一种临时方法;并且结果非常不可靠,这在某种程度上可以通过您的问题得到证明(同样适用于记事本)。我不知道有什么区别,因为我不知道你的应用程序不起作用。如果这是您的应用程序,您应该使用一些合法的IPC,可能是经典.NET远程处理或自托管WPF,还可以使用套接字,可能通过 TcpListener / TcpClient



如果这不是你的申请,我甚至不想浪费时间在它上面建议你把时间花在有用的事情上,抱歉。我明白你可能不喜欢它并想为此道歉。



-SA
Thank you for the clarification and the code sample.

I see. I think you are trying to do bad things: manipulating external processes which are not designed for inter-process collaboration. And, to compensate it, you try to use Windows messaging mechanism, a weird Windows-only legacy IPC-like mechanism, created when Windows was not OS, and when processes were not isolated.

They are isolated now; and your approach is too much artificial. This is an ad-hoc approach; and results are very non-reliable, which is somehow proven by your problem (same thing works for Notepad). I don''t know what''s the difference, because I have no idea of your application which does not work. If this is your application, you should use some legitimate IPC, possibly "classic" .NET remoting or self-hosted WPF, but also sockets, possibly via TcpListener/TcpClient.

If this is not your application, I don''t even want to waste time on it and would strongly advise you spend your time on something useful, sorry. I do understand you might dislike it and want to apologize for that.

—SA


大家好,

感谢您的所有支持和时间来了解我的问题。



我发布的代码解决了以下问题。

Hi all,
Thank you for all your support and time for taking a look into my problem.

I am posting my code which solved the issue below.
long style = WinAPI.GetWindowLongPtr(new HandleRef(this,console.MainWindowHandle), WinAPIConstants.GWL_STYLE).ToInt64();
            
            style= style & ~(WinAPIConstants.WS_CAPTION |
                                            WinAPIConstants.WS_BORDER |
                                            WinAPIConstants.WS_DLGFRAME);
            IntPtr styleValue = new IntPtr(style);
            Rectangle displayRectangle = newTab.DisplayRectangle;
                        
            // Removing the title bar and border.
            WinAPI.SetWindowLongPtr(new HandleRef( this,console.MainWindowHandle),
                                  WinAPIConstants.GWL_STYLE, styleValue);

            style = WinAPI.GetWindowLongPtr(new HandleRef(this, console.MainWindowHandle), WinAPIConstants.GWL_STYLE).ToInt64();
            style &= ~WinAPIConstants.WS_POPUP;
            style |= WinAPIConstants.WS_CHILD;

            styleValue = new IntPtr(style);

            // Setting window to be child of current application and the popup behaviour of window is removed.
            WinAPI.SetWindowLongPtr(new HandleRef(this, console.MainWindowHandle), WinAPIConstants.GWL_STYLE, styleValue);

            // Attach the window to the tab. 
            WinAPI.SetParent(console.MainWindowHandle, newTab.Handle);


这篇关于鼠标单击时不显示菜单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆