Click to See Complete Forum and Search --> : CE GetDC() not a member of _HDC ?


irb4
September 21st, 2006, 03:33 AM
So I got this really NICE nice document about fonts, read it and copy the codes to my windows mobile 5 app.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcefonts5/html/wce50condrawingandformattingtext.asp


void initiateText ()
{
// Get a GDI DC onto the backbuffer, where you will render the text.
g_lpDDSBack->GetDC (&hdcSurface);

// Select the font into the DC.
hfontSave = (HFONT) SelectObject (hdcSurface, hfontTimes);

// Set the background mode to transparent, so there is no
// rectangle behind the text.
SetBkMode (hdcSurface, TRANSPARENT);
}





EVC++ compiler says there is no declaration for g_lpDDSBack,

so I wrote


HDC g_lpDDSBack;




THe evc++ 2002 compiler says


:\WSC4eVC\APPS\message.cpp(209) : error C2039: 'GetDC' : is not a member of 'HDC__'

C:\Windows CE Tools\wce300\Pocket PC 2002\include\windef.h(254) : see declaration of 'HDC__'




I look up for GetDC() in msdn library and it didn't mention any special include files.

What's up? Thanks.



Mooooooooooo
Mooooooooooooooooooo
Moooooooooooooooooooooooooooooooooo

irb4
September 21st, 2006, 03:47 AM
So I found this site

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_win32_getdc.asp

Windows CE OS 1.0 and later
Winuser.h
Coredll.lib, Winmgr.lib

Pump those stuff into my #includes and library settings but the same
error: not a member of _HDC.

Ah, I can't sleep today. What is the problem?

MrViggy
September 21st, 2006, 01:04 PM
Well, an 'HDC' is a handle (usually an integer). The '->' operator is designed to work with a pointer to a class instance, not a handle.

I don't work with WindowsCE, so I don't know where 'g_lpDDSBack' would be declared. Sorry.

Viggy

HollyMatrix
September 21st, 2006, 10:13 PM
Hi.

try this (it's my first programme for mobiles).

1- Create your project
2- add this as global variable :
HFONT hMyFont; // Font handle

3- add this function:
void InitFont(){
LOGFONT logMyFont; // Logical font structure

// First, clear all fields.
memset (&logMyFont, 0, sizeof (logMyFont));

// Create a GDI Times New Roman font.
logMyFont.lfHeight = 10;
logMyFont.lfWidth = 0;
logMyFont.lfEscapement = 0;
logMyFont.lfOrientation = 0;
logMyFont.lfWeight = FW_BOLD;
logMyFont.lfItalic = TRUE;
logMyFont.lfUnderline = FALSE;
logMyFont.lfStrikeOut = FALSE;
logMyFont.lfCharSet = DEFAULT_CHARSET;
logMyFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logMyFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logMyFont.lfQuality = DEFAULT_QUALITY;
logMyFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
_tcsncpy (logMyFont.lfFaceName, TEXT("Arial"), LF_FACESIZE);
logMyFont.lfFaceName[LF_FACESIZE-1] = TEXT('\0'); // Ensure null termination
hMyFont = CreateFontIndirect (&logMyFont);

if (!hMyFont) {
// error, font not created.
}
}

4- add this function (InitFont()) in your WindowProcedure that process the Window messages at the end (just before the break;) of WM_CREATE message.

5- add DeleteObject(hMyFont); in the WM_DESTROY message before the PostQuitMessage Function.

6- add the variable HFONT hOldFont in the WndProc function (function that processes the Window messages)

7- in the WM_PAINT message add the following Code between the BeginPaint() and EndPaint(); like this

hdc = BeginPaint(hWnd, &ps);
hOldFont = (HFONT) SelectObject (hdc, hMyFont);
SetBkMode (hdc, TRANSPARENT);

SetTextColor (hdc, 0x000000ff); // color blue

ExtTextOut (hdc,10, 10,
0, // No flags set
NULL, // No clipping rectangle
_T("HollyMatrix"), // String to display
lstrlen (_T("HollyMatrix")), // Number of characters
NULL); // Use default spacing.

SelectObject (hdc, hOldFont);
EndPaint(hWnd, &ps);


that's all

the visual studio 2005 project for this example is attached

irb4
September 22nd, 2006, 02:44 AM
Thank you guys, you are the greatest, esp HollyMatrix, here, smoooooch.

greg_dolley
September 23rd, 2006, 09:53 PM
HDC is simply a HANDLE (which is typedef'ed to a "long"). The wrapper classes have GetDC(). Try using the CDC class.

Greg Dolley

irb4
September 24th, 2006, 08:49 PM
Many thanks, muah muah~

ovidiucucu
September 30th, 2006, 11:38 AM
Well, an 'HDC' is a handle (usually an integer).
HDC is simply a HANDLE (which is typedef'ed to a "long").

Huh?! :confused:

Please, just take a look at this post (http://www.codeguru.com/forum/showpost.php?p=1424531). ;)

ovidiucucu
September 30th, 2006, 12:02 PM
The wrapper classes have GetDC(). Try using the CDC class.
Nope. CDC has not GetDC() member function, but CWnd has.