1

I'm writing an .NET DLL for a Clarion (Clarion is a C++ type language) program. The Clarion program calls a .NET DLL method passing to it the HWND of a Clarion image control. In the .NET DLL I can get the correct RECT (Top, Right, Bottom, Left) from the passed in HWND so I know I have the correct HWND.

What I cannot seem to find out is in the .NET DLL write a bitmap to the HWND. On the Clarion side, I would simply do this:

?myImageControl{PROP:ImageBits} = ImageBytes

where ImageBytes is an array of bytes, such as a file or a Clarion STRING (fixed length, not zero terminated).

Thanks in advance.

RFM
  • 93
  • 7
  • `HDC hdc = GetDC(hwnd);` and `SetPixel(hdc, x, y, RGB(255,255,255));`? This uses Win32 from C++ but may help: http://www.falloutsoftware.com/tutorials/win/win3.htm Of course `BitBlt()` will likely be faster... –  Jul 10 '13 at 18:08
  • Thanks, but I need to know how to do this in C#. C# does not recognize HDC, GetDC, etc. Maybe there is a way to get C# to recognize them but I don't know how to do that at this time. If I was writing in C++, this would be simple. – RFM Jul 10 '13 at 18:56
  • Use P/Invoke or C++/CLI interop. See: http://msdn.microsoft.com/en-us/library/aa288468%28v=vs.71%29.aspx –  Jul 10 '13 at 19:21

1 Answers1

0

I suppose you could try: Graphics.FromHwnd():

Image image = new Bitmap("somefile.bmp");
using (Graphics g = Graphics.FromHwnd(intptrHwnd))
{
    g.DrawImage(image, new Point(0, 0));
}

see: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromhwnd.aspx

  • I gave the above a try, substituting valid values of course, and though all lines execute without error, I have a try-catch surrounding it, no image appears. The control is a Clarion IMAGE control and from the handle I can determine it's size in C#. After that didn't work, I added the Clarion code DISPLAY(?ImageControl) and that didn't help. – RFM Jul 18 '13 at 19:57
  • @RFM I'm trying to remember if the Point is relative to the screen or the window. Can you move the window to the far upper left corner of your display area and see if that makes any difference? –  Jul 19 '13 at 01:17
  • I moved the window to the upper left, then had it draw the image, no image appeared. It is possible that Clarion's IMAGE control is not the standard winforms image control, but I haven't found any documentation on it. I'm currently using a callback (http://stackoverflow.com/questions/17578527/net-dll-needs-to-receive-a-clarion-callback-procedure-and-then-all-it-passing-t) to get the image displayed in Clarion, but would rather be able to directly display the image in C#. – RFM Jul 19 '13 at 13:17
  • @RFM Is there a way to tell if Clarion is giving you a "top level" window versus just a sub-control of some kind? It could be .FromHwnd() only works with the top level window. Maybe there's a way to get the parent HWND before passing it in? Also, I'm not 100% sure whether .FromHwnd() will work successfully with basic win32 controls that aren't WinForms controls. –  Jul 19 '13 at 16:17
  • I cannot find anything in that regards. Will simply have to resort to the callback method until someone comes along that knows the makings of the Clarion IMAGE control well enough to know whether or not what I'm attempting is even possible, and if so, how it is accomplished. Thanks for your input. – RFM Jul 20 '13 at 12:47