Page 1 of 1
How can OSD show text with c++
Posted: Wed May 22, 2013 7:40 am
by zixi0007
This is my code of osd show. But I don't know how to do.
Any one who can help me!
Code: Select all
TOSDSurface osd;
osd.dwSize = sizeof(osd);
osd.dwHeight = 50;
osd.dwWidth = 400;
osd.dwTop = 1;
osd.dwLeft = 1;
osd.Transparency = 1;
int hOSD = SendMessage(hwndDD, WM_MODULE_MSG, DDMODAPI_OSD_CREATE_SURFACE, (LPARAM)&osd);
HBITMAP bmSurface = (HBITMAP)SendMessage(hwndDD, WM_MODULE_MSG, DDMODAPI_OSD_GET_SURFACE_BITMAP, hOSD); // get bitmap
SendMessage(hwndDD, WM_MODULE_MSG, DDMODAPI_OSD_SHOW_SURFACE, hOSD);
Re: How can OSD show text with c++
Posted: Sat May 25, 2013 4:29 am
by rel
you need to get a compatible DC for HBITMAP bmSurface
and then draw on that with Windows GDI functions
Re: How can OSD show text with c++
Posted: Wed Jun 05, 2013 7:18 am
by zixi0007
Any one who can help me.
I can't see the OSD text with the following codes!
I don't know what is wrong with the codes.
Code: Select all
CWnd *pWnd = CWnd::FromHandle(hwndDD);
bmSurface = (HBITMAP)SendMessage(hwndDD, WM_MODULE_MSG, DDMODAPI_OSD_GET_SURFACE_BITMAP, surface_id); // get bitmap
WCHAR* m_sshow ;
m_sshow = L"This is my text";
HDC hdcTemp=::GetDC(NULL);
HDC m_hdcMemory =CreateCompatibleDC(hdcTemp);
SelectObject(m_hdcMemory,bmSurface);
Graphics g(m_hdcMemory);
g.SetSmoothingMode(SmoothingModeAntiAlias);
POINT pt,pos;
pt.x=0;
pt.y=0;
RECT rt;
pWnd->GetWindowRect(&rt);
pos.x = rt.left;
pos.y = rt.top;
SIZE SZ;
SZ.cx=800;
SZ.cy=80;
BLENDFUNCTION b;
b.AlphaFormat =AC_SRC_ALPHA;
b.BlendFlags=0;
b.BlendOp=AC_SRC_OVER;
b.SourceConstantAlpha=255;
FontFamily font(L"宋体");
GraphicsPath path,path2;
path.AddString(
m_sshow,
-1,
&font,
FontStyleRegular,
72,
Rect(5, 5, 500, 100),
NULL);
path2.AddString(
m_sshow,
-1,
&font,
FontStyleRegular,
72,
Rect(8, 8, 500, 100),
NULL);
SolidBrush byy(Color(128,0, 0, 0));
LinearGradientBrush bin(PointF(0,0),PointF(0,80),Color(255,0,0,255),Color(255,0,255,0));;//图形填充画刷
Pen pout(Color(128, 255, 255,255),1.0f);
Pen pyy(Color(100, 0, 0,0),2.0f);
g.FillPath(&byy,&path2);
g.DrawPath(&pyy, &path2);
g.FillPath(&bin,&path);
g.DrawPath(&pout, &path);
::UpdateLayeredWindow( hwndDD,pWnd->GetDC()->m_hDC,&pos,
&SZ,m_hdcMemory,&pt,0,&b,2);
SendMessage(hwndDD, WM_MODULE_MSG, DDMODAPI_OSD_REPAINT_SURFACE, surface_id);
SendMessage(hwndDD, WM_MODULE_MSG, DDMODAPI_OSD_SHOW_SURFACE, surface_id);
Re: How can OSD show text with c++
Posted: Wed Jun 05, 2013 12:49 pm
by rel
send me your code if you would like, I'll try to compile and help here.