get font from HDC

Hi,

I would like to modify a function used to render some HTML and use the 
font I have choosen :


// C functions
int __stdcall DrawHTML(
                        HDC     hdc,        // handle of device context
                        LPCTSTR lpString,   // address of string to draw
                        int     nCount,     // string length, in characters
                        LPRECT  lpRect,     // address of structure with 
formatting dimensions
                        UINT    uFormat     // text-drawing flags
					   )
{
....


/* get the "default" font from the DC */
	SavedDC = SaveDC(hdc);
	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
	SelectObject(hdc, hfontBase);
	/* clear the other fonts, they are created "on demand" */
	for (Index = 0; Index < FV_NUMBER; Index++)
		hfontSpecial[Index] = NULL;
	hfontSpecial[0] = hfontBase;
....
}


Here is my code :


void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
BOOL bSelected)
{

  CFont* pOldFont  = MemDC.SelectObject( &m_font );

DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
			&rc,DT_LEFT|DT_WORDBREAK);
}



My problem is I don't know how to modify DrawHTML to take the font 
specified in DrawItem because from what I understand DrawHTML is using a 
default font :

hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
	SelectObject(hdc, hfontBase);











0
8/20/2007 1:05:43 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
198 Views

Similar Articles

[PageSpeed] 9

Oups I wanted to say (MemDC instead of pDC):

void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
BOOL bSelected)
{

  CFont* pOldFont  = MemDC.SelectObject( &m_font );

DrawHTML(MemDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
             &rc,DT_LEFT|DT_WORDBREAK);
}


mosfet a �crit :
> Hi,
> 
> I would like to modify a function used to render some HTML and use the 
> font I have choosen :
> 
> 
> // C functions
> int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
> formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>                        )
> {
> ...
> 
> 
> /* get the "default" font from the DC */
>     SavedDC = SaveDC(hdc);
>     hfontBase = (HFONT)SelectObject(hdc, 
> (HFONT)GetStockObject(SYSTEM_FONT));
>     SelectObject(hdc, hfontBase);
>     /* clear the other fonts, they are created "on demand" */
>     for (Index = 0; Index < FV_NUMBER; Index++)
>         hfontSpecial[Index] = NULL;
>     hfontSpecial[0] = hfontBase;
> ...
> }
> 
> 
> Here is my code :
> 
> 
> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
> BOOL bSelected)
> {
> 
>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
> 
> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>             &rc,DT_LEFT|DT_WORDBREAK);
> }
> 
> 
> 
> My problem is I don't know how to modify DrawHTML to take the font 
> specified in DrawItem because from what I understand DrawHTML is using a 
> default font :
> 
> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>     SelectObject(hdc, hfontBase);
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
0
8/20/2007 1:11:00 PM
On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:

>Hi,
>
>I would like to modify a function used to render some HTML and use the 
>font I have choosen :
>
>
>// C functions
>int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
>formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>					   )
>{
>...
>
>
>/* get the "default" font from the DC */
>	SavedDC = SaveDC(hdc);
****
You do a SaveDC but not a RestoreDC?  
****
>	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>	SelectObject(hdc, hfontBase);
****
It would be easier to write
	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
and not worry about the SelectObject pair
****
>	/* clear the other fonts, they are created "on demand" */
>	for (Index = 0; Index < FV_NUMBER; Index++)
>		hfontSpecial[Index] = NULL;
>	hfontSpecial[0] = hfontBase;
****
Note that if, in between times, the font which is currently selected into the DC is
deleted, the old handle you have saved here will become meaningless.  Therefore, you
cannot rely on the fact that this handle will still be valid at the time you use it.
Better to do an array of LOGFONT values, rather than an array of HFONTs.
****
>...
>}
>
>
>Here is my code :
>
>
>void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>BOOL bSelected)
>{
>
>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>
>DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>			&rc,DT_LEFT|DT_WORDBREAK);
****
So why do you save the font in the MemDC when you don't actually use it?  Note that the
m_font handle must represent a valid font to be selected, but the line seems to have no
meaning as shown in this function.  I would also suggest something like
	HDC dc = pDC->GetSafeHdc();
	if(dc == NULL)
	    return;
               DrawHTML(dc, ...as above...);
>}
>
>
>
>My problem is I don't know how to modify DrawHTML to take the font 
>specified in DrawItem because from what I understand DrawHTML is using a 
>default font :
>
>hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>	SelectObject(hdc, hfontBase);
>
****
I don't see the relationship of the above code to the problem.  Where is this line of
code?  I also could not find any method called DrawHTML in the MSDN documentation, could
you say more about where it is implemented or what it is supposed to do?
					joe
****
>
>
>
>
>
>
>
>
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15978)
8/20/2007 1:20:59 PM
Actually I want to use the following control 
http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
that's not the question) that is a Custom CListCtrl deriving from CWnd.
It's appropriate because on smartphone you don't have much space and 
this listctrl allow to have a different size for each row in addtion to 
support a few HTML tags.

But when reading the code I saw that it uses hfontBase = 
(HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
think it would be better to use the font selected in the control.
For instanc I could do a SetFont on my listctrl and the DrawHTML 
function should use it to do its rendering (bold, italic, ...)



About savedc and restordc it's because I haven't posted all the code.

int __stdcall DrawHTML(
                        HDC     hdc,        // handle of device context
                        LPCTSTR lpString,   // address of string to draw
                        int     nCount,     // string length, in characters
                        LPRECT  lpRect,     // address of structure with 
formatting dimensions
                        UINT    uFormat     // text-drawing flags
					   )
{
	LPCTSTR Start;
	int Left, Top, MaxWidth, MinWidth, Height;
	int SavedDC;
	int Tag, TokenLength;
	HFONT hfontBase, hfontSpecial[FV_NUMBER];
	int Styles, CurStyles;
	SIZE size;
	int Index, LineHeight;
	POINT CurPos;
	int WidthOfSPace, XPos;
	BOOL WhiteSpace;
	RECT rc;
	
	if (hdc == NULL || lpString == NULL)
		return 0;
	if (nCount < 0)
		nCount = _tcslen(lpString);
	
	if (lpRect != NULL) {
		Left = lpRect->left;
		Top = lpRect->top;
		MaxWidth = lpRect->right - lpRect->left;
	} else {
		GetCurrentPositionEx(hdc, &CurPos);
		Left = CurPos.x;
		Top = CurPos.y;
		MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
	} /* if */
	if (MaxWidth < 0)
		MaxWidth = 0;
	
	/* toggle flags we do not support */
	uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
	uFormat |= (DT_LEFT | DT_NOPREFIX);
	
	/* get the "default" font from the DC */
	SavedDC = SaveDC(hdc);
	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
	SelectObject(hdc, hfontBase);
	/* clear the other fonts, they are created "on demand" */
	for (Index = 0; Index < FV_NUMBER; Index++)
		hfontSpecial[Index] = NULL;
	hfontSpecial[0] = hfontBase;
	Styles = 0; /* assume the active font is normal weight, roman, 
non-underlined */
	
				/* get font height (use characters with ascender and descender);
				* we make the assumption here that changing the font style will
				* not change the font height
	*/
	GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
	LineHeight = size.cy;
	
	/* run through the string, word for word */
	XPos = 0;
	MinWidth = 0;
	stacktop = 0;
	CurStyles = -1; /* force a select of the proper style */
	Height = 0;
	WhiteSpace = FALSE;
	
	Start = lpString;
	for ( ;; ) {
		Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
		if (Tag < 0)
			break;
		switch (Tag & ~ENDFLAG) {
		case tP:
			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
				if (Start != lpString)
					Height += 3 * LineHeight / 2;
				XPos = 0;
			} /* if */
			break;
		case tBR:
			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
				Height += LineHeight;
				XPos = 0;
			} /* if */
			break;
		case tB:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | FV_BOLD;
			break;
		case tI:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | FV_ITALIC;
			break;
		case tU:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
FV_UNDERLINE;
			break;
		case tSUB:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
FV_SUBSCRIPT;
			break;
		case tSUP:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles | 
FV_SUPERSCRIPT;
			break;
		case tFONT:
			if ((Tag & ENDFLAG) == 0) {
				if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
					PushColor(hdc, ParseColor(Start + 12));
			} else {
				PopColor(hdc);
			} /* if */
			break;
		default:
			if (Tag == (tNONE | ENDFLAG))
				break;
			if (CurStyles != Styles) {
				if (hfontSpecial[Styles] == NULL)
					hfontSpecial[Styles] = GetFontVariant(hdc, hfontBase, Styles);
				CurStyles = Styles;
				SelectObject(hdc, hfontSpecial[Styles]);
				/* get the width of a space character (for word spacing) */
				GetTextExtentPoint32(hdc, _T(" "), 1, &size);
				WidthOfSPace = size.cx;
			} /* if */
			/* check word length, check whether to wrap around */
			GetTextExtentPoint32(hdc, Start, TokenLength, &size);
			if (size.cx > MaxWidth)
				MaxWidth = size.cx;   /* must increase width: long non-breakable word */
			if (WhiteSpace)
				XPos += WidthOfSPace;
			if (XPos + size.cx > MaxWidth && WhiteSpace) {
				if ((uFormat & DT_WORDBREAK) != 0) {
					/* word wrap */
					Height += LineHeight;
					XPos = 0;
				} else {
					/* no word wrap, must increase the width */
					MaxWidth = XPos + size.cx;
				} /* if */
			} /* if */
			/* output text (unless DT_CALCRECT is set) */
			if ((uFormat & DT_CALCRECT) == 0) {
				/* handle negative heights, too (suggestion of "Sims")  */
				/*if (Top < 0)
				{
					SetRect(&rc, Left + XPos, Top - Height,
					Left + MaxWidth, Top - (Height + LineHeight));
				}
				else*/
				{
					SetRect(&rc, Left + XPos, Top + Height,
					Left + MaxWidth, Top + Height + LineHeight);
				}
				
				/* reposition subscript text to align below the baseline */
				DrawText(hdc, Start, TokenLength, &rc,
					uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | DT_SINGLELINE : 0));
				
					/* for the underline style, the spaces between words should be
					* underlined as well
				*/
				if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= WidthOfSPace)
				{
					if (Top < 0)
					{
						SetRect(&rc, Left + XPos - WidthOfSPace, Top - Height,
							Left + XPos, Top - (Height + LineHeight));
					}
					else
					{
						SetRect(&rc, Left + XPos - WidthOfSPace, Top + Height,
							Left + XPos, Top + Height + LineHeight);
					}
					DrawText(hdc, _T(" "), 1, &rc, uFormat);
				} /* if */
			} /* if */
			/* update current position */
			XPos += size.cx;
			if (XPos > MinWidth)
				MinWidth = XPos;
			WhiteSpace = FALSE;
     } /* if */
	
     Start += TokenLength;
   } /* for */

   RestoreDC(hdc, SavedDC);
   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
hfontSpecial[0] */
	  if (hfontSpecial[Index] != NULL)
		  DeleteObject(hfontSpecial[Index]);
	
	  /* store width and height back into the lpRect structure */
	  if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
		  lpRect->right = lpRect->left + MinWidth;
		  if (lpRect->top < 0)
			  lpRect->bottom = lpRect->top - (Height + LineHeight);
		  else
			  lpRect->bottom = lpRect->top + Height + LineHeight;
	  } /* if */
	
	  return Height;
}




Joseph M. Newcomer a �crit :
> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:
> 
>> Hi,
>>
>> I would like to modify a function used to render some HTML and use the 
>> font I have choosen :
>>
>>
>> // C functions
>> int __stdcall DrawHTML(
>>                        HDC     hdc,        // handle of device context
>>                        LPCTSTR lpString,   // address of string to draw
>>                        int     nCount,     // string length, in characters
>>                        LPRECT  lpRect,     // address of structure with 
>> formatting dimensions
>>                        UINT    uFormat     // text-drawing flags
>> 					   )
>> {
>> ...
>>
>>
>> /* get the "default" font from the DC */
>> 	SavedDC = SaveDC(hdc);
> ****
> You do a SaveDC but not a RestoreDC?  
> ****
>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>> 	SelectObject(hdc, hfontBase);
> ****
> It would be easier to write
> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
> and not worry about the SelectObject pair
> ****
>> 	/* clear the other fonts, they are created "on demand" */
>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>> 		hfontSpecial[Index] = NULL;
>> 	hfontSpecial[0] = hfontBase;
> ****
> Note that if, in between times, the font which is currently selected into the DC is
> deleted, the old handle you have saved here will become meaningless.  Therefore, you
> cannot rely on the fact that this handle will still be valid at the time you use it.
> Better to do an array of LOGFONT values, rather than an array of HFONTs.
> ****
>> ...
>> }
>>
>>
>> Here is my code :
>>
>>
>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>> BOOL bSelected)
>> {
>>
>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>
>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>> 			&rc,DT_LEFT|DT_WORDBREAK);
> ****
> So why do you save the font in the MemDC when you don't actually use it?  Note that the
> m_font handle must represent a valid font to be selected, but the line seems to have no
> meaning as shown in this function.  I would also suggest something like
> 	HDC dc = pDC->GetSafeHdc();
> 	if(dc == NULL)
> 	    return;
>                DrawHTML(dc, ...as above...);
>> }
>>
>>
>>
>> My problem is I don't know how to modify DrawHTML to take the font 
>> specified in DrawItem because from what I understand DrawHTML is using a 
>> default font :
>>
>> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>> 	SelectObject(hdc, hfontBase);
>>
> ****
> I don't see the relationship of the above code to the problem.  Where is this line of
> code?  I also could not find any method called DrawHTML in the MSDN documentation, could
> you say more about where it is implemented or what it is supposed to do?
> 					joe
> ****
>>
>>
>>
>>
>>
>>
>>
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
0
8/20/2007 1:37:16 PM
Finally I did this :

hfontBase = (HFONT)::GetCurrentObject(hdc, OBJ_FONT);
if (hfontBase == NULL){
	hfontBase = (HFONT) GetStockObject(SYSTEM_FONT) );
}
SelectObject(hdc, hfontBase);


mosfet a �crit :
> Actually I want to use the following control 
> http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
> that's not the question) that is a Custom CListCtrl deriving from CWnd.
> It's appropriate because on smartphone you don't have much space and 
> this listctrl allow to have a different size for each row in addtion to 
> support a few HTML tags.
> 
> But when reading the code I saw that it uses hfontBase = 
> (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
> think it would be better to use the font selected in the control.
> For instanc I could do a SetFont on my listctrl and the DrawHTML 
> function should use it to do its rendering (bold, italic, ...)
> 
> 
> 
> About savedc and restordc it's because I haven't posted all the code.
> 
> int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
> formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>                        )
> {
>     LPCTSTR Start;
>     int Left, Top, MaxWidth, MinWidth, Height;
>     int SavedDC;
>     int Tag, TokenLength;
>     HFONT hfontBase, hfontSpecial[FV_NUMBER];
>     int Styles, CurStyles;
>     SIZE size;
>     int Index, LineHeight;
>     POINT CurPos;
>     int WidthOfSPace, XPos;
>     BOOL WhiteSpace;
>     RECT rc;
>     
>     if (hdc == NULL || lpString == NULL)
>         return 0;
>     if (nCount < 0)
>         nCount = _tcslen(lpString);
>     
>     if (lpRect != NULL) {
>         Left = lpRect->left;
>         Top = lpRect->top;
>         MaxWidth = lpRect->right - lpRect->left;
>     } else {
>         GetCurrentPositionEx(hdc, &CurPos);
>         Left = CurPos.x;
>         Top = CurPos.y;
>         MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
>     } /* if */
>     if (MaxWidth < 0)
>         MaxWidth = 0;
>     
>     /* toggle flags we do not support */
>     uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
>     uFormat |= (DT_LEFT | DT_NOPREFIX);
>     
>     /* get the "default" font from the DC */
>     SavedDC = SaveDC(hdc);
>     hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>     hfontBase = (HFONT)SelectObject(hdc, 
> (HFONT)GetStockObject(SYSTEM_FONT));
>     SelectObject(hdc, hfontBase);
>     /* clear the other fonts, they are created "on demand" */
>     for (Index = 0; Index < FV_NUMBER; Index++)
>         hfontSpecial[Index] = NULL;
>     hfontSpecial[0] = hfontBase;
>     Styles = 0; /* assume the active font is normal weight, roman, 
> non-underlined */
>     
>                 /* get font height (use characters with ascender and 
> descender);
>                 * we make the assumption here that changing the font 
> style will
>                 * not change the font height
>     */
>     GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
>     LineHeight = size.cy;
>     
>     /* run through the string, word for word */
>     XPos = 0;
>     MinWidth = 0;
>     stacktop = 0;
>     CurStyles = -1; /* force a select of the proper style */
>     Height = 0;
>     WhiteSpace = FALSE;
>     
>     Start = lpString;
>     for ( ;; ) {
>         Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
>         if (Tag < 0)
>             break;
>         switch (Tag & ~ENDFLAG) {
>         case tP:
>             if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>                 if (Start != lpString)
>                     Height += 3 * LineHeight / 2;
>                 XPos = 0;
>             } /* if */
>             break;
>         case tBR:
>             if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>                 Height += LineHeight;
>                 XPos = 0;
>             } /* if */
>             break;
>         case tB:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | 
> FV_BOLD;
>             break;
>         case tI:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | 
> FV_ITALIC;
>             break;
>         case tU:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
> FV_UNDERLINE;
>             break;
>         case tSUB:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
> FV_SUBSCRIPT;
>             break;
>         case tSUP:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles 
> | FV_SUPERSCRIPT;
>             break;
>         case tFONT:
>             if ((Tag & ENDFLAG) == 0) {
>                 if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
>                     PushColor(hdc, ParseColor(Start + 12));
>             } else {
>                 PopColor(hdc);
>             } /* if */
>             break;
>         default:
>             if (Tag == (tNONE | ENDFLAG))
>                 break;
>             if (CurStyles != Styles) {
>                 if (hfontSpecial[Styles] == NULL)
>                     hfontSpecial[Styles] = GetFontVariant(hdc, 
> hfontBase, Styles);
>                 CurStyles = Styles;
>                 SelectObject(hdc, hfontSpecial[Styles]);
>                 /* get the width of a space character (for word spacing) */
>                 GetTextExtentPoint32(hdc, _T(" "), 1, &size);
>                 WidthOfSPace = size.cx;
>             } /* if */
>             /* check word length, check whether to wrap around */
>             GetTextExtentPoint32(hdc, Start, TokenLength, &size);
>             if (size.cx > MaxWidth)
>                 MaxWidth = size.cx;   /* must increase width: long 
> non-breakable word */
>             if (WhiteSpace)
>                 XPos += WidthOfSPace;
>             if (XPos + size.cx > MaxWidth && WhiteSpace) {
>                 if ((uFormat & DT_WORDBREAK) != 0) {
>                     /* word wrap */
>                     Height += LineHeight;
>                     XPos = 0;
>                 } else {
>                     /* no word wrap, must increase the width */
>                     MaxWidth = XPos + size.cx;
>                 } /* if */
>             } /* if */
>             /* output text (unless DT_CALCRECT is set) */
>             if ((uFormat & DT_CALCRECT) == 0) {
>                 /* handle negative heights, too (suggestion of "Sims")  */
>                 /*if (Top < 0)
>                 {
>                     SetRect(&rc, Left + XPos, Top - Height,
>                     Left + MaxWidth, Top - (Height + LineHeight));
>                 }
>                 else*/
>                 {
>                     SetRect(&rc, Left + XPos, Top + Height,
>                     Left + MaxWidth, Top + Height + LineHeight);
>                 }
>                
>                 /* reposition subscript text to align below the baseline */
>                 DrawText(hdc, Start, TokenLength, &rc,
>                     uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | 
> DT_SINGLELINE : 0));
>                
>                     /* for the underline style, the spaces between words 
> should be
>                     * underlined as well
>                 */
>                 if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= 
> WidthOfSPace)
>                 {
>                     if (Top < 0)
>                     {
>                         SetRect(&rc, Left + XPos - WidthOfSPace, Top - 
> Height,
>                             Left + XPos, Top - (Height + LineHeight));
>                     }
>                     else
>                     {
>                         SetRect(&rc, Left + XPos - WidthOfSPace, Top + 
> Height,
>                             Left + XPos, Top + Height + LineHeight);
>                     }
>                     DrawText(hdc, _T(" "), 1, &rc, uFormat);
>                 } /* if */
>             } /* if */
>             /* update current position */
>             XPos += size.cx;
>             if (XPos > MinWidth)
>                 MinWidth = XPos;
>             WhiteSpace = FALSE;
>     } /* if */
>     
>     Start += TokenLength;
>   } /* for */
> 
>   RestoreDC(hdc, SavedDC);
>   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
> hfontSpecial[0] */
>       if (hfontSpecial[Index] != NULL)
>           DeleteObject(hfontSpecial[Index]);
>     
>       /* store width and height back into the lpRect structure */
>       if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
>           lpRect->right = lpRect->left + MinWidth;
>           if (lpRect->top < 0)
>               lpRect->bottom = lpRect->top - (Height + LineHeight);
>           else
>               lpRect->bottom = lpRect->top + Height + LineHeight;
>       } /* if */
>     
>       return Height;
> }
> 
> 
> 
> 
> Joseph M. Newcomer a �crit :
>> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> 
>> wrote:
>>
>>> Hi,
>>>
>>> I would like to modify a function used to render some HTML and use 
>>> the font I have choosen :
>>>
>>>
>>> // C functions
>>> int __stdcall DrawHTML(
>>>                        HDC     hdc,        // handle of device context
>>>                        LPCTSTR lpString,   // address of string to draw
>>>                        int     nCount,     // string length, in 
>>> characters
>>>                        LPRECT  lpRect,     // address of structure 
>>> with formatting dimensions
>>>                        UINT    uFormat     // text-drawing flags
>>>                        )
>>> {
>>> ...
>>>
>>>
>>> /* get the "default" font from the DC */
>>>     SavedDC = SaveDC(hdc);
>> ****
>> You do a SaveDC but not a RestoreDC?  ****
>>>     hfontBase = (HFONT)SelectObject(hdc, 
>>> (HFONT)GetStockObject(SYSTEM_FONT));
>>>     SelectObject(hdc, hfontBase);
>> ****
>> It would be easier to write
>>     hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>> and not worry about the SelectObject pair
>> ****
>>>     /* clear the other fonts, they are created "on demand" */
>>>     for (Index = 0; Index < FV_NUMBER; Index++)
>>>         hfontSpecial[Index] = NULL;
>>>     hfontSpecial[0] = hfontBase;
>> ****
>> Note that if, in between times, the font which is currently selected 
>> into the DC is
>> deleted, the old handle you have saved here will become meaningless.  
>> Therefore, you
>> cannot rely on the fact that this handle will still be valid at the 
>> time you use it.
>> Better to do an array of LOGFONT values, rather than an array of HFONTs.
>> ****
>>> ...
>>> }
>>>
>>>
>>> Here is my code :
>>>
>>>
>>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM 
>>> *pItem, BOOL bSelected)
>>> {
>>>
>>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>>
>>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(), 
>>>
>>>             &rc,DT_LEFT|DT_WORDBREAK);
>> ****
>> So why do you save the font in the MemDC when you don't actually use 
>> it?  Note that the
>> m_font handle must represent a valid font to be selected, but the line 
>> seems to have no
>> meaning as shown in this function.  I would also suggest something like
>>     HDC dc = pDC->GetSafeHdc();
>>     if(dc == NULL)
>>         return;
>>                DrawHTML(dc, ...as above...);
>>> }
>>>
>>>
>>>
>>> My problem is I don't know how to modify DrawHTML to take the font 
>>> specified in DrawItem because from what I understand DrawHTML is 
>>> using a default font :
>>>
>>> hfontBase = (HFONT)SelectObject(hdc, 
>>> (HFONT)GetStockObject(SYSTEM_FONT));
>>>     SelectObject(hdc, hfontBase);
>>>
>> ****
>> I don't see the relationship of the above code to the problem.  Where 
>> is this line of
>> code?  I also could not find any method called DrawHTML in the MSDN 
>> documentation, could
>> you say more about where it is implemented or what it is supposed to do?
>>                     joe
>> ****
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
0
8/20/2007 1:41:06 PM
See below,,,
On Mon, 20 Aug 2007 15:37:16 +0200, mosfet <john.doe@anonymous.org> wrote:

>Actually I want to use the following control 
>http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
>that's not the question) that is a Custom CListCtrl deriving from CWnd.
>It's appropriate because on smartphone you don't have much space and 
>this listctrl allow to have a different size for each row in addtion to 
>support a few HTML tags.
>
>But when reading the code I saw that it uses hfontBase = 
>(HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
>think it would be better to use the font selected in the control.
>For instanc I could do a SetFont on my listctrl and the DrawHTML 
>function should use it to do its rendering (bold, italic, ...)
>
>
>
>About savedc and restordc it's because I haven't posted all the code.
>
>int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
>formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>					   )
>{
>	LPCTSTR Start;
>	int Left, Top, MaxWidth, MinWidth, Height;
****
You should avoid commas in declaration lists.  It makes the code unreadable, and hard to
edit.  One variable, one line should be the rule.
****
>	int SavedDC;
>	int Tag, TokenLength;
>	HFONT hfontBase, hfontSpecial[FV_NUMBER];
>	int Styles, CurStyles;
>	SIZE size;
>	int Index, LineHeight;
>	POINT CurPos;
>	int WidthOfSPace, XPos;
>	BOOL WhiteSpace;
>	RECT rc;
>	
>	if (hdc == NULL || lpString == NULL)
>		return 0;
>	if (nCount < 0)
>		nCount = _tcslen(lpString);
>	
>	if (lpRect != NULL) {
>		Left = lpRect->left;
>		Top = lpRect->top;
>		MaxWidth = lpRect->right - lpRect->left;
>	} else {
>		GetCurrentPositionEx(hdc, &CurPos);
>		Left = CurPos.x;
>		Top = CurPos.y;
>		MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
****
Note that this is very sensitive to where the current position is; can you really trust it
to be in a sensible place?
****
>	} /* if */
****
It is good to indicate the end of nested structures, but this tends to break down if you
have a nested if.  I tend to something stronger:
	if(lpRect != NULL)
	    { /* Use given rect */
	     ... code here
	    } /* Use given rect */
	else
	   { /* Compute default rect */
	    ... code here
	   } /* Compute default rect */

This deals with one of our weaknesses as human beings: we cannot cope well with nesting.
My editor, when I type {, puts in a comment and leaves me in the middle ready to type the
contents; when I type }, my editor grabs the comment from the matching { and duplicates
it, meaning I never, ever have to guess which } matches which {.  
****
>	if (MaxWidth < 0)
>		MaxWidth = 0;
>	
>	/* toggle flags we do not support */
****
Actually, you are not "toggling" them (which would imply setting them to the opposite of
their current value), you are "clearing" them.  And the next line "sets" others.
****
>	uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
>	uFormat |= (DT_LEFT | DT_NOPREFIX);
>	
>	/* get the "default" font from the DC */
>	SavedDC = SaveDC(hdc);
>	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>	SelectObject(hdc, hfontBase);
***
But the above two lines with SelectObject is now meaningless!
Get rid of these two lines, since GetCurrentObject does what you need! 
****
>	/* clear the other fonts, they are created "on demand" */
>	for (Index = 0; Index < FV_NUMBER; Index++)
>		hfontSpecial[Index] = NULL;
****
What if they weren't already NULL?  If they already existed, you now have a handle leak.
They should be cleared when the fonts are deleted using ::DeleteObject, not here.
****
>	hfontSpecial[0] = hfontBase;
>	Styles = 0; /* assume the active font is normal weight, roman, 
>non-underlined */
>	
>				/* get font height (use characters with ascender and descender);
>				* we make the assumption here that changing the font style will
>				* not change the font height
>	*/
>	GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
>	LineHeight = size.cy;
****
GetTextMetrics would be a better choice here, since you can't really depend on how the
font represents �.  You would then use the tmHeight for line height, although you usually
get a better result from using tmHeight + tmInternalLeading.  These will account for all
the ascender/descender values, not just the incidental representations of two characters
(which may not have ascenders and descenders in a particular font)
****
>	
>	/* run through the string, word for word */
***
This code is a bit dangerous, because you really don't know what a "word" is (there is a
myth that words are separated by whitespace, which is only true in a limited number of
languages)
>	XPos = 0;
>	MinWidth = 0;
>	stacktop = 0;
>	CurStyles = -1; /* force a select of the proper style */
>	Height = 0;
>	WhiteSpace = FALSE;
>	
>	Start = lpString;
>	for ( ;; ) {
>		Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
>		if (Tag < 0)
>			break;
>		switch (Tag & ~ENDFLAG) {
>		case tP:
****
Putting comments like <p> would make it a little easier to understand what is going on
here...
****
>			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>				if (Start != lpString)
>					Height += 3 * LineHeight / 2;
>				XPos = 0;
>			} /* if */
>			break;
>		case tBR:
>			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>				Height += LineHeight;
>				XPos = 0;
>			} /* if */
>			break;
>		case tB:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | FV_BOLD;
>			break;
>		case tI:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | FV_ITALIC;
>			break;
>		case tU:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
>FV_UNDERLINE;
>			break;
>		case tSUB:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
>FV_SUBSCRIPT;
>			break;
>		case tSUP:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles | 
>FV_SUPERSCRIPT;
>			break;
>		case tFONT:
>			if ((Tag & ENDFLAG) == 0) {
>				if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
>					PushColor(hdc, ParseColor(Start + 12));
****
This really makes a very strong assumption which is almost certainly not true, that the
specification is always 
	<font color="colorid">
but it could just as easily be 
	<font size="3" color="colorid">
so you really have to parse the parameters as an unordered set.
****
>			} else {
>				PopColor(hdc);
****
Actually, you need to pop the entire font context, not just the color, because a font
specification could change the size as well.
****
>			} /* if */
>			break;
>		default:
****
What about &-escapes such as &lt;?
****
>			if (Tag == (tNONE | ENDFLAG))
>				break;
>			if (CurStyles != Styles) {
>				if (hfontSpecial[Styles] == NULL)
>					hfontSpecial[Styles] = GetFontVariant(hdc, hfontBase, Styles);
>				CurStyles = Styles;
>				SelectObject(hdc, hfontSpecial[Styles]);
>				/* get the width of a space character (for word spacing) */
>				GetTextExtentPoint32(hdc, _T(" "), 1, &size);
>				WidthOfSPace = size.cx;
>			} /* if */
>			/* check word length, check whether to wrap around */
>			GetTextExtentPoint32(hdc, Start, TokenLength, &size);
****
As I learned to my dismay, this isn't really reliable for languages other than English. It
doesn't work with certain accented characters even in English. This gets you into issues
such as proper handling of Unicode.  You would be better off using DrawText, which should
do the correct font computations correctly.  Generally, trying to do layout on your own is
very risky.  Perhaps Mihai can jump in here; he's one of the Unicode layout experts.  I
got into serious trouble trying to do word breaks in a client app, mostly because the
client gave me a set of "critical" specs that were incompatible with the reality of
international fonts, and it took a massive amount of effort to get them to change the
specs to recognize the fact that their specs wouldn't work.
**** 
>			if (size.cx > MaxWidth)
>				MaxWidth = size.cx;   /* must increase width: long non-breakable word */
>			if (WhiteSpace)
>				XPos += WidthOfSPace;
>			if (XPos + size.cx > MaxWidth && WhiteSpace) {
>				if ((uFormat & DT_WORDBREAK) != 0) {
>					/* word wrap */
>					Height += LineHeight;
>					XPos = 0;
>				} else {
>					/* no word wrap, must increase the width */
>					MaxWidth = XPos + size.cx;
>				} /* if */
>			} /* if */
>			/* output text (unless DT_CALCRECT is set) */
>			if ((uFormat & DT_CALCRECT) == 0) {
>				/* handle negative heights, too (suggestion of "Sims")  */
>				/*if (Top < 0)
>				{
>					SetRect(&rc, Left + XPos, Top - Height,
>					Left + MaxWidth, Top - (Height + LineHeight));
>				}
>				else*/
>				{
>					SetRect(&rc, Left + XPos, Top + Height,
>					Left + MaxWidth, Top + Height + LineHeight);
>				}
>				
>				/* reposition subscript text to align below the baseline */
>				DrawText(hdc, Start, TokenLength, &rc,
>					uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | DT_SINGLELINE : 0));
>				
>					/* for the underline style, the spaces between words should be
>					* underlined as well
>				*/
>				if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= WidthOfSPace)
>				{
>					if (Top < 0)
>					{
>						SetRect(&rc, Left + XPos - WidthOfSPace, Top - Height,
>							Left + XPos, Top - (Height + LineHeight));
>					}
>					else
>					{
>						SetRect(&rc, Left + XPos - WidthOfSPace, Top + Height,
>							Left + XPos, Top + Height + LineHeight);
>					}
>					DrawText(hdc, _T(" "), 1, &rc, uFormat);
>				} /* if */
>			} /* if */
>			/* update current position */
>			XPos += size.cx;
>			if (XPos > MinWidth)
>				MinWidth = XPos;
>			WhiteSpace = FALSE;
>     } /* if */
>	
>     Start += TokenLength;
>   } /* for */
>
>   RestoreDC(hdc, SavedDC);
>   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
>hfontSpecial[0] */
>	  if (hfontSpecial[Index] != NULL)
>		  DeleteObject(hfontSpecial[Index]);
***
This is where you should set the handles to NULL.  Not at the beginning.

Overall, there are a huge number of potential problems here as soon as you move outside
English, and the issue of height and word break needs to be treated in a more
culturally-neutral fashion.
***
>	
>	  /* store width and height back into the lpRect structure */
>	  if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
>		  lpRect->right = lpRect->left + MinWidth;
>		  if (lpRect->top < 0)
>			  lpRect->bottom = lpRect->top - (Height + LineHeight);
>		  else
>			  lpRect->bottom = lpRect->top + Height + LineHeight;
>	  } /* if */
>	
>	  return Height;
>}
>
>
>
>
>Joseph M. Newcomer a �crit :
>> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:
>> 
>>> Hi,
>>>
>>> I would like to modify a function used to render some HTML and use the 
>>> font I have choosen :
>>>
>>>
>>> // C functions
>>> int __stdcall DrawHTML(
>>>                        HDC     hdc,        // handle of device context
>>>                        LPCTSTR lpString,   // address of string to draw
>>>                        int     nCount,     // string length, in characters
>>>                        LPRECT  lpRect,     // address of structure with 
>>> formatting dimensions
>>>                        UINT    uFormat     // text-drawing flags
>>> 					   )
>>> {
>>> ...
>>>
>>>
>>> /* get the "default" font from the DC */
>>> 	SavedDC = SaveDC(hdc);
>> ****
>> You do a SaveDC but not a RestoreDC?  
>> ****
>>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>> 	SelectObject(hdc, hfontBase);
>> ****
>> It would be easier to write
>> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>> and not worry about the SelectObject pair
>> ****
>>> 	/* clear the other fonts, they are created "on demand" */
>>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>>> 		hfontSpecial[Index] = NULL;
>>> 	hfontSpecial[0] = hfontBase;
>> ****
>> Note that if, in between times, the font which is currently selected into the DC is
>> deleted, the old handle you have saved here will become meaningless.  Therefore, you
>> cannot rely on the fact that this handle will still be valid at the time you use it.
>> Better to do an array of LOGFONT values, rather than an array of HFONTs.
>> ****
>>> ...
>>> }
>>>
>>>
>>> Here is my code :
>>>
>>>
>>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>>> BOOL bSelected)
>>> {
>>>
>>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>>
>>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>>> 			&rc,DT_LEFT|DT_WORDBREAK);
>> ****
>> So why do you save the font in the MemDC when you don't actually use it?  Note that the
>> m_font handle must represent a valid font to be selected, but the line seems to have no
>> meaning as shown in this function.  I would also suggest something like
>> 	HDC dc = pDC->GetSafeHdc();
>> 	if(dc == NULL)
>> 	    return;
>>                DrawHTML(dc, ...as above...);
>>> }
>>>
>>>
>>>
>>> My problem is I don't know how to modify DrawHTML to take the font 
>>> specified in DrawItem because from what I understand DrawHTML is using a 
>>> default font :
>>>
>>> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>> 	SelectObject(hdc, hfontBase);
>>>
>> ****
>> I don't see the relationship of the above code to the problem.  Where is this line of
>> code?  I also could not find any method called DrawHTML in the MSDN documentation, could
>> you say more about where it is implemented or what it is supposed to do?
>> 					joe
>> ****
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15978)
8/20/2007 2:27:37 PM
Thanks for all this positive remarks but for some of them it may be true 
but not as important as it seems.
For instance about the word break, languages that don't use space as 
separator don't interest me ;-)
if you know a tiny, free, well written HTML engine(engine is not really 
appropriate because I only needs bold italic, font color and size) just 
let me know ...
I am not interested by CHtmlView or this kind of solution because it 
takes too much space for what I need.



Joseph M. Newcomer a �crit :
> See below,,,
> On Mon, 20 Aug 2007 15:37:16 +0200, mosfet <john.doe@anonymous.org> wrote:
> 
>> Actually I want to use the following control 
>> http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
>> that's not the question) that is a Custom CListCtrl deriving from CWnd.
>> It's appropriate because on smartphone you don't have much space and 
>> this listctrl allow to have a different size for each row in addtion to 
>> support a few HTML tags.
>>
>> But when reading the code I saw that it uses hfontBase = 
>> (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
>> think it would be better to use the font selected in the control.
>> For instanc I could do a SetFont on my listctrl and the DrawHTML 
>> function should use it to do its rendering (bold, italic, ...)
>>
>>
>>
>> About savedc and restordc it's because I haven't posted all the code.
>>
>> int __stdcall DrawHTML(
>>                        HDC     hdc,        // handle of device context
>>                        LPCTSTR lpString,   // address of string to draw
>>                        int     nCount,     // string length, in characters
>>                        LPRECT  lpRect,     // address of structure with 
>> formatting dimensions
>>                        UINT    uFormat     // text-drawing flags
>> 					   )
>> {
>> 	LPCTSTR Start;
>> 	int Left, Top, MaxWidth, MinWidth, Height;
> ****
> You should avoid commas in declaration lists.  It makes the code unreadable, and hard to
> edit.  One variable, one line should be the rule.
> ****
>> 	int SavedDC;
>> 	int Tag, TokenLength;
>> 	HFONT hfontBase, hfontSpecial[FV_NUMBER];
>> 	int Styles, CurStyles;
>> 	SIZE size;
>> 	int Index, LineHeight;
>> 	POINT CurPos;
>> 	int WidthOfSPace, XPos;
>> 	BOOL WhiteSpace;
>> 	RECT rc;
>> 	
>> 	if (hdc == NULL || lpString == NULL)
>> 		return 0;
>> 	if (nCount < 0)
>> 		nCount = _tcslen(lpString);
>> 	
>> 	if (lpRect != NULL) {
>> 		Left = lpRect->left;
>> 		Top = lpRect->top;
>> 		MaxWidth = lpRect->right - lpRect->left;
>> 	} else {
>> 		GetCurrentPositionEx(hdc, &CurPos);
>> 		Left = CurPos.x;
>> 		Top = CurPos.y;
>> 		MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
> ****
> Note that this is very sensitive to where the current position is; can you really trust it
> to be in a sensible place?
> ****
>> 	} /* if */
> ****
> It is good to indicate the end of nested structures, but this tends to break down if you
> have a nested if.  I tend to something stronger:
> 	if(lpRect != NULL)
> 	    { /* Use given rect */
> 	     ... code here
> 	    } /* Use given rect */
> 	else
> 	   { /* Compute default rect */
> 	    ... code here
> 	   } /* Compute default rect */
> 
> This deals with one of our weaknesses as human beings: we cannot cope well with nesting.
> My editor, when I type {, puts in a comment and leaves me in the middle ready to type the
> contents; when I type }, my editor grabs the comment from the matching { and duplicates
> it, meaning I never, ever have to guess which } matches which {.  
> ****
>> 	if (MaxWidth < 0)
>> 		MaxWidth = 0;
>> 	
>> 	/* toggle flags we do not support */
> ****
> Actually, you are not "toggling" them (which would imply setting them to the opposite of
> their current value), you are "clearing" them.  And the next line "sets" others.
> ****
>> 	uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
>> 	uFormat |= (DT_LEFT | DT_NOPREFIX);
>> 	
>> 	/* get the "default" font from the DC */
>> 	SavedDC = SaveDC(hdc);
>> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>> 	SelectObject(hdc, hfontBase);
> ***
> But the above two lines with SelectObject is now meaningless!
> Get rid of these two lines, since GetCurrentObject does what you need! 
> ****
>> 	/* clear the other fonts, they are created "on demand" */
>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>> 		hfontSpecial[Index] = NULL;
> ****
> What if they weren't already NULL?  If they already existed, you now have a handle leak.
> They should be cleared when the fonts are deleted using ::DeleteObject, not here.
> ****
>> 	hfontSpecial[0] = hfontBase;
>> 	Styles = 0; /* assume the active font is normal weight, roman, 
>> non-underlined */
>> 	
>> 				/* get font height (use characters with ascender and descender);
>> 				* we make the assumption here that changing the font style will
>> 				* not change the font height
>> 	*/
>> 	GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
>> 	LineHeight = size.cy;
> ****
> GetTextMetrics would be a better choice here, since you can't really depend on how the
> font represents �.  You would then use the tmHeight for line height, although you usually
> get a better result from using tmHeight + tmInternalLeading.  These will account for all
> the ascender/descender values, not just the incidental representations of two characters
> (which may not have ascenders and descenders in a particular font)
> ****
>> 	
>> 	/* run through the string, word for word */
> ***
> This code is a bit dangerous, because you really don't know what a "word" is (there is a
> myth that words are separated by whitespace, which is only true in a limited number of
> languages)
>> 	XPos = 0;
>> 	MinWidth = 0;
>> 	stacktop = 0;
>> 	CurStyles = -1; /* force a select of the proper style */
>> 	Height = 0;
>> 	WhiteSpace = FALSE;
>> 	
>> 	Start = lpString;
>> 	for ( ;; ) {
>> 		Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
>> 		if (Tag < 0)
>> 			break;
>> 		switch (Tag & ~ENDFLAG) {
>> 		case tP:
> ****
> Putting comments like <p> would make it a little easier to understand what is going on
> here...
> ****
>> 			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>> 				if (Start != lpString)
>> 					Height += 3 * LineHeight / 2;
>> 				XPos = 0;
>> 			} /* if */
>> 			break;
>> 		case tBR:
>> 			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>> 				Height += LineHeight;
>> 				XPos = 0;
>> 			} /* if */
>> 			break;
>> 		case tB:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | FV_BOLD;
>> 			break;
>> 		case tI:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | FV_ITALIC;
>> 			break;
>> 		case tU:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
>> FV_UNDERLINE;
>> 			break;
>> 		case tSUB:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
>> FV_SUBSCRIPT;
>> 			break;
>> 		case tSUP:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles | 
>> FV_SUPERSCRIPT;
>> 			break;
>> 		case tFONT:
>> 			if ((Tag & ENDFLAG) == 0) {
>> 				if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
>> 					PushColor(hdc, ParseColor(Start + 12));
> ****
> This really makes a very strong assumption which is almost certainly not true, that the
> specification is always 
> 	<font color="colorid">
> but it could just as easily be 
> 	<font size="3" color="colorid">
> so you really have to parse the parameters as an unordered set.
> ****
>> 			} else {
>> 				PopColor(hdc);
> ****
> Actually, you need to pop the entire font context, not just the color, because a font
> specification could change the size as well.
> ****
>> 			} /* if */
>> 			break;
>> 		default:
> ****
> What about &-escapes such as &lt;?
> ****
>> 			if (Tag == (tNONE | ENDFLAG))
>> 				break;
>> 			if (CurStyles != Styles) {
>> 				if (hfontSpecial[Styles] == NULL)
>> 					hfontSpecial[Styles] = GetFontVariant(hdc, hfontBase, Styles);
>> 				CurStyles = Styles;
>> 				SelectObject(hdc, hfontSpecial[Styles]);
>> 				/* get the width of a space character (for word spacing) */
>> 				GetTextExtentPoint32(hdc, _T(" "), 1, &size);
>> 				WidthOfSPace = size.cx;
>> 			} /* if */
>> 			/* check word length, check whether to wrap around */
>> 			GetTextExtentPoint32(hdc, Start, TokenLength, &size);
> ****
> As I learned to my dismay, this isn't really reliable for languages other than English. It
> doesn't work with certain accented characters even in English. This gets you into issues
> such as proper handling of Unicode.  You would be better off using DrawText, which should
> do the correct font computations correctly.  Generally, trying to do layout on your own is
> very risky.  Perhaps Mihai can jump in here; he's one of the Unicode layout experts.  I
> got into serious trouble trying to do word breaks in a client app, mostly because the
> client gave me a set of "critical" specs that were incompatible with the reality of
> international fonts, and it took a massive amount of effort to get them to change the
> specs to recognize the fact that their specs wouldn't work.
> **** 
>> 			if (size.cx > MaxWidth)
>> 				MaxWidth = size.cx;   /* must increase width: long non-breakable word */
>> 			if (WhiteSpace)
>> 				XPos += WidthOfSPace;
>> 			if (XPos + size.cx > MaxWidth && WhiteSpace) {
>> 				if ((uFormat & DT_WORDBREAK) != 0) {
>> 					/* word wrap */
>> 					Height += LineHeight;
>> 					XPos = 0;
>> 				} else {
>> 					/* no word wrap, must increase the width */
>> 					MaxWidth = XPos + size.cx;
>> 				} /* if */
>> 			} /* if */
>> 			/* output text (unless DT_CALCRECT is set) */
>> 			if ((uFormat & DT_CALCRECT) == 0) {
>> 				/* handle negative heights, too (suggestion of "Sims")  */
>> 				/*if (Top < 0)
>> 				{
>> 					SetRect(&rc, Left + XPos, Top - Height,
>> 					Left + MaxWidth, Top - (Height + LineHeight));
>> 				}
>> 				else*/
>> 				{
>> 					SetRect(&rc, Left + XPos, Top + Height,
>> 					Left + MaxWidth, Top + Height + LineHeight);
>> 				}
>> 				
>> 				/* reposition subscript text to align below the baseline */
>> 				DrawText(hdc, Start, TokenLength, &rc,
>> 					uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | DT_SINGLELINE : 0));
>> 				
>> 					/* for the underline style, the spaces between words should be
>> 					* underlined as well
>> 				*/
>> 				if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= WidthOfSPace)
>> 				{
>> 					if (Top < 0)
>> 					{
>> 						SetRect(&rc, Left + XPos - WidthOfSPace, Top - Height,
>> 							Left + XPos, Top - (Height + LineHeight));
>> 					}
>> 					else
>> 					{
>> 						SetRect(&rc, Left + XPos - WidthOfSPace, Top + Height,
>> 							Left + XPos, Top + Height + LineHeight);
>> 					}
>> 					DrawText(hdc, _T(" "), 1, &rc, uFormat);
>> 				} /* if */
>> 			} /* if */
>> 			/* update current position */
>> 			XPos += size.cx;
>> 			if (XPos > MinWidth)
>> 				MinWidth = XPos;
>> 			WhiteSpace = FALSE;
>>     } /* if */
>> 	
>>     Start += TokenLength;
>>   } /* for */
>>
>>   RestoreDC(hdc, SavedDC);
>>   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
>> hfontSpecial[0] */
>> 	  if (hfontSpecial[Index] != NULL)
>> 		  DeleteObject(hfontSpecial[Index]);
> ***
> This is where you should set the handles to NULL.  Not at the beginning.
> 
> Overall, there are a huge number of potential problems here as soon as you move outside
> English, and the issue of height and word break needs to be treated in a more
> culturally-neutral fashion.
> ***
>> 	
>> 	  /* store width and height back into the lpRect structure */
>> 	  if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
>> 		  lpRect->right = lpRect->left + MinWidth;
>> 		  if (lpRect->top < 0)
>> 			  lpRect->bottom = lpRect->top - (Height + LineHeight);
>> 		  else
>> 			  lpRect->bottom = lpRect->top + Height + LineHeight;
>> 	  } /* if */
>> 	
>> 	  return Height;
>> }
>>
>>
>>
>>
>> Joseph M. Newcomer a �crit :
>>> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:
>>>
>>>> Hi,
>>>>
>>>> I would like to modify a function used to render some HTML and use the 
>>>> font I have choosen :
>>>>
>>>>
>>>> // C functions
>>>> int __stdcall DrawHTML(
>>>>                        HDC     hdc,        // handle of device context
>>>>                        LPCTSTR lpString,   // address of string to draw
>>>>                        int     nCount,     // string length, in characters
>>>>                        LPRECT  lpRect,     // address of structure with 
>>>> formatting dimensions
>>>>                        UINT    uFormat     // text-drawing flags
>>>> 					   )
>>>> {
>>>> ...
>>>>
>>>>
>>>> /* get the "default" font from the DC */
>>>> 	SavedDC = SaveDC(hdc);
>>> ****
>>> You do a SaveDC but not a RestoreDC?  
>>> ****
>>>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>>> 	SelectObject(hdc, hfontBase);
>>> ****
>>> It would be easier to write
>>> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>>> and not worry about the SelectObject pair
>>> ****
>>>> 	/* clear the other fonts, they are created "on demand" */
>>>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>>>> 		hfontSpecial[Index] = NULL;
>>>> 	hfontSpecial[0] = hfontBase;
>>> ****
>>> Note that if, in between times, the font which is currently selected into the DC is
>>> deleted, the old handle you have saved here will become meaningless.  Therefore, you
>>> cannot rely on the fact that this handle will still be valid at the time you use it.
>>> Better to do an array of LOGFONT values, rather than an array of HFONTs.
>>> ****
>>>> ...
>>>> }
>>>>
>>>>
>>>> Here is my code :
>>>>
>>>>
>>>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>>>> BOOL bSelected)
>>>> {
>>>>
>>>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>>>
>>>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>>>> 			&rc,DT_LEFT|DT_WORDBREAK);
>>> ****
>>> So why do you save the font in the MemDC when you don't actually use it?  Note that the
>>> m_font handle must represent a valid font to be selected, but the line seems to have no
>>> meaning as shown in this function.  I would also suggest something like
>>> 	HDC dc = pDC->GetSafeHdc();
>>> 	if(dc == NULL)
>>> 	    return;
>>>                DrawHTML(dc, ...as above...);
>>>> }
>>>>
>>>>
>>>>
>>>> My problem is I don't know how to modify DrawHTML to take the font 
>>>> specified in DrawItem because from what I understand DrawHTML is using a 
>>>> default font :
>>>>
>>>> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>>> 	SelectObject(hdc, hfontBase);
>>>>
>>> ****
>>> I don't see the relationship of the above code to the problem.  Where is this line of
>>> code?  I also could not find any method called DrawHTML in the MSDN documentation, could
>>> you say more about where it is implemented or what it is supposed to do?
>>> 					joe
>>> ****
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>> Joseph M. Newcomer [MVP]
>>> email: newcomer@flounder.com
>>> Web: http://www.flounder.com
>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
0
8/20/2007 3:07:44 PM
Reply:

Similar Artilces:

installing a non-MS font into word
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Hi, I'm trying to download a free font called scriptina <http://www.1001fonts.com/font_details.html?font_id=2873> into word. It won't show up? I was able to get it to install into the text editor. any suggestions?? thanks! heatherc heatherc@officeformac.com wrote: > I'm trying to download a free font called scriptina > <http://www.1001fonts.com/font_details.html?font_id=2873> > into word. > > It won't show up? I was able to get it to install into the text editor. Install fonts in your ma...

i get error 404 not found when trying to download
I'm trying to download nokia pc suite to windows xp to upload gallery onto the computer but get error message404 not found - how can i download this pc suite please -- Krysy Albutt Krysy Albutt wrote: > I'm trying to download nokia pc suite to windows xp to upload gallery > onto the computer but get error message404 not found - how can i > download this pc suite please Care to enlighten us how this pertains to: - 1) Microsoft 2) Publisher 3) Windows If you're having problems downloading from the *NOKIA* site where do you think you should be directing your ...

Help with font size in Outlook 2003
Hi, how do I increase the font size of the "To" "Bcc" and "From" fields? It's really small and hard to see. I know how to change the font size when composing and viewing so I read it, but the above drives me crazy! Any suggestions or is it even possible to increase the size? Thanks, -- Cheryl ...

How to get Calendar to send me reminders
I have changed my e-mail address but for some reason I cannot get Calendar to send reminders to my new address - I think I have carried out all that is necessary to effect the changover but I am not getting reminders sent. Can anyone help please? Is the Calendar Live ID based and accessible at Calendar.live.com ? -- ....winston ms-mvp mail "Dabardevon" wrote in message = news:FDC2B3B2-EDE4-41B1-BFC4-C0F9ED59CFB9@microsoft.com... I have changed my e-mail address but for some reason I cannot get = Calendar to send reminders to my new address - I think I have...

Some recipients get the attachment, some get winmail.dat
This one has me baffled. We are using Exchange 2000 and Outlook 2000 and have been for 8 months. No previous problems with attachments (.doc, .xls, .jpg). About 2 weeks ago, we started hearing from certain recipients that the attachment wasn't arriving; instead they were getting an unreadable file called winmail.dat. MS says that this is because the sender is using Rich Text to format the email. We have changed the senders to use Plain Text and still have the same problem. If the email is sent to several recipients, some will get the attachment fine, some will not. This didn'...

How to get the CScrollBar's Handle in CTreeCtrl?
Hey,All: I thought I have a problem when I trid to get the CScrollBar's handle from my CTreeCtrl extended handle. Can anybody tell me whether I can get the handle of the CScrollBar from the CTreeCtrl? Thanks in advance! Carl :-| Carl wrote: > Hey,All: > > I thought I have a problem when I trid to get the CScrollBar's handle from > my CTreeCtrl extended handle. > Can anybody tell me whether I can get the handle of the CScrollBar from the > CTreeCtrl? > > Thanks in advance! > Carl > :-| > > Sorry, it is not that simple. The scroll bars that...

A Crystal Beginner
I am using Crystal 9.2.4.77 and have loaded the Crystal enhancements. Now I want to do against the CRM database. What do I do? I thought I would create a data source to the CRM SQLserver, which I did, then connect to it through Crystal Reports. That works, but when I drill down on the AAA_MSCRM database to choose my tables, it shows me dbo as the only option (where did this come from??) and under that are just a few generic tables. No CRM tables. Something's not quite right. What am I missing? file - log on to aps server "KBLawson" <klawson@aetinc.com> wrote in ...

Cannot get fast forward or fast reverse to work with WMP 11
I am running Vista Home Premium on a HP G 217-EM Notebook which comes pre-installed with Windows Media Player 11. When I play cds and try to fast forward or fast reverse by keeping the fast forward or fast reverse buttons constantly depressed nothing happens. Why is this, and can anyone come up with a solution? Many thanks This doesn't work on my system either, so it's probably just a limitation of WMP. Fast forward and fast reverse should work fine when you rip the CD's to MP3 or WMA files, and play these files instead. Regards -- Tim De Baets http://www....

Get paid while you get online!!
I found a great Internet company - Cashfiesta.com - that has created a product everyone can benefit from. They pay you while you work or play on your computer. All you need to do is keep their software - the FiestaBar=99 - active while you are online. They even pay you when your friends are using their computers. Unlike other companies, Cashfiesta gives you control over how much money you earn. They have an individual payrate based on the number of Special Offers you sign up for. As some of these offers are free, you can increase your payrate up to 33 times without spending a penny. It's...

Spreadsheet getting corrupted
Hello All: I have a relatively large spreadsheet. I am getting errors (see after my signature line). What could be causing these errors? Is it that the spreadsheet is too large? Thanks Deguza -------------------------------------------------------- Microsoft Office Excel File Repair Log Errors were detected in file 'C:\Documents and Settings\deguza\My Documents\sales\Sales_2006_2007.xls' The following is a list of repairs: Global PivotTable report information was repaired due to integrity problems. Global PivotTable report information was repaired due to integrity problems. Glo...

Can't get auto-update (update) to install
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC I've been trying to manually check for updates to Word 2008, and I get a &quot;critical update&quot; notice, asking me to install auto-update. When I try to install it, I cannot. It just keeps repeating the attempt, in an &quot;endless loop.&quot; What to do? <br> Thank you. ...

Reg getting the next IV Document Number field !
Hi, I am creating a window in dexterity similar to the item transaction entry window (Transactions>Inventory> Transaction Entry). In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field. I wanted to know if there is any function , or table that i can access to get the next document number in the new window that i am creating. Thanks, swetha -- swetha >In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field.< T...

How do I get??
Sorry if this seems a fairly easy question to you guys. I have a spreadsheet and I need to get the current system time into a cell. The format of the time is hh:mm am/pm. Any assistance would be most helpful. Hi try =INT(NOW()) in this cell and format is to your needs -- Regards Frank Kabel Frankfurt, Germany PM wrote: > Sorry if this seems a fairly easy question to you guys. > > I have a spreadsheet and I need to get the current system time into a > cell. The format of the time is hh:mm am/pm. > > Any assistance would be most helpful. PM, in the cell you want pu...

Get notified when Out of Office is on
I am using Outlook 2007. With 2003, when returning from leave, I used to get a notification that the Outlook out of office was still on and asking me if I wanted to switch it off. This reminder no longer appears with 2007. How can I switch this setting on so that I get the notification? "Mary Ann" <MaryAnn@discussions.microsoft.com> wrote in message news:ED5533A7-D0EA-41B8-B1A0-A9D15FB6FD98@microsoft.com... >I am using Outlook 2007. With 2003, when returning from leave, I used to get > a notification that the Outlook out of office was still on and asking me ...

problems copying invoice form but then changing to a different font
I've downloaded an Invoice form (in .doc format) but the downloaded version has a font where all the letters appear unnaturally compressed. I've tried to change it to a more readable font (select all, then changed font to Arial, size to 10). Now the letters/font look good but the different lines and text entries are in the wrong positions. It looks like the size of the original page won't accomodate the new font and parts of the text have shifted to incorrect positions. If this is just a page size problem, how would I go about adjusting the new document before I change...

Getting Control ID in Active X control
GetWindowLong return 0. You need to call GetDlgCtrlID from outside the activex control as the function available within the control returns an arbitrary value of zero. Take a look at this article http://xendra.ens.uabc.mx/~sinfante/loo/libro/ch17_4.htm particularly the paragraph preceeding the title "MFC and Ambient Properties". This really begs the question why you want the ID in the first place as activex controls have to be fully self containing to operate - with a few exceptions where sibling controls need to be able to locate each other. - Tim "ytv" <...

over VPN, it gets stuck when sending outgoing email
When I use VPN to connect to work from home, the outlook can not finish sending outgoing emails. The progress bar moves to the end but then stops there forever. It can never finish. The receiving of new incoming emails work fine. All other network functionality works, e.g. internet browsing, telnet, ftp, etc, all work fine. My system is win2k. I use linksys wireless DSL router. I'd appreciate any hint! Are you using Exchange server? I'd set up your mail profile to prompt you to work offline or online - when using VPN, work offline with scheduled syncs. If not using exchange, pos...

Get photos from a camera
I have an asp.net intranet application that I need to upload 1 or all photos from a digital camera at a PC workstation. We are using DataGrids and GridViews to display them on the web once they are uploaded but need something at the client. I assume I need some sort of ActiveX process or something. Has anyone run into a solution for this need? Thanks. -- David "DavidC" <dlchase@lifetimeinc.com> wrote in message news:2B061F4F-B548-4AA4-96FA-2F87383192D2@microsoft.com... > I have an asp.net intranet application that I need to upload 1 or all > photos ...

how to get the format of this cell right?
When I let go: Selection.Replace " ", Replacement:="-", Lookat:=xlPart, _ SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False " " is entered by means of an array: Words = Array(" ", "+", "/", "---", "--", "&") on a cell containing: 5 a I would expect to get: 5-a as a result. Unfortunately, it produces 5:00:00-AM. How can I solve this tiny but frustrating problem? best regards Pet...

how to get the pointer variable address from a dll
hi all, I have a DLL which has a output parameter LPVOID, A application calls this DLL function, the Dll responsibility is to assign a valid pointer to the lpBuffer, Till here it is OK, but once it returns to the Application this lpBuffer becomes NULL. Prototype, __declspec(dllexport) BOOL TRSTMonGetStatus(LPVOID lpBuffer) Please let me know what to do, I am stuck in this. try this __declspec(dllexport) BOOL TRSTMonGetStatus(LPVOID &lpBuffer) AliR. <karunyalakshmi@gmail.com> wrote in message news:1182179607.989434.318540@x35g2000prf.googlegroups.com... > > hi a...

How do I get my best friend back?
I NEED TO KNOW "monsterboy16" <monsterboy16@discussions.microsoft.com> wrote in message news:7918DF09-EB34-46E4-852E-8DAAC3FFF45F@microsoft.com... > I NEED TO KNOW Easy. Just lift the lid on your toilet seat and whistle. Dipshit! -- "Don't pick a fight with an old man. If he is too old to fight, he'll just kill you." Pretend that you're in a coma and unable to communicate in any way (such as posting messages in newsgroups). "monsterboy16" <monsterboy16@discussions.microsoft.com> wrote in message news...

Why do I get this?
IMCEAEX-_O=ABC_OU=CN121_CN=RECIPIENTS_CN=USER1@companyABC.com <-- why am I getting this as the FROM field from a recently upgrade user to Exchange 2003? ...

Excel Data List Gets "Stuck" -- Help
This has now happened for the second time. I have a "data list" that is around 1800 rows in size. Somcetimes, after I've filtered the data to show just a small number of rows, it gets "stuck." I I am no longer able to expand the list to show all the rows. I've gone in to all the columns and chosen "All" for all the columns and it still does not work. I know I can highight the entire list and tell it to remove the list and recreate the list, but that's a pain, and I lose some formatting. Can anyone help me? -- slobizman -----------------------...

how do you get umlauts?
I've changed the language to German but how do I get umlauts helen <helen@discussions.microsoft.com> was very recently heard to utter: > I've changed the language to German but how do I get umlauts a) Change your keyboard layout to German in Regional Settings. The umlauted letters are then where ', ;, and [ are on a standard UK keyboard (uncertain about USA) (� is where - is) or b) Use Insert > Symbol or c) Memorise the character codes. To get � for example, hold down Alt and tap 0252 on your numeric keypad, then release Alt. 0223 is �, 0246 is �, and 0228 is ...

Get this error trying to get @live.com mail to sync with Windows M
[error messge] Account: 'pop3.live.com', Server: 'pop3.live.com', Protocol: POP3, Server Response: '-ERR command not implemented', Port: 995, Secure(SSL): Yes, Server Error: 0x800CCC90, Error Number: 0x800CCC18 You enabled an option that your mail server does not support. In Windows Mail go to Tools, Accounts, select that account, Properties, Servers, then uncheck "Log on using Secure Password Authentication". -- Gary VanderMolen, Microsoft MVP (Mail) "JbarJensen" <JbarJensen@discussions.microsoft.com> wrote in message news...