Component needs a form's HWND

M

mikesnoise

I am writing a class derived from Component that calls a Win32
function to display a dialog box. The Win32 function takes an HWND as
the parent window of the dialog box (for positioning the dialog over
the parent). How do I get the HWND of the form that it was dropped on?

Thanks,
-Mike-
 
C

ClayB

Try using

IntPtr HWND = this.Handle; //this refers to the Form.

to see if this is what you need.

=============
Clay Burch
Syncfusion, Inc.
 
M

mikesnoise

Try using

IntPtr HWND = this.Handle; //this refers to the Form.

to see if this is what you need.

=============
Clay Burch
Syncfusion, Inc.

I'm writing a class derived from Component. I want it to be able to
figure out the form's handle. The this keyword would be the Component,
not the form. In other words I don't want to expose a property to
specify the HWND -- I want this to be automatic like the
FileOpenDialog component.

-Mike-
 
J

Jeff Gaines

On 14/02/2007 in message
<[email protected]>
I'm writing a class derived from Component. I want it to be able to
figure out the form's handle. The this keyword would be the Component,
not the form. In other words I don't want to expose a property to
specify the HWND -- I want this to be automatic like the
FileOpenDialog component.

-Mike-

In cases like this I use a constructor that takes the parent form as a
parameter.
 
M

mikesnoise

In cases like this I use a constructor that takes the parent form as a
parameter.

Yeah, I could do that. But I'm really trying to emulate the
System.Windows.Forms.OpenFileDialog (I mistakenly called it the
FileOpenDialog component in a previous post). I looked in the
documentation and found that FileOpenDialog has two overloads of
ShowDialog: ShowDialog() and ShowDialog(IWin32Window). I guess
ShowDialog() probably calls GetOpenFileName() with a NULL owner HWND
while ShowDialog(IWin32Window) provides the parameter's HWND. I always
assumed that somehow the component was able to get the HWND of the
containing form. Does anyone know if ShowDialog() does any trick to
get the HWND or if it just passes NULL?

Thanks for all your help!
-Mike-
 
S

Stoitcho Goutsev \(100\)

Mike,

Common dialogs use GetActiveWindow API if parent window is not provided.
 

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