1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
// legacy.cpp
#include <windows.h>
#include "tLegacy.h"
/*
* RectConvertMappings
*
* Purpose:
* Converts the contents of a rectangle from device to logical
* coordinates where the hDC defines the logical coordinates.
*
* Parameters:
* pRect LPRECT containing the rectangle to convert.
* hDC HDC describing the logical coordinate system.
* if NULL, uses a screen DC in MM_LOMETRIC.
* fToDevice BOOL TRUE to convert from uConv to device,
* FALSE to convert device to uConv.
*
* Return Value:
* None
*/
void RectConvertMappings(LPRECT pRect, HDC hDC, BOOL fToDevice)
{
POINT rgpt[2];
BOOL fSysDC=FALSE;
if (NULL==pRect)
return;
rgpt[0].x=pRect->left;
rgpt[0].y=pRect->top;
rgpt[1].x=pRect->right;
rgpt[1].y=pRect->bottom;
if (NULL==hDC)
{
hDC=GetDC(NULL);
SetMapMode(hDC, MM_LOMETRIC);
fSysDC=TRUE;
}
if (fToDevice)
LPtoDP(hDC, rgpt, 2);
else
DPtoLP(hDC, rgpt, 2);
if (fSysDC)
ReleaseDC(NULL, hDC);
pRect->left=rgpt[0].x;
pRect->top=rgpt[0].y;
pRect->right=rgpt[1].x;
pRect->bottom=rgpt[1].y;
return;
}
STDAPI_(void) XformRectInHimetricToPixels(HDC hDC, LPRECT prcHiMetric
, LPRECT prcPix)
{
int iXppli; //Pixels per logical inch along width
int iYppli; //Pixels per logical inch along height
int iXextInHiMetric=(prcHiMetric->right-prcHiMetric->left);
int iYextInHiMetric=(prcHiMetric->bottom-prcHiMetric->top);
BOOL fSystemDC=FALSE;
if (NULL==hDC || GetDeviceCaps(hDC, LOGPIXELSX) == 0)
{
hDC=GetDC(NULL);
fSystemDC=TRUE;
}
iXppli=GetDeviceCaps (hDC, LOGPIXELSX);
iYppli=GetDeviceCaps (hDC, LOGPIXELSY);
//We got pixel units, convert them to logical HIMETRIC along the display
prcPix->right=MAP_LOGHIM_TO_PIX(iXextInHiMetric, iXppli);
prcPix->top =MAP_LOGHIM_TO_PIX(iYextInHiMetric, iYppli);
prcPix->left =0;
prcPix->bottom= 0;
if (fSystemDC)
ReleaseDC(NULL, hDC);
return;
}
/*
* INOLE_SetIconInCache
*
* Purpose:
* Stores an iconic presentation metafile in the cache.
*
* Parameters:
* pObj IUnknown * of the object.
* hMetaPict HGLOBAL containing the presentation.
*
* Return Value:
* HRESULT From IOleCache::SetData.
*/
#if 0
STDAPI INOLE_SetIconInCache(IUnknown *pObj, HGLOBAL hMetaPict)
{
IOleCache *pCache;
FORMATETC fe;
STGMEDIUM stm;
HRESULT hr;
if (NULL==hMetaPict)
return ResultFromScode(E_INVALIDARG);
if (FAILED(pObj->QueryInterface(IID_IOleCache, (void **)&pCache)))
return ResultFromScode(E_NOINTERFACE);
SETFormatEtc(fe, CF_METAFILEPICT, DVASPECT_ICON, NULL
, TYMED_MFPICT, -1);
stm.tymed=TYMED_MFPICT;
stm.hGlobal=hMetaPict;
stm.pUnkForRelease=NULL;
hr=pCache->SetData(&fe, &stm, FALSE);
pCache->Release();
return hr;
}
#endif
/*
* XformRectInPixelsToHimetric
* XformRectInHimetricToPixels
*
* Purpose:
* Convert a rectangle between pixels of a given hDC and HIMETRIC units
* as manipulated in OLE. If the hDC is NULL, then a screen DC is used
* and assumes the MM_TEXT mapping mode.
*
* Parameters:
* hDC HDC providing reference to the pixel mapping. If
* NULL, a screen DC is used.
* prcPix LPRECT containng the rectangles to convert.
* prcHiMetric
*
* Return Value:
* None
*
* NOTE:
* When displaying on the screen, Window apps display everything enlarged
* from its actual size so that it is easier to read. For example, if an
* app wants to display a 1in. horizontal line, that when printed is
* actually a 1in. line on the printed page, then it will display the line
* on the screen physically larger than 1in. This is described as a line
* that is "logically" 1in. along the display width. Windows maintains as
* part of the device-specific information about a given display device:
* LOGPIXELSX -- no. of pixels per logical in along the display width
* LOGPIXELSY -- no. of pixels per logical in along the display height
*
* The following formula converts a distance in pixels into its equivalent
* logical HIMETRIC units:
*
* DistInHiMetric=(HIMETRIC_PER_INCH * DistInPix)
* -------------------------------
* PIXELS_PER_LOGICAL_IN
*
* Rect in Pixels (MM_TEXT):
*
* 0---------- X
* |
* | 1) ------------------ ( 2 P1=(rc.left, rc.top)
* | | | P2=(rc.right, rc.top)
* | | | P3=(rc.left, rc.bottom)
* | | | P4=(rc.right, rc.bottom)
* | |
* Y | |
* 3) ------------------ ( 4
*
* NOTE: Origin =(P1x, P1y)
* X extent=P4x - P1x
* Y extent=P4y - P1y
*
*
* Rect in Himetric (MM_HIMETRIC):
*
*
* 1) ------------------ ( 2 P1=(rc.left, rc.top)
* Y | | P2=(rc.right, rc.top)
* | | P3=(rc.left, rc.bottom)
* | | | P4=(rc.right, rc.bottom)
* | | |
* | | |
* | 3) ------------------ ( 4
* |
* 0---------- X
*
* NOTE: Origin =(P3x, P3y)
* X extent=P2x - P3x
* Y extent=P2y - P3y
*
*
*/
STDAPI_(void) XformRectInPixelsToHimetric(HDC hDC, LPRECT prcPix
, LPRECT prcHiMetric)
{
int iXppli; //Pixels per logical inch along width
int iYppli; //Pixels per logical inch along height
int iXextInPix=(prcPix->right-prcPix->left);
int iYextInPix=(prcPix->bottom-prcPix->top);
BOOL fSystemDC=FALSE;
if (NULL==hDC || GetDeviceCaps(hDC, LOGPIXELSX) == 0)
{
hDC=GetDC(NULL);
fSystemDC=TRUE;
}
iXppli=GetDeviceCaps (hDC, LOGPIXELSX);
iYppli=GetDeviceCaps (hDC, LOGPIXELSY);
//We got pixel units, convert them to logical HIMETRIC along the display
prcHiMetric->right=MAP_PIX_TO_LOGHIM(iXextInPix, iXppli);
prcHiMetric->top =MAP_PIX_TO_LOGHIM(iYextInPix, iYppli);
prcHiMetric->left =0;
prcHiMetric->bottom =0;
if (fSystemDC)
ReleaseDC(NULL, hDC);
return;
}
|