Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
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 );

Awaiting your answers.
Thanks in advance for your answers.

Regards
Vk Mallaya
Posted
Updated 6-Nov-12 16:36pm
v4
Comments
Sergey Alexandrovich Kryukov 6-Nov-12 16:42pm    
Well, without any code sample, it's not so easy to figure out...
--SA
Vipin Kumar Mallaya G 7-Nov-12 0:33am    
Code is added to question
Sergey Alexandrovich Kryukov 7-Nov-12 1:01am    
OK, I see. You are doing bad things, trying to manipulate a different process, not designed for some civilized collaboration. I'm very much against such approach: ad-hoc, never reliable results. I don't want to waste time on such stuff and would strongly suggest you to spend time on something useful. I understand you might not like it and apologize.
--SA
Vipin Kumar Mallaya G 7-Nov-12 3:26am    
First of all thank you for responding.
The requirement laid out to me is like that :)

My actual Problem Goes like this
There is an existing application which contacts a remote server in users machine( i cannot make any changes to the existing application).
User requires a tabbed application to contact with multiple server and he should also be able to work with multiple tab simultaneously.
Thus i designed a solution which is similar to chrome. Each tab host the existing child application, which contacts the desired server.
I managed to do it and its working fine too user is quite happy with it. Sole problem is with menus in the child application. Menus are not getting displayed on mouse click for my child application once attached to my application. Keyboard shortcuts are working fine and displaying menu.

Is it the problem with child application or with .net menus ?

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
 
Share this answer
 
v2
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.
C#
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);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900