How to get the MDIForm client area handle

R

Rene Mansveld

Hi all,

I'm desperately trying to figure out how to retrieve the handle of the
MDIForm's client area.
I need this for the .NET version of our free MDI TaskBar control.
The control needs to get to the MDIForm's client area handle in order to
receive windows messages on the creation and destruction of MDIChild forms.
I wrote a subclassing class according to MS's knowledge base article
#311317, and I want to use code like the following:

Private MDI As SubclassMDI = New SubclassMDI()

Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
MyBase.OnHandleCreated(e)
MDI.AssignHandle(Me.Parent.Handle) ' <-- here I need something like
"Me.Parent.ClientArea.Handle"
End Sub

Protected Overrides Sub OnHandleDestroyed(ByVal e As System.EventArgs)
MDI.ReleaseHandle()
End Sub


--
Any help gladly appreciated ...

Rene Mansveld
Spider IT - Germany (was Whitworth Software Solutions)
www.Spider-IT.de / www.Spider-IT.net / www.Spider-IT.org / www.Spider-IT.biz

Please reply to the newsgroup(s) :blush:)
 
G

Guest

Hello Rene

You can find MdiClient control by iterating over the form's child controls until you find one that can by cast to MdiClient. See the following C# code.

foreach (Control control in Controls)
{
if (control as MdiClient != null)
{
mdiClient = (MdiClient)control;
break;
}
}

/Henrik
 
R

Rene Mansveld

Hi again,

now I have another problem:
I can get to the messages of the MDIClient area now, but I don't seem to get
the WM_MDICREATE message, although I do get the WM_MDIDESTROY message.
My code in question:

Public Class SubclassMDI
Inherits NativeWindow

Public Event LoadButton(ByVal hWnd As Integer)
Public Event RemoveButton(ByVal hWnd As Integer)

Private Const WM_MDICREATE = &H220
Private Const WM_MDIDESTROY = &H221

Protected Overloads Overrides Sub WndProc(ByRef m As Message)
'Process the needed messages
Select Case m.Msg
Case WM_MDICREATE
'Forward message to base WndProc
MyBase.WndProc(m)
Application.DoEvents()
RaiseEvent LoadButton(m.HWnd.ToInt32)
Case WM_MDIDESTROY
RaiseEvent RemoveButton(m.WParam.ToInt32)
'Forward message to base WndProc
MyBase.WndProc(m)
Case Else
'Forward message to base WndProc
MyBase.WndProc(m)
Debug.WriteLine(m.ToString())
End Select
End Sub
End Class

Am I doing anything wrong here?
I don't even see the message in the Debug window.

Does anyone have an alternativ for me?

BTW: The instance of SubclassMDI gets the handle of the MDIClient area by an
AssignHandle call.

--
Rene Mansveld
Spider IT - Germany (was Whitworth Software Solutions)
www.Spider-IT.de / www.Spider-IT.net / www.Spider-IT.org / www.Spider-IT.biz

Please reply to the newsgroup(s) :blush:)
 
G

Guest

Here's how I found it:


Dim x As String = " "
Declares.GetClassName(mdi.Handle, x, x.Length)
x = Replace(x, "Window.8", "MDICLIENT")
Dim hwnd As IntPtr = Declares.FindWindowEx(mdi.Handle, IntPtr.Zero, x, vbNullString)

where hwnd is th MDIClient and mdi is your mdi form
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top