Welcome Guest Search | Active Topics | Members | Log In | Register

Get CDC or HDC Object Options
addict
Posted: Thursday, May 22, 2008 12:38:41 PM
Rank: Newbie
Groups: Member

Joined: 2/20/2008
Posts: 4
Points: 12
Location: Swiss
I've the problem that I have a lot of text. Now I want to calculate how many pages I need. For that I need a cdc or HDC object of the library how can I get that object?
hm
Posted: Thursday, May 22, 2008 3:57:42 PM

Rank: Administration
Groups: Administration , Member

Joined: 7/17/2007
Posts: 8
Points: 27
Location: Saint-Petersburg
To get metrics of fonts you can use next piece of code:

Quote:

HDC dc=CreateDC(_T("DISPLAY"),0,0,0);

BESTVIEW::COREPREVIEW_PAGESIZE CorePreviewPageSize;
ZeroMemory(&CorePreviewPageSize,sizeof(CorePreviewPageSize));
// let it be A4 sheet, i.e. 210 x 297 mm
CorePreviewPageSize.dwSize=sizeof(CorePreviewPageSize);
CorePreviewPageSize.dwPageWidth=21000;
CorePreviewPageSize.dwPageHeight=29700;
// with 10 mm margins
CorePreviewPageSize.dwLeftOffset=1000;
CorePreviewPageSize.dwTopOffset=1000;
CorePreviewPageSize.dwWidth=CorePreviewPageSize.dwPageWidth-2*CorePreviewPageSize.dwTopOffset;
CorePreviewPageSize.dwHeight=CorePreviewPageSize.dwPageHeight-2*CorePreviewPageSize.dwLeftOffset;


BESTVIEW::COREPREVIEW_COORDINATESPACE CoordinateSpace;
ZeroMemory(&CoordinateSpace,sizeof(CoordinateSpace));
CoordinateSpace.dc=dc;
CoordinateSpace.ViewportOrgXOffset=0;
CoordinateSpace.ViewportOrgYOffset=0;
// should be a positive value, let it be CorePreviewPageSize.dwPageWidth
CoordinateSpace.ViewportExtWidth=CorePreviewPageSize.dwPageWidth;
// should be a positive value, let it be CorePreviewPageSize.dwPageHeight
CoordinateSpace.ViewportExtHeight=CorePreviewPageSize.dwPageHeight;


// here we configure HDC
BESTVIEW::bvSetHdcCoordinateSpace(&CoordinateSpace,&CorePreviewPageSize);


LOGFONT LogFont;
ZeroMemory(&LogFont,sizeof(LogFont));
LogFont.lfHeight=BESTVIEW::bvCalculateFontSize(24);
LogFont.lfOutPrecision=OUT_TT_PRECIS;
LogFont.lfQuality =PROOF_QUALITY;
LogFont.lfWeight = FW_NORMAL;
LogFont.lfOutPrecision=OUT_DEFAULT_PRECIS;
LogFont.lfCharSet=DEFAULT_CHARSET;
_tcscpy(LogFont.lfFaceName,_T("Arial"));

HFONT hFont=CreateFontIndirect(&LogFont);
HFONT hOldFont=(HFONT) SelectObject(dc,hFont);

TEXTMETRIC TextMetric;
ZeroMemory(&TextMetric,sizeof(TextMetric));

BOOL b=GetTextMetrics(dc,&TextMetric);

SelectObject(dc,hOldFont);
DeleteObject(hFont);

DeleteDC(dc);



In this example I retrieve data for the TEXTMETRIC struct.
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

Powered by Yet Another Forum.net version 1.9.0 (NET v2.0) - 10/10/2006
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.349 seconds.