Page 1 of 1

loading abitmap file into an osd with c++

Posted: Fri Jun 18, 2010 11:10 am
by dashne
Hi, everyone, Iwant to load a bitmap file into an osd and how I can add text on it like channel information ,Iam using mvc++,anyone can help?!!


thanks

Posted: Fri Jun 18, 2010 1:37 pm
by rel
DD will create a bitmap handle (HBITMAP) when youcreate an OSD surface and you can pass it to GDI API functions.

http://www.toymaker.info/Games/html/gdi.html

check the section named "Displaying Text"

I think, you can use BitBlt() to place a bitmap on another bitmap (OSD surface for example).

Posted: Sat Jun 19, 2010 11:31 am
by r00t
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.

I failed

Posted: Mon Jun 28, 2010 2:48 pm
by dashne
Hi,guys
thank you for your replies,when I compiled your code I got an error message :
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
when I exclude the windows.h from the code I get more than 100 error
please help me ,if you can upload acomplete project for these particular problems ?

thanks.

Posted: Tue Jun 29, 2010 4:03 am
by r00t
Here are all important includes:

stdafx.h:

Code: Select all

#if !defined(AFX_STDAFX_H_)
#define AFX_STDAFX_H_

#include <atlbase.h>
#include <atlapp.h>

extern CAppModule _Module;

#include <atlcrack.h>
#include <atlwin.h>
#include <atldlgs.h>
#include <atlmisc.h>

#include "..\Include\moduleAPI.h" // Dream SDK API

#endif
stdafx.cpp:

Code: Select all

#include "stdafx.h"

#if (_ATL_VER < 0x0700)
#include <atlimpl.cpp>
#endif //(_ATL_VER < 0x0700)

BOOL __stdcall DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
_Module.Init(0, hInstance);
break;

case DLL_THREAD_DETACH:
break;

case DLL_PROCESS_DETACH:
_Module.Term();
break;
}

return TRUE;
}
plugin.cpp:

Code: Select all

#include "stdafx.h"
#include "resource.h"
#include <atlframe.h>
#include <atlctrls.h>
#include <atldlgs.h>
#include <atlctrlw.h>
#include <atlctrlx.h>
#include <atlmisc.h>

CAppModule _Module;

...
stdafx.h/cpp is for precompiled headers, plugin.cpp is main program file.
CAppModule is used by WTL when creating new windows and dialogs, you may not need it if you have none in your plugin.

Note that I'm using no MFC headers, it's all ATL + WTL. (ATL is part of Microsoft Platform SDK, WTL can be downloaded from SourceForge).

I failed again

Posted: Tue Jun 29, 2010 5:49 am
by dashne
Hi agin I failed,I exactly used the code but this time cmpilation is ok,but dvbdream didnt show me anything,can you upload plugin.cpp code completely to know where should I put the functions,Iam so sorry for anoying but I just have you for helping

thanks.

image loading

Posted: Wed Jun 30, 2010 6:01 am
by dashne
Hi again,thank you so much for your help,but I have aproblem with loading the image(bitmap) ,Iam loading it with function 'LoadImage(...)'
but the the return value is error code 2 which means the specified file does not exis but I have this file and it is inthe same directory of the plugin,H do not know what is the problem?

thanks

Posted: Wed Jun 30, 2010 6:30 am
by r00t
... but I have this file and it is inthe same directory of the plugin ...

That's wrong then, because DLL is loaded by Dream and path is relative to EXE, not DLL.

I succeeded

Posted: Wed Jun 30, 2010 10:02 am
by dashne
Finally I succeeded with your help,thank you so much