casting hwnd to windows form handle

  • Thread starter Thread starter The Real Andy
  • Start date Start date
T

The Real Andy

Sorry if this question sounds stupid, its early days for me when it
comes to c# and com interop.

I have a method imported from Win Media PLayer SDK,
IWMPPluginUI:DisplayPropertyPage, like so:

void DisplayPropertyPage(IntPtr hwndParent)

I need to pass hwndParent to a dialog, but I cant for the life of me
figure out how to cast it to a windows.forms.form handle.

I am trying to acheive something like this:

void DisplayPropertyPage(IntPtr hwndParent)
{
m_properties = new UIPropertiesDialog();
m_properties.Parent = hwndParent // CAST HERE
m_properties.ShowDialog();
}

Am I heading down the wrong path?

Andy
 
Write a class that implements IWin32Window and wraps your IntPtr
window handle. Then call m_properties.ShowDialog(IWin32Window)
instead.



Mattias
 
Write a class that implements IWin32Window and wraps your IntPtr
window handle. Then call m_properties.ShowDialog(IWin32Window)
instead.

OK, I got all excited and went straight to the MSDN to look up
IWin32Window. From what I can understand is that this class exposes a
HWND handle. Maybe I am trying to bite off more than I can chew!

What I dont understand is how I can write a class that wraps up the
IntPtr when this is being passed in from a COM method?

I kinda feel stupid asking. I have been trying to work this out for
three nights now and i am starting to pull my hair out. I think I am
going to but that suggesed book of your website Mattias.

Regards:

Andy
 
On Tue, 30 Nov 2004 19:40:13 +1000, The Real Andy

Something like this perhaps?

public class WMPHandle : IWin32Window
{
public IWin32Window MediaPlayerHandle
{
get
{
return (getWMP(HWND));
}
}
}

Am I getting closer? How do implement getWMP(HWND) or am I on the
wrong track?

Then call,

m_properties.ShowDialog(WMPHandle.MediaPlayerHandle)
 
Andy,

If you are passing the handle into your DisplayPropertyPage method, then
why not have your WMPHandle class have a constructor that takes that IntPtr
value, and then returns that. Then, when you show the dialog, pass the
WMPHandle instance into the ShowDialog method.

Hope this helps.
 
Andy,

If you are passing the handle into your DisplayPropertyPage method, then
why not have your WMPHandle class have a constructor that takes that IntPtr
value, and then returns that. Then, when you show the dialog, pass the
WMPHandle instance into the ShowDialog method.

Hope this helps.

That makes complete sense. I was getting tired and frustrated last
night, helps to walk away when you get like that. I'll have a go at
that tonight.

May I ask another question, Is there a good beginners group where
someone like me can ask lots of silly questions? Or am I welcome to
post here? I am sure I will have a lot to ask over the next few
months.

Regards:

Andrew
 
Back
Top