#include <mil.h>
#include <windows.h>
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Board.mim")
#define WINDOW_TITLE MIL_TEXT("Custom Title")
void OverlayDraw(MIL_ID Display);
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilDigitizer=0,
MilImage;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
if (MsysInquire(MilSystem, M_DIGITIZER_NUM, M_NULL))
{
MdigAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDigitizer);
MbufAllocColor(MilSystem,
MdigInquire(MilDigitizer,M_SIZE_BAND,M_NULL),
MdigInquire(MilDigitizer,M_SIZE_X,M_NULL),
MdigInquire(MilDigitizer,M_SIZE_Y,M_NULL),
8+M_UNSIGNED,
M_IMAGE+M_DISP+M_PROC+M_GRAB,
&MilImage);
MbufClear(MilImage, 0);
}
else
{
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
}
MdispControl(MilDisplay, M_TITLE, M_PTR_TO_DOUBLE(WINDOW_TITLE));
MdispSelect(MilDisplay, MilImage);
OverlayDraw(MilDisplay);
if (MilDigitizer)
MdigGrabContinuous(MilDigitizer, MilImage);
MosPrintf(MIL_TEXT("\nOVERLAY ANNOTATIONS:\n"));
MosPrintf(MIL_TEXT("--------------------\n\n"));
MosPrintf(MIL_TEXT("Displaying an image with overlay annotations.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
if (MilDigitizer)
{
MdigHalt(MilDigitizer);
MdigFree(MilDigitizer);
MosPrintf(MIL_TEXT("Displaying the last grabbed image.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
}
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}
void OverlayDraw(MIL_ID MilDisplay)
{
MIL_ID MilOverlayImage;
MIL_INT ImageWidth, ImageHeight;
int Count;
HDC hCustomDC;
HGDIOBJ hpen, hpenOld;
MIL_TEXT_CHAR chText[80];
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MdispControl(MilDisplay, M_OVERLAY_SHOW, M_DISABLE);
ImageWidth = MbufInquire(MilOverlayImage, M_SIZE_X, M_NULL);
ImageHeight = MbufInquire(MilOverlayImage, M_SIZE_Y, M_NULL);
MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);
MgraColor(M_DEFAULT, M_COLOR_WHITE);
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth/9, ImageHeight/5,
MIL_TEXT(" -------------------- "));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth/9, ImageHeight/5+25,
MIL_TEXT(" - MIL Overlay Text - "));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth/9, ImageHeight/5+50,
MIL_TEXT(" -------------------- "));
MgraColor(M_DEFAULT, M_COLOR_GREEN);
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth*11/18, ImageHeight/5,
MIL_TEXT(" ---------------------"));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth*11/18, ImageHeight/5+25,
MIL_TEXT(" - MIL Overlay Text - "));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth*11/18, ImageHeight/5+50,
MIL_TEXT(" ---------------------"));
MdispControl(MilDisplay, M_OVERLAY_SHOW, M_ENABLE);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MbufControl(MilOverlayImage, M_DC_ALLOC, M_DEFAULT);
hCustomDC = ((HDC)MbufInquire(MilOverlayImage, M_DC_HANDLE, M_NULL));
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
if (hCustomDC)
{
POINT Hor[2];
POINT Ver[2];
SIZE TxtSz;
RECT Txt;
hpen=CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
hpenOld = SelectObject(hCustomDC, hpen);
Hor[0].x = (MIL_INT32)0;
Hor[0].y = (MIL_INT32)(ImageHeight/2);
Hor[1].x = (MIL_INT32)ImageWidth;
Hor[1].y = (MIL_INT32)(ImageHeight/2);
Polyline(hCustomDC, Hor,2);
Ver[0].x = (MIL_INT32)(ImageWidth/2);
Ver[0].y = (MIL_INT32)0;
Ver[1].x = (MIL_INT32)(ImageWidth/2);
Ver[1].y = (MIL_INT32)ImageHeight;
Polyline(hCustomDC, Ver,2);
SelectObject(hCustomDC, hpenOld);
DeleteObject(hpen);
SetBkMode(hCustomDC, TRANSPARENT);
MosStrcpy(chText, 80, MIL_TEXT("GDI Overlay Text"));
Count = (int) MosStrlen(chText);
GetTextExtentPoint(hCustomDC, chText, Count, &TxtSz);
Txt.left = (MIL_INT32)(ImageWidth*3/18);
Txt.top = (MIL_INT32)(ImageHeight*17/24);
Txt.right = (MIL_INT32)(Txt.left + TxtSz.cx);
Txt.bottom = (MIL_INT32)(Txt.top + TxtSz.cy);
SetTextColor(hCustomDC,RGB(255, 0, 0));
DrawText(hCustomDC, chText, Count, &Txt, DT_RIGHT);
Txt.left = (MIL_INT32)ImageWidth*12/18;
Txt.top = (MIL_INT32)ImageHeight*17/24;
Txt.right = (MIL_INT32)(Txt.left + TxtSz.cx);
Txt.bottom = (MIL_INT32)(Txt.top + TxtSz.cy);
SetTextColor(hCustomDC, RGB(255, 255, 0));
DrawText(hCustomDC, chText, Count, &Txt, DT_RIGHT);
MbufControl(MilOverlayImage, M_DC_FREE, M_DEFAULT);
MbufControl(MilOverlayImage, M_MODIFIED, M_DEFAULT);
}
}