Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualanders211

Posted 21 December 2012 - 01:07 PM

I have had a problem but I solved it. This is the solution which tell You how to set transparency to the background window.

The solution depends on ivoking twice BitBlt operation. First time when copying current background window into HDC of our bitmap and secondly when You write the text into bitmap and copy them back to HDC of window.

 

 

 

 

HRESULT Buffer::drawText(i32 x, i32 y, RECT* rect)
{
/*HRESULT hr = ScriptTextOut(hdc
_In_ const HDC hdc,
_Inout_ SCRIPT_CACHE *psc,
_In_ int x,
_In_ int y,
_In_ UINT fuOptions,
_In_opt_ const RECT *lprc,
_In_ const SCRIPT_ANALYSIS *psa,
_In_ const WCHAR *pwcReserved,
_In_ int iReserved,
_In_ const WORD *pwGlyphs,
_In_ int cGlyphs,
_In_ const int *piAdvance,
_In_opt_ const int *piJustify,
_In_ const GOFFSET *pGoffset*/

HDC hDC = NULL;
if(mFont.font != NULL)
hDC = mFont.font->GetDC(); //get font DC
else
{
::MessageBox(NULL, "Buffer::drawText - font not initialized", "Warning", MB_ICONWARNING);
return S_FALSE;
}

//Prepare ID3DXFont
HBITMAP hBitmapOld = (HBITMAP) SelectObject(hDC, mBitmap);
COLORREF prevBkColor = SetBkColor(hDC, 0x00FF00);
//HBRUSH hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
//HBRUSH hBrushOld = (HBRUSH)SelectObject(hDC, hBrush);
//COLORREF dcColorOld = GetDCBrushColor(hDC);
//SetDCBrushColor(hDC, 0xFF0000);
i32 prevBkMode = SetBkMode(hDC, TRANSPARENT);
COLORREF prevTextColor = SetTextColor(hDC, 0x000000);
BitBlt(hDC, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, GUI::hDCWin, rect->left, rect->top, SRCCOPY);

SCRIPT_CACHE scriptCache = NULL; //in: font info

//TextOutW(hDC,rect->left, rect->top, mBuffer,getTextSize()); //used for debug purposes
HRESULT hr = ScriptTextOut(hDC, &scriptCache, x, y, ETO_CLIPPED, rect, &mItems[0].a, NULL, 0, &mGlyphs[0], //ETO_OPAQUE set BkColor so don't use it
static_cast<i32>(mGlyphs.size()), &mPiAdvance[0], NULL, &mGoffset[0]); //&mPiJustify[0]
BitBlt(GUI::hDCWin, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, hDC, rect->left, rect->top, SRCCOPY);

ScriptFreeCache(&scriptCache);

//Restore hDC of ID3DXFont
SelectObject(hDC, hBitmapOld);
SetBkMode(hDC, prevBkMode);
//SelectObject(hDC, hBrushOld);
SetBkColor(hDC, prevBkColor);
SetTextColor(hDC, prevTextColor);
//SetDCBrushColor(hDC, dcColorOld);

return hr;
}

 


#1anders211

Posted 21 December 2012 - 12:57 PM

I was trying different things and none helps.It iseems like TRANSAPRENCY is not possible when You are using TextOut or ScriptTextOut.

 

 

 

HDC hDC = NULL;
if(mFont.font != NULL)
hDC = mFont.font->GetDC(); //get font DC
else
{
::MessageBox(NULL, "Buffer::drawText - font not initialized", "Warning", MB_ICONWARNING);
return S_FALSE;
}

//Prepare ID3DXFont
HBITMAP hBitmapOld = (HBITMAP) SelectObject(hDC, mBitmap);
COLORREF prevBkColor = SetBkColor(hDC, 0x00FF00);
//HBRUSH hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
//HBRUSH hBrushOld = (HBRUSH)SelectObject(hDC, hBrush);
COLORREF dcColorOld = GetDCBrushColor(hDC);
SetDCBrushColor(hDC, 0xFF0000);
i32 prevBkMode = SetBkMode(hDC, TRANSPARENT);
COLORREF prevTextColor = SetTextColor(hDC, 0x000000);

SCRIPT_CACHE scriptCache = NULL; //in: font info

//TextOutW(hDC,rect->left, rect->top, mBuffer,getTextSize()); //used for debug purposes
HRESULT hr = ScriptTextOut(hDC, &scriptCache, x, y, ETO_CLIPPED | ETO_OPAQUE, rect, &mItems[0].a, NULL, 0, &mGlyphs[0],
static_cast<i32>(mGlyphs.size()), &mPiAdvance[0], NULL, &mGoffset[0]); //&mPiJustify[0]
BitBlt(GUI::hDCWin, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, hDC, rect->left, rect->top, SRCCOPY);

ScriptFreeCache(&scriptCache);

//Restore hDC of ID3DXFont
SelectObject(hDC, hBitmapOld);
SetBkMode(hDC, prevBkMode);
//SelectObject(hDC, hBrushOld);
SetBkColor(hDC, prevBkColor);
SetTextColor(hDC, prevTextColor);
SetDCBrushColor(hDC, dcColorOld);

PARTNERS