Component needs a form's HWND

  • Thread starter Thread starter mikesnoise
  • Start date Start date
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-
 
Try using

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

to see if this is what you need.

=============
Clay Burch
Syncfusion, Inc.
 
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-
 
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.
 
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-
 
Mike,

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