?
Solved

How do I stop the childform overlapping the menubar and statusbar when i use Setparent?

Posted on 2010-01-11
2
Medium Priority
?
512 Views
Last Modified: 2013-11-25
As a test app, I have a .net MDI parent form, with a standard menubar and statusbar.  On the 'new' button click, I start a new process, get it's window handle using .MainWindowHandle, and pass it to SetParent, to make it a child of the main form.  This works, however if I maximize the child window it overlaps the menubar and the statusbar.  It also overlaps the menu/status bar when the form is moved around inside the client area.

Any ideas how i stop this?  I only want it to expand into the main client area.

Many Thanks in advance
Dim p As New Process
        p.StartInfo.FileName = "notepad.exe"

        p.Start()
        Threading.Thread.Sleep(1000)
        SetParent(p.MainWindowHandle(), Me.Handle)

Open in new window

0
Comment
Question by:ITPOL
2 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 26290257
This is what I use in a MDI...
this code will fill inthe MDI area and check to make sure that it is not running already in the background under someother screen.
This code will also kept the Maximized Child Forms from flickering when opening


Public Const WM_SETREDRAW As Integer = &HB
Public Declare Auto Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean

'ADD this to your button or menu click
Dim objForm As Form = New frmMyNewScreen
                    With objForm
                        If Not CheckActive(.Name) Then
                            .Dock = DockStyle.Fill
                            SendMessage(Me.Handle, WM_SETREDRAW, 0, 0)
                            .Text = "My New Screen"
                            .MdiParent = Me
                            .Show()
                        Else
                            .Text = "My New Screen"
                            .MdiParent = Me
                            .TopMost = True
                        End If
                    End With
'' IF you use a StatusBar  then un-comment
 ''       StatusBar1.Height += 1
 ''   StatusBar1.Height -= 1     
    SendMessage(Me.Handle, WM_SETREDRAW, 1, 0)
    Me.Invalidate(True)

  Private Function CheckActive(ByVal pChildName As String) As Boolean
        '//////////////////////////////////////////////
        '//  Check to see if the form 
        '//  is already open for viewing
        '//////////////////////////////////////////////
        For Each childForm As Form In Me.MdiChildren
            If TypeName(childForm).ToUpper = pChildName.ToUpper Then
                childForm.Activate()
                Return True
            End If
        Next
        Return False
    End Function

Open in new window

0
 
LVL 1

Accepted Solution

by:
ITPOL earned 0 total points
ID: 26291637
Thanks Planocz,

Unfortunately what I was also looking for was a way to turn the window handle into the form object, then the above code would be fine.

I managed to achieve what I was looking for using the following code and API's;

Thanks for your suggestion
p = New Process
        p.StartInfo.FileName = "notepad.exe"

        p.Start()
        'Threading.Thread.Sleep(1000)
        p.WaitForInputIdle()

        ' Create a new instance of the child form.
        Dim ChildForm As New ChildFormvb(p.MainWindowHandle)
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        m_ChildFormNumber += 1
        ChildForm.Text = "Window " & m_ChildFormNumber
        'Dim panel1 As New Panel
        'ChildForm.Controls.Add(panel1)
        'panel1.Dock = DockStyle.Fill
        'panel1.BorderStyle = BorderStyle.Fixed3D
        ChildForm.Show()

        'SetParent(p.MainWindowHandle(), Me.Handle)
        SetParent(p.MainWindowHandle(), ChildForm.Handle)

        ' Remove border and whatnot
        SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE)

        ' Move the window to overlay it on this window
        MoveWindow(p.MainWindowHandle, 0, 0, ChildForm.Width, ChildForm.Height, True)

Open in new window

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question