It's relatively simple if you already know how to use GDI calls.
Following code uses WTL classes for GDI functions, but you can easily change it to pure Win32 GDI calls.
First tell DD to create bitmap for you and get HBITMAP for it. Also create DC for drawing.
Code: Select all
// Global variables
HBITMAP bmSurface;
int surface_id;
CDC dcSurface;
CRect rcSurface;
void InitOSD()
{
CRect rc(10,10,200,50); // Rectangle for OSD surface
TOSDSurface surface = {
sizeof(TOSDSurface),
rc.left,rc.top,rc.Width(),rc.Height();
TRANSPARENCY_NONE
};
rcSurface = CRect(0,0,rc.Width(),rc.Height()); // so we dont need to calculate this every time...
surface_id = SendMessage(m_hWndDream, WM_MODULE_MSG, DDMODAPI_OSD_CREATE_SURFACE, (LPARAM)&surface); // create surface
bmSurface = (HBITMAP)SendMessage(m_hWndDream, WM_MODULE_MSG, DDMODAPI_OSD_GET_SURFACE_BITMAP, surface_id); // get bitmap
dcSurface.CreateCompatibleDC(NULL); // create screen compatible DC
}
When you want to update OSD, use function like this:
Code: Select all
void UpdateOSD()
{
HBITMAP oldbm = dcSurface.SelectBitmap(bmSurface);
/// here you can use dcSurface for any painting, drawing text and other stuff ///
dcSurface.FillSolidRect(rcSurface,RGB(50,50,50));
// If you want to draw bitmap, use code like this:
{
CDC bdc;
bdc.CreateCompatibleDC(dcSurface);
HBITMAP pOldBmp = bdc.SelectBitmap(some_bitmap_you_have_loaded);
dcSurface.BitBlt(0,0,bitmap_width,bitmap_height,bdc,0,0,SRCCOPY); // Change pos/size as needed...
pdc.SelectBitmap(pOldBmp);
}
dcSurface.SelectBitmap(oldbm); // Important -> de-select bitmap before calling DD API
SendMessage(m_hWndDream, WM_MODULE_MSG, DDMODAPI_OSD_REPAINT_SURFACE, surface_id);
SendMessage(m_hWndDream, WM_MODULE_MSG, DDMODAPI_OSD_SHOW_SURFACE, surface_id);
// Show surface, you need to call this only once
}
I call function like this that fills all info on event, like channel or volume change.
For every surface, I have "changed" and "visible" state, so I'm updating only surfaces that really needs to be updated.
Finally on module unload, destroy dcSurface and also DD surface by DDMODAPI_OSD_DESTROY_SURFACE.