Small Problem with Type Casting

  • Thread starter Thread starter Tibby
  • Start date Start date
T

Tibby

Okay, here's my calling code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mdiClient = New MDIClientWindow(Me, Me.Handle) '**
SetClassLong(mdiClient.Handle, GCL_HBRBACKGROUND, 0)
End Sub ' End Form1_Load

Here's the Code Being Called:

Public Sub New(ByVal i As IMDIClientNotify, ByVal handle As IntPtr)
'Find the MDI Client window handle:
GetWindows(handle)
If Not hWndMdiClient.ToInt32 = IntPtr.Zero.ToInt32 Then
MyBase.AssignHandle(hWndMdiClient)
End If
notify = i
End Sub ' End Sub New

And here is the Interface:

Public Interface IMDIClientNotify
Sub WndProc(ByRef m As Message, ByRef doDefault As Boolean)
End Interface

Here's the origional C# code for the above functions:

private void mfrmMDIClientPaint_Load(object sender, System.EventArgs e)
{
// Start processing for MDIClient window messages:
mdiClient = new MDIClientWindow(this, this.Handle);
// Stop the default window proc from drawing the MDI background
// with the brush:
UnManagedMethods.SetClassLong(
mdiClient.Handle,
UnManagedMethods.GCL_HBRBACKGROUND,
0);
}

public MDIClientWindow(IMDIClientNotify i, IntPtr handle)
{
// Find the MDI Client window handle:
GetWindows(handle);
if (hWndMdiClient != IntPtr.Zero)
{
this.AssignHandle(hWndMdiClient);
}
this.notify = i;
}

public interface IMDIClientNotify
{
void WndProc(ref Message m, ref bool doDefault);
}

The '** Mark is where things go heywire!

"Additional information: Specified cast is not valid." is the exact error
that comes up, if that helps...

Thanks again,
Sueffel
 
Tibby said:
mdiClient = New MDIClientWindow(Me, Me.Handle) '**

The '** Mark is where things go heywire!

"Additional information: Specified cast is not valid." is the exact error
that comes up, if that helps...

What is the full message? What are the source and destination types of the
cast? What's the type of mdiClient? Is it "MDIClientWindow" or one of it's
base classes? Did you enable Option Strict?
 
Armin Zingler said:
What is the full message? What are the source and destination types of the
cast? What's the type of mdiClient? Is it "MDIClientWindow" or one of it's
base classes? Did you enable Option Strict?


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Not sure if I can answer those questions, I'm flying blind as is! LOL
But, I can zip up the project and attach it here. I do know that option
strict is off at the moment. I know how much people love it when there's
binary data attached to a thread. But anyhew, I'm trying to implement this
as a nifty to take away the boring MDI Interface and make it look a little
more snatzy.

Thanks again,
Sueffel
 
Armin Zingler said:
You did not enable Option Strict!

You get the exception because Form1 does not implement IMDIClientNotify.
Implement the interface and the project will be compilable (after removing
the other two errors).


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

That was the one thing I was missing, the implementation! Thank you
sooooooo much! No I just have to figure out the PInvoke Errors and I'm good
to go!

Thanks again,
Tibby

PS - Sorry bout the Option Strict, I have a long time aversion to it.
 
Sueffel said:
That was the one thing I was missing, the implementation! Thank you
sooooooo much! No I just have to figure out the PInvoke Errors and I'm good
to go!

Thanks again,
Tibby

PS - Sorry bout the Option Strict, I have a long time aversion to it.

BTW, how can I trap a "Unhandled exception of type
'System.StackOverflowException' occured in system.dll" ? I know that that
one has something to do with circular reference, but I'm not seeing it...
*sigh* All kinds of nifty errors with this code. Unfortunatly, I don't have
the time to "Learn" what is going on, so I may have to scrap this project
:(

Thanks again
Sueffel
 
Sueffel said:
That was the one thing I was missing, the implementation! Thank
you sooooooo much! No I just have to figure out the PInvoke Errors
and I'm good to go!


....and:
Why do you need pInvoke here? Native window sub classing is often not
necessary anymore. You can override WndProc.
 
Armin Zingler said:
...and:
Why do you need pInvoke here? Native window sub classing is often
not necessary anymore. You can override WndProc.

Ignore my message... you do override windproc.
 
Armin Zingler said:
...and:
Why do you need pInvoke here? Native window sub classing is often not
necessary anymore. You can override WndProc.

API Calls... That is the example that was shown to me.... I'm not spiffey
with graphics, try to avoid them if possible actually, but I just thought it
would be a nice touch to the GUI, but I do have time contraints and can go
back later and insitute it.... Or maybe just take the origional C# code,
throw it into a DLL, and inherit from that.?.?. That may not work. Hmmmmmm

Thanks agian,
Sueffel
 
Back
Top