GetHdc in CF ???

  • Thread starter Thread starter ORC
  • Start date Start date
O

ORC

I have made a custum control (a graph control) and imported all the
neccesary Dll's (I think) like createpen, polyline and deleteobject. In the
OnPaint function I found the e.graphic.GetHdc ---Great .....but but but -
it's not implemented in CF like all the other useful fiunctions that is
missing in CF.
How do I then get a Hdc? I'm using C# and the graph control is defined as
this:
public Graph : Control
{
code......
}

Any help is highly appreciated.

Thanks
Ole
 
You can get the native window handle from a form or control by using

this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;

[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

Then you can P/Invoke GetDC passing in this handle e.g.
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);

IntPtr hdc = GetDC(hwnd);

Peter
 
Thanks. I can't unfortunately get the below suggestion to work. I get the
hwnd allright but the corrosponding hdc is null. I have entered all the code
in my controls code - is that how to do it??

Thanks
Ole

Peter Foot said:
You can get the native window handle from a form or control by using

this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;

[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

Then you can P/Invoke GetDC passing in this handle e.g.
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);

IntPtr hdc = GetDC(hwnd);

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

ORC said:
I have made a custum control (a graph control) and imported all the
neccesary Dll's (I think) like createpen, polyline and deleteobject. In
the
OnPaint function I found the e.graphic.GetHdc ---Great .....but but but -
it's not implemented in CF like all the other useful fiunctions that is
missing in CF.
How do I then get a Hdc? I'm using C# and the graph control is defined as
this:
public Graph : Control
{
code......
}

Any help is highly appreciated.

Thanks
Ole
 
With a slight modification to
[DllImport("coredll.dll", SetLastError=true)]
private static extern IntPtr GetDC(IntPtr hwnd);

What does Marshal.GetLastWin32Error() return after a call to GetDC results
in IntPtr.Zero?

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

ORC said:
Thanks. I can't unfortunately get the below suggestion to work. I get the
hwnd allright but the corrosponding hdc is null. I have entered all the
code
in my controls code - is that how to do it??

Thanks
Ole

Peter Foot said:
You can get the native window handle from a form or control by using

this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;

[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

Then you can P/Invoke GetDC passing in this handle e.g.
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);

IntPtr hdc = GetDC(hwnd);

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

ORC said:
I have made a custum control (a graph control) and imported all the
neccesary Dll's (I think) like createpen, polyline and deleteobject. In
the
OnPaint function I found the e.graphic.GetHdc ---Great .....but but but -
it's not implemented in CF like all the other useful fiunctions that is
missing in CF.
How do I then get a Hdc? I'm using C# and the graph control is defined as
this:
public Graph : Control
{
code......
}

Any help is highly appreciated.

Thanks
Ole
 
Hi Peter,

By implemeting the getlasterror I got my eyes on a real error 40 bug - I
forgot to remove the 'IntPtr' in this line:
IntPtr hdc = GetDC(hwnd);
because the hdc is also allocated globally but will never be reached.

It now all works! Thank you very much for your help!

Ole

Peter Foot said:
With a slight modification to
[DllImport("coredll.dll", SetLastError=true)]
private static extern IntPtr GetDC(IntPtr hwnd);

What does Marshal.GetLastWin32Error() return after a call to GetDC results
in IntPtr.Zero?

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

ORC said:
Thanks. I can't unfortunately get the below suggestion to work. I get the
hwnd allright but the corrosponding hdc is null. I have entered all the
code
in my controls code - is that how to do it??

Thanks
Ole

Peter Foot said:
You can get the native window handle from a form or control by using

this.Capture = true;
IntPtr hwnd = GetCapture();
this.Capture = false;

[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

Then you can P/Invoke GetDC passing in this handle e.g.
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);

IntPtr hdc = GetDC(hwnd);

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

I have made a custum control (a graph control) and imported all the
neccesary Dll's (I think) like createpen, polyline and deleteobject. In
the
OnPaint function I found the e.graphic.GetHdc ---Great .....but but but -
it's not implemented in CF like all the other useful fiunctions that is
missing in CF.
How do I then get a Hdc? I'm using C# and the graph control is
defined
as
this:
public Graph : Control
{
code......
}

Any help is highly appreciated.

Thanks
Ole
 
Back
Top