Followers 0

# How to get HFONT from ID3DXFont instance

## 0 posts in this topic

Hi,
Short introduction:
I have created ID3DXFont instance with the aid of function D3DXCreateFont(). In fact this instance You might also create with the aid of D3DXCreateFontIndirect. What You can do with this font instance after creating - You may invoke ID3DXFont::DrawText method to draw the text.
The problem is how to convert ID3DXFont instance to HFONT, because sometimes I would like to use function which draw text based on HFONT instance, not ID3DXFont one. In my particular case this function which I would like to use it: ScriptTextOut(), in which first parameter is HDC. In fact I might obtain HDC from ID3DXFont interface with the aid of method ID3DXFont::GetDC. However after I did it nothing is draw in this obtained ID3DXFont HDC - I cannot see any drawn text. But when I change HDC into hDC of window, I can see drawn text. However the window HDC has some default HFONT related. So the question is how to relate ID3DXFont HFONT into hDC of window??? I know that there isn't HFONT in ID3DXFont but the question is how to solve my problem?
This is my code in which the text is not seen (it is seen only when I use default hWnd font, not obtained from ID3DXFont):
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 != NULL)hDC = mFont->font->GetDC(); //get font DCelse{::MessageBox(NULL, "Buffer::drawText - font not initialized", "Warning", MB_ICONWARNING);return S_FALSE;}HPEN fPen = (HPEN)SelectObject(hDC, NULL); //get font HPENSelectObject(hDC, fPen); //restore font HPENHDC hDCWin = GetDC(GUI::hWnd); //get window DCHPEN winPen = (HPEN)SelectObject(hDCWin, fPen); //set new HPEN to window and get old HPEN//SCRIPT_CACHE scriptCache = NULL; //in: font infoTextOutW(hDC,rect->left, rect->top, mBuffer,getTextSize()); //let's first try this simple function instead of ScriptTextOutHRESULT hr = S_OK;//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]//ScriptFreeCache(&scriptCache);SelectObject(hDCWin, winPen); //restore original window HPENReleaseDC(GUI::hWnd, hDCWin); //release window HDCreturn hr;}

I hope that You understand my problem. If not, in other words the question might be how to draw the text with the aid of ScriptTextOut (or TextOutW) with font from ID3DXFont interface in the way that it is seen in the screen? Edited by anders211
0

## Create an account

Register a new account