void PDC::ShowReverseTrace(void)
{
//get the file path
TCHAR moduleDir[260];
TCHAR PicPath[260];
GetModuleDir_pdc(moduleDir);
wcscpy(PicPath, L"\\");
wcscat(PicPath, moduleDir+1);
//set the camera visual degree
if(isCamerahighAngle)
wcscat(PicPath,RC_Array[traceIndex]);
else
wcscat(PicPath,RC_Array_EX[traceIndex]);
//display the picture by path ,and decode the file (if not bmp )
{
IImage *pImg = NULL;
ImageInfo imgInfo;
int pix_format;
RECT bmp_rect;
IBitmapImage *pBitmap;
BitmapData bmpData = {0};
HBITMAP hbmp = NULL;
int bits_pixel;
BOOL bRet = FALSE;
BITMAP bmpinfo;
if(m_hdcTrace == NULL)
{
if (hbmp)
{
DeleteObject(hbmp);
}
}
//by source display
//hbm = (HBITMAP)LoadImage(hInstance, lpstrResID, IMAGE_BITMAP, 0, 0, 0); //from resource
{
//init COM,isComInit_Pdc is a flag make init action do only once
if(FALSE==isComInit_Pdc)
{
HRESULT hRet;
if (FAILED(hRet = CoInitializeEx(NULL, COINIT_MULTITHREADED)))
{
printf("CoInitializeEx failed!");
return ;
}
if (FAILED(hRet = CoCreateInstance(CLSID_ImagingFactory,NULL,CLSCTX_INPROC_SERVER,IID_IImagingFactory,(void**)&g_pImagingFactory_pdc)))
{
printf("CoCreateInstance failed!");
return ;
}
isComInit_Pdc = TRUE;
printf("wince com init once\r\n");
}
//image decode
HDC temphdc = ::GetDC(NULL);
bits_pixel = GetDeviceCaps (temphdc, BITSPIXEL); //get the device color depth 16 or 32
::ReleaseDC(NULL, temphdc);
UINT32 t_u4Result = g_pImagingFactory_pdc->CreateImageFromFile(PicPath,&pImg);
if (t_u4Result != S_OK || pImg == NULL)
{
PRINTF_WRONG("t_u4Result != S_OK || pImg == NULL")
return;
}
pImg->GetImageInfo(&imgInfo);
pix_format = (bits_pixel==16) ? PIXFMT_16BPP_RGB565 : PIXFMT_32BPP_ARGB;
g_pImagingFactory_pdc->CreateBitmapFromImage(pImg,imgInfo.Width, imgInfo.Height,pix_format,InterpolationHintDefault,&pBitmap);
SetRect(&bmp_rect, 0,0,imgInfo.Width,imgInfo.Height);
pBitmap->LockBits(&bmp_rect, ImageLockModeRead, pix_format, &bmpData); //get the pic binary data to bmpData
hbmp = CreateBitmap(imgInfo.Width, imgInfo.Height, 1,bits_pixel, bmpData.Scan0); //从位图数据bmpData.Scan0创建HBITMAP
}
if(hbmp == NULL)
{
printf("SHLoadDIBitmap %S failed!!\n",PicPath);
m_hdcTrace = NULL;
if (hbmp)
{
DeleteObject(hbmp);
}
}
//获得bitmap大小信息
GetObject(hbmp,sizeof(BITMAP),&bmpinfo);
m_rcTrace.left = 0;
m_rcTrace.top = 0;
m_rcTrace.right = bmpinfo.bmWidth;
m_rcTrace.bottom = bmpinfo.bmHeight;
m_hdcTrace = CreateCompatibleDC(NULL);
SelectObject(m_hdcTrace, hbmp);
if(NULL!=hbmp)
{
DeleteObject(hbmp);
}
if(NULL!=pImg)
{
DeleteObject(pImg);
}
if(NULL!=pBitmap)
{
DeleteObject(pBitmap);
}
bRet = TRUE;
if(!bRet)
{
return ;
}
}
//if( !bRet1)
// return ;
if(FALSE==isRevTraceInit)
{
UIHdc *pHdc=NULL;
UI_HDC_DATA hdc_data;
RECT rt={0,0,800,480};
hdc_data.hdcRect=rt;
hdc_data.szHdcName=L"HDC_TRACE";
pHdc = CreateHdc(g_hinst,&hdc_data);
if(NULL!=pHdc)
{
pHdcTrace=pHdc;
}
UI_BUTTON_DATA button_data;
button_data.iPosX =100;
button_data.iPosY =20;
button_data.CallFunc =OnTouchButton;
button_data.szButtonName =L"TRACE_BUTTON";
button_data.wButtonBmpDownResID =L"IDB_BITMAP_TRACE_BUTTON_FREE";
button_data.wButtonBmpResID =L"IDB_BITMAP_TRACE_BUTTON_SEL";
pTraceButton=CreateButton(qtQpcpp_inst, &button_data);
if(NULL!=pTraceButton)
{
pTraceButton->SetVisible(FALSE);
}
isRevTraceInit=TRUE;
printf("trace dc and button init once\r\n");