Problem WebMFDs

timelzayus

New member
Joined
Aug 7, 2010
Messages
10
Reaction score
0
Points
0
Hi all !
I have discovered Orbiter 2 weeks ago and I find it tremendous !
Being a developper, I thought I could develop a bit for Orbiter.

Here's my idea :
I would like to use MFDs in other PCs (especially my touch netbook). Currently, the only way to export MFDs over network has to be integrated in a ship, which is not very useful. I also tried solutions like VNC or MaxiVista with ExtMFD but there's alway the input problem : I can't touch / modify my external MFD and handle my ship in the same way as the coputer sees only one input.
Being a Web expert (HTML5 / Javascript and all) I figured : How about creating a plugin that would create a small web server (using the mongoose library) which would display the MFD and its button : there would be no need for a client, any web browser would do it. That would permit to have acces to the MFDs on any computer as well as on any tablet (like the iPad) or any othe device that has a web browser.

The thing is : I have troubles exporting the MFD display. I know it is possible : the module ExtMFD does it.
I am not bad in C/C++ (5 years of studying it) but I usually program only with cross-platform libraries (mainly with QT, boost, etc.) so I have absolutely no knowledge of MFC and GDI.
I have started a new module project copying the ExtMFD module sources.
The first step for me to do this module is to be able to export the MFD in a jpeg file (as I figured using the m-jpeg format over http would be a nice solution to display the MFD in a browser).
Here is what I have done so far : I have added a button marked "save" on the popup, this puts a bool save to true when it is clicked.
Then, I have added this code to the MFDWindow::RepaintDisplay method (my code is in red) :
Code:
void MFDWindow::RepaintDisplay(HWND hWnd)
{
	PAINTSTRUCT ps;
	HDC hDCtgt = BeginPaint(hWnd, &ps);
	SURFHANDLE surf = GetDisplaySurface();
	if (surf)
	{
		HDC hDCsrc = oapiGetDC(surf);
 		BitBlt(hDCtgt, 0, 0, DW, DH, hDCsrc, 0, 0, SRCCOPY);
		oapiReleaseDC(surf, hDCsrc);

		[COLOR="Red"][B]if (save == true)
		{
			save = false;
			using namespace Gdiplus;

			Graphics* grph = Graphics::FromHDC(hDCtgt);
			Bitmap bmp(DW, DH, grph);
			CLSID clsid;
			GetEncoderClsid(L"image/jpeg", &clsid);
			bmp.Save(L"MFD.jpg", &clsid);
			OutputDebugString("MFD SAVED\r\n");
			delete grph;
		}[/B][/COLOR]
	}
	else
	{
		SelectObject(hDCtgt, GetStockObject (BLACK_BRUSH));
		Rectangle(hDCtgt, 0, 0, DW, DH);
	}
 	EndPaint(hWnd, &ps);
}
It creates me a jpeg file, but the image is all black, nothing's on it.
I can't figure what I missed, could someone help me ?
I am completely stuck with this issue and I passed the entire afternoon reading the MSDN library, I could not find my mistake....
Thank you for helping !
 

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
i really can't tell from that snippet... but it may be a problem related to the fact that you're using GDIplus, while orbiter uses good 'ole GDI.... some compatibility issue, perhaps?


also, (i just might be shooting in the dark here) i hear that blitting operations should not be done with the device acquired... so i'd advise you to have the release line put before the blit call :rolleyes:
 

timelzayus

New member
Joined
Aug 7, 2010
Messages
10
Reaction score
0
Points
0
I searched but I could not find a way to transform a GDI Device Context (HDC) into a JPEG or BMP file other than using GDI+.

The code I added is in red. Having the bitblt operation before the release is not my code, it's Martin's.

---------- Post added at 05:32 PM ---------- Previous post was at 04:48 PM ----------

Finally found out :

Code:
void MFDWindow::RepaintDisplay(HWND hWnd)
{
	PAINTSTRUCT ps;
	HDC hDCtgt = BeginPaint(hWnd, &ps);
	SURFHANDLE surf = GetDisplaySurface();
	if (surf)
	{
		HDC hDCsrc = oapiGetDC(surf);
 		BitBlt(hDCtgt, 0, 0, DW, DH, hDCsrc, 0, 0, SRCCOPY);

		[B][COLOR="Red"]if (save == true)
		{
			save = false;

			HDC cdc = CreateCompatibleDC(hDCsrc);
			HBITMAP cbm = CreateCompatibleBitmap(hDCsrc,DW, DH);
			HBITMAP oldbm = (HBITMAP)SelectObject(cdc, cbm);
			BitBlt(cdc, 0, 0, DW, DH, hDCsrc, 0, 0, SRCCOPY);
			SelectObject(cdc, oldbm);

			CImage img;
			img.Attach(cbm);
			img.Save(_T("MFC.jpg"), Gdiplus::ImageFormatJPEG);

			OutputDebugString("MFD SAVED\r\n");
		}[/COLOR][/B]

		oapiReleaseDC(surf, hDCsrc);
	}
	else
	{
		SelectObject(hDCtgt, GetStockObject (BLACK_BRUSH));
		Rectangle(hDCtgt, 0, 0, DW, DH);
	}
 	EndPaint(hWnd, &ps);
}

It's working !
Thank you for your help !
 
Top