473,806 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

casting hwnd to windows form handle

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:Di splayPropertyPa ge, like so:

void DisplayProperty Page(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.f orm handle.

I am trying to acheive something like this:

void DisplayProperty Page(IntPtr hwndParent)
{
m_properties = new UIPropertiesDia log();
m_properties.Pa rent = hwndParent // CAST HERE
m_properties.Sh owDialog();
}

Am I heading down the wrong path?

Andy

Nov 16 '05 #1
5 12250

Write a class that implements IWin32Window and wraps your IntPtr
window handle. Then call m_properties.Sh owDialog(IWin32 Window)
instead.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
On Tue, 30 Nov 2004 08:56:12 +0100, Mattias Sjögren
<ma************ ********@mvps.o rg> wrote:

Write a class that implements IWin32Window and wraps your IntPtr
window handle. Then call m_properties.Sh owDialog(IWin32 Window)
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
Nov 16 '05 #3
On Tue, 30 Nov 2004 19:40:13 +1000, The Real Andy
<.pearson@wayit _dot_com_dot_au _remove_the_obv ious_to_reply> wrote:

Something like this perhaps?

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

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

Then call,

m_properties.Sh owDialog(WMPHan dle.MediaPlayer Handle)

On Tue, 30 Nov 2004 08:56:12 +0100, Mattias Sjögren
<ma*********** *********@mvps. org> wrote:

Write a class that implements IWin32Window and wraps your IntPtr
window handle. Then call m_properties.Sh owDialog(IWin32 Window)
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


Nov 16 '05 #4
Andy,

If you are passing the handle into your DisplayProperty Page 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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"The Real Andy" <.pearson@wayit _dot_com_dot_au _remove_the_obv ious_to_reply>
wrote in message news:ej******** *************** *********@4ax.c om...
On Tue, 30 Nov 2004 19:40:13 +1000, The Real Andy
<.pearson@wayit _dot_com_dot_au _remove_the_obv ious_to_reply> wrote:

Something like this perhaps?

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

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

Then call,

m_properties.Sh owDialog(WMPHan dle.MediaPlayer Handle)

On Tue, 30 Nov 2004 08:56:12 +0100, Mattias Sjögren
<ma********** **********@mvps .org> wrote:

Write a class that implements IWin32Window and wraps your IntPtr
window handle. Then call m_properties.Sh owDialog(IWin32 Window)
instead.


OK, I got all excited and went straight to the MSDN to look up
IWin32Windo w. 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

Nov 16 '05 #5
On Tue, 30 Nov 2004 14:02:50 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c om> wrote:
Andy,

If you are passing the handle into your DisplayProperty Page 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
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4177
by: Tamir Khason | last post by:
I need to fetch hWnd IntPtr of the form, which hold user control from inside the user control. How to do this. this.Handle returns wrong results. Another question form the same field: I want to use ONE and ONLY ONE Interoped ActiveX on my control. So in the control I make static axControl wich get hWnd of the windows to show itself. I override all disposes (to keep the instance) and make dispose on main application, BUT when openning...
3
11048
by: Andrew Moore | last post by:
Hi All, I have a managed C++ class that makes calls into the Win32 API. I specifically am trying to take a Handle from a .NET form and convert it to a HWND to pass to a Win32 functions. The code works properly but I get the following compiler warning: warning C4312: 'reinterpret_cast' : conversion from 'int' to 'HWND' of greater size.
3
1982
by: None | last post by:
Hi, How do I get an HWND for an aspx page? like System.Windows.Forms.Form.ActiveForm.Handle.ToInt32() in Windows Forms. If anybody knows solution please let me know it. Thanks, Vinoth
1
1898
by: Edward Diener | last post by:
How do I convert a System::IntPtr returned by .net as a handle to an actual Win32 handle like an HWND ? Attempts to use static_cast<HWND>(anIntPtr) do not work.
1
12323
by: MultiMarine | last post by:
Hello I have just started using .NET and C# from a c++ background using win32. Now i want to do something that i used to do, without using the win32 API. I use Spy++ to get a HWND from another application in hex form from a RICHEDIT control. now i want to turn this hex value (HWND) into a control in C#.
2
7149
by: Gary | last post by:
Hi i need to work with windows of processes that are running on my pc from a certain programme. I've figured out how to build an array of processes that contain just the processes i'm interested in by checking what the process name starts with. How do i find out the hWnd for the processes i've returned, because the function i need to run wants me to pass it the hWnd of the processes. Here's what I have so far, using notepad as my...
15
30121
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
How can I pass a C++ HWND to and from C# and Managed C++?
16
2012
by: ink | last post by:
Hi all, If I have a Windows 32 pointer to and object (Handle) and I know what that object is (Button) can I some how cast that pointer to a type of System.Windows.Forms.Button and then use its methods and properties? I am using C# compact framework 2.0 I have obtained the handle using the Windows 32 API and PInvoce. I am using one dot.net application to control another application.
11
4641
by: =?ISO-8859-15?Q?Kolja_M=E4rtens?= | last post by:
Hello! I've been professionally working on java projects for several years, but have done extremely little C/C++ coding and just a few little things in VB.Net. Right now I'm trying to write a Windows Service in VC++ .Net thats supposed to use a 3rd party SDK do receive Image data and send it out through a webservice.
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10623
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10373
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.