P/Invoke to CreateWindowEx()

  • Thread starter Nandakumar Sankaran
  • Start date
N

Nandakumar Sankaran

I'm trying to create a native custom window through managed code.
Essentially I want to wrap a native custom window class into a managed
custom control. So I tried calling the Win32 API CreateWindowEx() using
P/Invoke. This API takes a parent window handle and since .NETCF's controls
do not expose a handle, I created a MessageWindow object and passed its HWnd
member to CreateWindowEx(). I obtained the instance handle through another
Win32API GetModuleHandle(null). The call to CreateWindowEx() succeeds and I
get a window handle as the return value. However the window never shows up
on the form!

The same code works fine on the desktop. The only change being that the
parent window handle is actually the Form.Handle member.

To reduce the number of unknowns, I tried the above on a standard EDIT
control with
the same results. What am I missing?

Nandakumar
 
N

Nandakumar Sankaran

That worked great! Thanks.

Out of academic interest, I'm curious why MessageWindow.HWnd was unable to
function successfully as a parent window.

Nandakumar


Tim Wilson said:
Get the handle in the following way:

//Declare the Win API GetCapture
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

//When you want to get the handle
<name of control>.Capture = true;
IntPtr hWnd = GetCapture();
<name of control>.Capture = false;

--
Tim Wilson
Windows Embedded MVP

Nandakumar Sankaran said:
I'm trying to create a native custom window through managed code.
Essentially I want to wrap a native custom window class into a managed
custom control. So I tried calling the Win32 API CreateWindowEx() using
P/Invoke. This API takes a parent window handle and since .NETCF's controls
do not expose a handle, I created a MessageWindow object and passed its HWnd
member to CreateWindowEx(). I obtained the instance handle through another
Win32API GetModuleHandle(null). The call to CreateWindowEx() succeeds
and
I
get a window handle as the return value. However the window never shows up
on the form!

The same code works fine on the desktop. The only change being that the
parent window handle is actually the Form.Handle member.

To reduce the number of unknowns, I tried the above on a standard EDIT
control with
the same results. What am I missing?

Nandakumar
 
T

Tim Wilson [MVP]

Because MessageWindow is not a visible control on the Form, and therefore,
anything assigned as a child would not be visible.

--
Tim Wilson
Windows Embedded MVP

Nandakumar Sankaran said:
That worked great! Thanks.

Out of academic interest, I'm curious why MessageWindow.HWnd was unable to
function successfully as a parent window.

Nandakumar


Tim Wilson said:
Get the handle in the following way:

//Declare the Win API GetCapture
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

//When you want to get the handle
<name of control>.Capture = true;
IntPtr hWnd = GetCapture();
<name of control>.Capture = false;

--
Tim Wilson
Windows Embedded MVP

Nandakumar Sankaran said:
I'm trying to create a native custom window through managed code.
Essentially I want to wrap a native custom window class into a managed
custom control. So I tried calling the Win32 API CreateWindowEx() using
P/Invoke. This API takes a parent window handle and since .NETCF's controls
do not expose a handle, I created a MessageWindow object and passed
its
HWnd
member to CreateWindowEx(). I obtained the instance handle through another
Win32API GetModuleHandle(null). The call to CreateWindowEx() succeeds
and
I
get a window handle as the return value. However the window never
shows
 
P

Peter Foot [MVP]

Unless you P/Invoke SetWindow etc API calls to manipulate the size and
behaviour of the MessageWindow in which case you can effectively turn it
into a panel to host native controls.

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
Handheld Interactive Reference Guides

Tim Wilson said:
Because MessageWindow is not a visible control on the Form, and therefore,
anything assigned as a child would not be visible.

--
Tim Wilson
Windows Embedded MVP

Nandakumar Sankaran said:
That worked great! Thanks.

Out of academic interest, I'm curious why MessageWindow.HWnd was unable to
function successfully as a parent window.

Nandakumar


Tim Wilson said:
Get the handle in the following way:

//Declare the Win API GetCapture
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

//When you want to get the handle
<name of control>.Capture = true;
IntPtr hWnd = GetCapture();
<name of control>.Capture = false;

--
Tim Wilson
Windows Embedded MVP

I'm trying to create a native custom window through managed code.
Essentially I want to wrap a native custom window class into a managed
custom control. So I tried calling the Win32 API CreateWindowEx() using
P/Invoke. This API takes a parent window handle and since .NETCF's
controls
do not expose a handle, I created a MessageWindow object and passed its
HWnd
member to CreateWindowEx(). I obtained the instance handle through another
Win32API GetModuleHandle(null). The call to CreateWindowEx()
succeeds
and
I
get a window handle as the return value. However the window never
shows
up
on the form!

The same code works fine on the desktop. The only change being that the
parent window handle is actually the Form.Handle member.

To reduce the number of unknowns, I tried the above on a standard EDIT
control with
the same results. What am I missing?

Nandakumar
 
T

Tim Wilson [MVP]

Yup :)

--
Tim Wilson
Windows Embedded MVP

Peter Foot said:
Unless you P/Invoke SetWindow etc API calls to manipulate the size and
behaviour of the MessageWindow in which case you can effectively turn it
into a panel to host native controls.

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
Handheld Interactive Reference Guides

Tim Wilson said:
Because MessageWindow is not a visible control on the Form, and therefore,
anything assigned as a child would not be visible.
unable
to
function successfully as a parent window.

Nandakumar


Get the handle in the following way:

//Declare the Win API GetCapture
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

//When you want to get the handle
<name of control>.Capture = true;
IntPtr hWnd = GetCapture();
<name of control>.Capture = false;

--
Tim Wilson
Windows Embedded MVP

I'm trying to create a native custom window through managed code.
Essentially I want to wrap a native custom window class into a managed
custom control. So I tried calling the Win32 API CreateWindowEx() using
P/Invoke. This API takes a parent window handle and since .NETCF's
controls
do not expose a handle, I created a MessageWindow object and
passed
its
HWnd
member to CreateWindowEx(). I obtained the instance handle through
another
Win32API GetModuleHandle(null). The call to CreateWindowEx() succeeds
and
I
get a window handle as the return value. However the window never shows
up
on the form!

The same code works fine on the desktop. The only change being
that
the
parent window handle is actually the Form.Handle member.

To reduce the number of unknowns, I tried the above on a standard EDIT
control with
the same results. What am I missing?

Nandakumar
 

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