DrawText, logical untits to HORZRES units?

Home built / K9a2 cf-f
February 18, 2010 at 07:19:31
Specs: Windows XP, Athlon xp x2 64 5600 / 2gb
Language: C++
Compiler: Mingw(whatever comes with dev-c++ 5 beta)
Other: Windows Api

Can anyone tell me the correct way to convert logical units for a device context to the equivalent units for "GetDeviceCaps(PrnHdl, HORZRES)" is?

Basically I have this program(alternate version)(Needs to be downloaded as a .midi and renamed to a .zip), file "09_print.cpp" function "PrintAddress", I was updating for the tumble weed and came across a problem, "GetTextExtentPoint32" and "DrawText with DT_CALCRECT" return Logical units where I need the equivalent to "GetDeviceCaps(PrnHdl, HORZRES)" units.

I'm using "CalcRect.right * (GetDeviceCaps(PrnHdl, LOGPIXELSX) / GetDeviceCaps(PrnHdl, HORZSIZE) +1 )" where "CalcRect.right" is the output from "DrawText" with "DT_CALCRECT"(the same number is output from "GetTextExtentPoint32").

Is this the correct way to convert?

I tried "DPtoLP" and "LPtoDP" but got the exact same number out that I put in.

I'm going away sometime on Saturday (gmt+10) and may never come back, if you reply and I don't answer please forgive me, it means I'm gone. I will give a notification post before I go.......

See More: DrawText, logical untits to HORZRES units?

Report •

February 18, 2010 at 18:41:59
Ok I think I have it working, but I still don't really understand how.

       SetMapMode(PrnHdl, MM_LOENGLISH);
        for (int i=0 ; i < TMax ; i++)
            if (FontSize[i])
                SelectObject(PrnHdl, LFontO);
            } else {
                SelectObject(PrnHdl, SFontO);
            DrawText(PrnHdl, AddressText[i].c_str(), -1, &CalcRect,DT_CALCRECT|DT_LEFT|DT_NOPREFIX|DT_NOCLIP);
            UnitConv.x = CalcRect.right;
            UnitConv.y = 0;
            LPtoDP(PrnHdl, &UnitConv, 1);
            if ( UnitConv.x / 2 > GetDeviceCaps(PrnHdl, HORZRES)- (2 * XPMarg))

The thing that bugs me is the "/ 2", because I have no idea
what LPtoDP exactly does.....

Report •

February 18, 2010 at 23:53:39
This seems to be equivalent to LPtoDP(In this circumstance):

CalcRect.right * GetDeviceCaps(PrnHdl, LOGPIXELSX) / 100

I still can't figure out why this double what it should be.....

Anyway thanks to anyone that looked in, I'm done
with it.

Report •

February 19, 2010 at 00:37:40
I can't believe it, I was selecting the wrong font!!

CalcRect.right on it's own works perfectly fine............

Report •

Related Solutions

February 19, 2010 at 05:17:02
Thanks Judago!

I couldn't have solved it without you!

Have a good one!

Report •

Ask Question