Click here to Skip to main content
16,014,860 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralConverting HDC to HBitmap Pin
Adrenalin27-May-02 22:55
Adrenalin27-May-02 22:55 
GeneralRe: Converting HDC to HBitmap Pin
Ernest Laurentin28-May-02 6:06
Ernest Laurentin28-May-02 6:06 
GeneralListview control Pin
Adrenalin27-May-02 22:49
Adrenalin27-May-02 22:49 
GeneralRe: Listview control Pin
Prem Kumar27-May-02 23:22
Prem Kumar27-May-02 23:22 
GeneralIncluding MSHTML Pin
rrrado27-May-02 22:53
rrrado27-May-02 22:53 
GeneralRe: Including MSHTML Pin
Rama Krishna Vavilala28-May-02 2:01
Rama Krishna Vavilala28-May-02 2:01 
GeneralRe: Including MSHTML Pin
rrrado28-May-02 3:35
rrrado28-May-02 3:35 
GeneralDrawing rotated WMF Pin
27-May-02 20:57
suss27-May-02 20:57 
I wrote the following functions to draw rotated (0, 90, 180 and 270 degrees) WMF. It almost works, the rotation itself seems to be correct, but the translation is not. I get WMF which is properly rotated, but it is placed in the wrong place.
Note, this function must work under NT 4.0/2000/XP.

What is the reason of this problem?


long G_lHeightWmf = 0, G_lWidthWmf = 0;

static int CALLBACK WMFEnumCallback(HDC hdc,HANDLETABLE *lpHTable,METARECORD *pmfr, int nObj,LPARAM lparam)
{
long width = 0,height = 0;

hdc;lpHTable;nObj;lparam;
if(pmfr->rdFunction==META_SETWINDOWEXT)
{
width=abs((SHORT)pmfr->rdParm[1]);
if(width>G_lWidthWmf)
G_lWidthWmf=width;
height=abs((SHORT)pmfr->rdParm[0]);
if(height>G_lHeightWmf)
G_lHeightWmf=height;
}
return TRUE;
}

void GetSizeWMF(HDC A_hDC,HMETAFILE A_hMetaFile,long *A_pWidth,long *A_pHeight)
{
if(A_hMetaFile!=NULL)
{
G_lWidthWmf=0;
G_lHeightWmf=0;
EnumMetaFile(A_hDC,A_hMetaFile,WMFEnumCallback,0); // <--to calcule size wmf
*A_pWidth=G_lWidthWmf;
*A_pHeight=G_lHeightWmf;
}
}

void DrawWMF(HDC A_hDC,RECT *A_pRect,HMETAFILE A_Hmf, bool A_bDrawRotated/* = false*/)
{
POINT ptRect[2], ptSize[2] = {0};
SIZE sizeViewNew, sizeViewNewLP;
int nSavedDC;
BOOL bOK = TRUE;
XFORM XForm, XFormSaved;
int nGraphMode = 0;
float fPixelXPermm(0.f), fPixelYPermm(0.f);
float fScaleXY(1.f), fScaleYX(1.f);
CRect rcNormal(A_pRect->left, A_pRect->top, A_pRect->right, A_pRect->bottom);
long dx = 0, dy = 0;

rcNormal.NormalizeRect();

if(A_pRect != NULL && A_Hmf != NULL)
{
rcNormal.SetRect(A_pRect->left, A_pRect->top, A_pRect->right, A_pRect->bottom);
rcNormal.NormalizeRect();

if(GetDeviceCaps(A_hDC,TECHNOLOGY)!=DT_METAFILE)
{
fPixelXPermm = GetDeviceCaps(A_hDC,LOGPIXELSX)/MMPERINCH;
fPixelYPermm = GetDeviceCaps(A_hDC,LOGPIXELSY)/MMPERINCH;
}
else
{
HDC hScreenDC = GetDC(NULL);
fPixelXPermm = GetDeviceCaps(hScreenDC,LOGPIXELSX)/MMPERINCH;
fPixelYPermm = GetDeviceCaps(hScreenDC,LOGPIXELSY)/MMPERINCH;
ReleaseDC(NULL, hScreenDC);
}
ptRect[0].x = rcNormal.left;
ptRect[0].y = rcNormal.top;
ptRect[1].x = rcNormal.right;
ptRect[1].y = rcNormal.bottom;

bOK = LPtoDP(A_hDC, ptRect, 2);
sizeViewNew.cx = abs(ptRect[1].x - ptRect[0].x);
sizeViewNew.cy = abs(ptRect[1].y - ptRect[0].y);
ptSize[1].x = sizeViewNew.cx;
DPtoLP(A_hDC, ptSize, 2);
sizeViewNewLP.cx = abs(ptSize[1].x-ptSize[0].x);
ptSize[0].x = 0;
ptSize[0].y = 0;
ptSize[1].x = 0;
ptSize[1].y = sizeViewNew.cy;
DPtoLP(A_hDC, ptSize, 2);
sizeViewNewLP.cy = abs(ptSize[1].y-ptSize[0].y);

if(bOK && sizeViewNew.cx > 0 && sizeViewNew.cy > 0)
{
fScaleXY = float(sizeViewNew.cx)/sizeViewNew.cy;
fScaleYX = float(sizeViewNew.cy)/sizeViewNew.cx;
nSavedDC = SaveDC(A_hDC);
SetMapMode(A_hDC, MM_ANISOTROPIC);
SetViewportOrgEx(A_hDC, ptRect[0].x, ptRect[0].y, NULL);
SetViewportExtEx(A_hDC, sizeViewNew.cx, sizeViewNew.cy, NULL);

GetSizeWMF(A_hDC, A_Hmf, &dx, &dy);
float sYX = (float)dy/(float)dx;
float sXY = (float)dx/(float)dy;

if(A_bDrawRotated)
{
GetWorldTransform(A_hDC, &XFormSaved);
nGraphMode = GetGraphicsMode(A_hDC);
SetGraphicsMode(A_hDC, GM_ADVANCED);

switch(TGraphicFilesSettings::GetCurrentRotationAngle())
{
case 270:
{
SetViewportOrgEx(A_hDC, ptRect[1].x, ptRect[0].y, NULL);
XForm.eM11 = 0;
XForm.eM12 = sYX;
XForm.eM21 = -sXY;
XForm.eM22 = 0;
XForm.eDx = 0;
XForm.eDy = 0;
break;
}
case 180:
{
SetViewportOrgEx(A_hDC, ptRect[1].x, ptRect[1].y, NULL);
XForm.eM11 = - 1;
XForm.eM12 = 0;
XForm.eM21 = 0;
XForm.eM22 = - 1;
XForm.eDx = 0;
XForm.eDy = 0;
}
break;
case 90:
{
SetViewportOrgEx(A_hDC, ptRect[0].x, ptRect[1].y, NULL);
XForm.eM11 = 0;
XForm.eM12 = -sYX;
XForm.eM21 = sXY;
XForm.eM22 = 0;
XForm.eDx = 0;
XForm.eDy = 0;
}
break;
}
ModifyWorldTransform(A_hDC, NULL, MWT_IDENTITY);
SetWorldTransform(A_hDC, &XForm);
}
PlayMetaFile(A_hDC, A_Hmf);
RestoreDC(A_hDC, nSavedDC);

if(A_bDrawRotated)
{
SetWorldTransform(A_hDC, &XFormSaved);
ModifyWorldTransform(A_hDC, NULL, MWT_IDENTITY);
SetGraphicsMode(A_hDC, nGraphMode);
}
}
}
}

Confused | :confused:
GeneralClass wont work unless global Pin
Mikel27-May-02 19:01
Mikel27-May-02 19:01 
GeneralRe: Class wont work unless global Pin
Joaquín M López Muñoz27-May-02 20:01
Joaquín M López Muñoz27-May-02 20:01 
GeneralRe: Class wont work unless global Pin
Michael P Butler27-May-02 23:25
Michael P Butler27-May-02 23:25 
Generalprocess, thread's memory question Pin
zecodela27-May-02 18:06
zecodela27-May-02 18:06 
GeneralRe: process, thread's memory question Pin
Michael Dunn27-May-02 18:29
sitebuilderMichael Dunn27-May-02 18:29 
GeneralRe: process, thread's memory question Pin
Alexandru Savescu27-May-02 21:58
Alexandru Savescu27-May-02 21:58 
GeneralRe: process, thread's memory question Pin
zecodela27-May-02 23:23
zecodela27-May-02 23:23 
GeneralRe: process, thread's memory question Pin
zecodela27-May-02 23:23
zecodela27-May-02 23:23 
GeneralRe: process, thread's memory question Pin
Alexandru Savescu27-May-02 23:47
Alexandru Savescu27-May-02 23:47 
GeneralRe: process, thread's memory question Pin
zecodela28-May-02 3:12
zecodela28-May-02 3:12 
GeneralBest Way to Get Installed DLL Version Pin
John Clump27-May-02 17:53
John Clump27-May-02 17:53 
GeneralRe: Best Way to Get Installed DLL Version Pin
Alex Cramer27-May-02 18:24
Alex Cramer27-May-02 18:24 
Generalhelp with class project... Pin
C++ Virgin27-May-02 15:01
C++ Virgin27-May-02 15:01 
GeneralRe: help with class project... Pin
Christian Graus27-May-02 15:07
protectorChristian Graus27-May-02 15:07 
GeneralRe: help with class project... Pin
C++ Virgin27-May-02 16:35
C++ Virgin27-May-02 16:35 
GeneralRe: help with class project... Pin
Christian Graus27-May-02 16:48
protectorChristian Graus27-May-02 16:48 
GeneralRe: help with class project... Pin
C++ Virgin27-May-02 17:25
C++ Virgin27-May-02 17:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.