loading abitmap file into an osd with c++

Module API help / support section for programmers.

Moderators: Dreamer, FredB, X05

dashne
Just can't stay away
Posts: 20
Joined: Thu Jun 03, 2010 2:25 pm

loading abitmap file into an osd with c++

Postby dashne » Fri Jun 18, 2010 11:10 am

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

skystar2
User avatar
rel
relocation
Posts: 2051
Joined: Fri Jun 16, 2006 9:50 am

Postby rel » Fri Jun 18, 2010 1:37 pm

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).
DVB Dream - because I have to dream about having time to code it
r00t
Just can't stay away
Posts: 26
Joined: Mon Apr 05, 2010 4:58 pm

Postby r00t » Sat Jun 19, 2010 11:31 am

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.
Skystar2 2.3 + Skystar HD2 + SG-2100 + TwinLNB
dashne
Just can't stay away
Posts: 20
Joined: Thu Jun 03, 2010 2:25 pm

I failed

Postby dashne » Mon Jun 28, 2010 2:48 pm

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.
skystar2
r00t
Just can't stay away
Posts: 26
Joined: Mon Apr 05, 2010 4:58 pm

Postby r00t » Tue Jun 29, 2010 4:03 am

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).
Skystar2 2.3 + Skystar HD2 + SG-2100 + TwinLNB
dashne
Just can't stay away
Posts: 20
Joined: Thu Jun 03, 2010 2:25 pm

I failed again

Postby dashne » Tue Jun 29, 2010 5:49 am

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.
skystar2
dashne
Just can't stay away
Posts: 20
Joined: Thu Jun 03, 2010 2:25 pm

image loading

Postby dashne » Wed Jun 30, 2010 6:01 am

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
skystar2
r00t
Just can't stay away
Posts: 26
Joined: Mon Apr 05, 2010 4:58 pm

Postby r00t » Wed Jun 30, 2010 6:30 am

... 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.
Skystar2 2.3 + Skystar HD2 + SG-2100 + TwinLNB
dashne
Just can't stay away
Posts: 20
Joined: Thu Jun 03, 2010 2:25 pm

I succeeded

Postby dashne » Wed Jun 30, 2010 10:02 am

Finally I succeeded with your help,thank you so much
skystar2

Return to “Module / Plugin Programming”

Who is online

Users browsing this forum: No registered users and 1 guest