📄 util.cpp
字号:
*
* Parameters:
* clsID CLSID to store.
* dwAspect DWORD with the display aspect
* pszl LPSIZEL (optional) if the object is being scaled in
* its container, then the container should pass the
* extents that it is using to display the object.
* ptl POINTL from upper-left corner of object where
* mouse went down for use with Drag & Drop.
* dwMisc DWORD containing MiscStatus flags
* pszName LPTSTR naming the object to copy
* pszSrc LPTSTR identifying the source of the object.
*
* Return Value:
* HBGLOBAL Handle to OBJECTDESCRIPTOR structure.
*/
/*
* AllocObjectDescriptor
*
* Purpose:
* Allocated and fills an OBJECTDESCRIPTOR structure.
*
* Parameters:
* clsID CLSID to store.
* dwAspect DWORD with the display aspect
* pszl LPSIZEL (optional) if the object is being scaled in
* its container, then the container should pass the
* extents that it is using to display the object.
* ptl POINTL from upper-left corner of object where
* mouse went down for use with Drag & Drop.
* dwMisc DWORD containing MiscStatus flags
* pszName LPTSTR naming the object to copy
* pszSrc LPTSTR identifying the source of the object.
*
* Return Value:
* HBGLOBAL Handle to OBJECTDESCRIPTOR structure.
*/
static HGLOBAL AllocObjectDescriptor(
CLSID clsID,
DWORD dwAspect,
SIZEL szl,
POINTL ptl,
DWORD dwMisc,
LPTSTR pszName,
LPTSTR pszSrc)
{
#ifndef PEGASUS
HGLOBAL hMem=NULL;
LPOBJECTDESCRIPTOR pOD;
DWORD cb, cbStruct;
DWORD cchName, cchSrc;
cchName=wcslen(pszName)+1;
if (NULL!=pszSrc)
cchSrc=wcslen(pszSrc)+1;
else
{
cchSrc=cchName;
pszSrc=pszName;
}
/*
* Note: CFSTR_OBJECTDESCRIPTOR is an ANSI structure.
* That means strings in it must be ANSI. OLE will do
* internal conversions back to Unicode as necessary,
* but we have to put ANSI strings in it ourselves.
*/
cbStruct=sizeof(OBJECTDESCRIPTOR);
cb=cbStruct+(sizeof(WCHAR)*(cchName+cchSrc)); //HACK
hMem=GlobalAlloc(GHND, cb);
if (NULL==hMem)
return NULL;
pOD=(LPOBJECTDESCRIPTOR)GlobalLock(hMem);
pOD->cbSize=cb;
pOD->clsid=clsID;
pOD->dwDrawAspect=dwAspect;
pOD->sizel=szl;
pOD->pointl=ptl;
pOD->dwStatus=dwMisc;
if (pszName)
{
pOD->dwFullUserTypeName=cbStruct;
wcscpy((LPTSTR)((LPBYTE)pOD+pOD->dwFullUserTypeName)
, pszName);
}
else
pOD->dwFullUserTypeName=0; //No string
if (pszSrc)
{
pOD->dwSrcOfCopy=cbStruct+(cchName*sizeof(WCHAR));
wcscpy((LPTSTR)((LPBYTE)pOD+pOD->dwSrcOfCopy), pszSrc);
}
else
pOD->dwSrcOfCopy=0; //No string
GlobalUnlock(hMem);
return hMem;
#else
return NULL;
#endif
}
HGLOBAL OleGetObjectDescriptorDataFromOleObject(
LPOLEOBJECT pObj,
DWORD dwAspect,
POINTL ptl,
LPSIZEL pszl
)
{
#ifndef PEGASUS
CLSID clsID;
LPTSTR pszName=NULL;
LPTSTR pszSrc=NULL;
BOOL fLink=FALSE;
IOleLink *pLink;
TCHAR szName[512];
DWORD dwMisc=0;
SIZEL szl;
HGLOBAL hMem;
HRESULT hr;
if (SUCCEEDED(pObj->QueryInterface(IID_IOleLink
, (void **)&pLink)))
fLink=TRUE;
if (FAILED(pObj->GetUserClassID(&clsID)))
ZeroMemory(&clsID, sizeof(CLSID));
//Get user string, expand to "Linked %s" if this is link
pObj->GetUserType(USERCLASSTYPE_FULL, &pszName);
if (fLink && NULL!=pszName)
{
// NB!! we do these two lines of code below instead
// wcscat because we don't use wcscat anywhere else
// in the product at the moment. The string "Linked "
// should never change either.
wcscpy(szName, TEXT("Linked "));
wcscpy(&(szName[7]), pszName);
}
else if (pszName)
wcscpy(szName, pszName);
else
szName[0] = 0;
pCoTaskMemFree(pszName);
/*
* Get the source name of this object using either the
* link display name (for link) or a moniker display
* name.
*/
if (fLink)
{
hr=pLink->GetSourceDisplayName(&pszSrc);
}
else
{
IMoniker *pmk;
hr=pObj->GetMoniker(OLEGETMONIKER_TEMPFORUSER
, OLEWHICHMK_OBJFULL, &pmk);
if (SUCCEEDED(hr))
{
IBindCtx *pbc;
pCreateBindCtx(0, &pbc);
pmk->GetDisplayName(pbc, NULL, &pszSrc);
pbc->Release();
pmk->Release();
}
}
if (fLink)
pLink->Release();
//Get MiscStatus bits
hr=pObj->GetMiscStatus(dwAspect, &dwMisc);
//Get OBJECTDESCRIPTOR
hMem=AllocObjectDescriptor(clsID, dwAspect, szl, ptl
, dwMisc, szName, pszSrc);
pCoTaskMemFree(pszSrc);
return hMem;
#else
return NULL;
#endif
}
/*
* OleStdGetMetafilePictFromOleObject()
*
* @mfunc:
* Generate a MetafilePict from the OLE object.
* Parameters:
* lpOleObj LPOLEOBJECT pointer to OLE Object
* dwDrawAspect DWORD Display Aspect of object
* lpSizelHim SIZEL (optional) If the object is being scaled in its
* container, then the container should pass the extents
* that it is using to display the object.
* May be NULL if the object is NOT being scaled. in this
* case, IViewObject2::GetExtent will be called to get the
* extents from the object.
* ptd TARGETDEVICE FAR* (optional) target device to render
* metafile for. May be NULL.
*
* @rdesc
* HANDLE -- handle of allocated METAFILEPICT
*/
HANDLE OleStdGetMetafilePictFromOleObject(
LPOLEOBJECT lpOleObj,
DWORD dwDrawAspect,
LPSIZEL lpSizelHim,
DVTARGETDEVICE FAR* ptd
)
{
#ifndef PEGASUS
LPVIEWOBJECT2 lpViewObj2 = NULL;
HDC hDC;
HMETAFILE hmf;
HANDLE hMetaPict;
LPMETAFILEPICT lpPict;
RECT rcHim;
RECTL rclHim;
SIZEL sizelHim;
HRESULT hrErr;
SIZE size;
POINT point;
LPOLECACHE polecache = NULL;
LPDATAOBJECT pdataobj = NULL;
FORMATETC fetc;
STGMEDIUM med;
// First try the easy way,
// pull out the cache's version of things.
ZeroMemory(&fetc, sizeof(FORMATETC));
fetc.dwAspect = dwDrawAspect;
fetc.cfFormat = CF_METAFILEPICT;
fetc.lindex = -1;
fetc.tymed = TYMED_MFPICT;
ZeroMemory(&med, sizeof(STGMEDIUM));
hMetaPict = NULL;
if (!lpOleObj->QueryInterface(IID_IOleCache, (void **)&polecache) &&
!polecache->QueryInterface(IID_IDataObject, (void **)&pdataobj) &&
!pdataobj->GetData(&fetc, &med))
{
hMetaPict = pOleDuplicateData(med.hGlobal, CF_METAFILEPICT, 0);
pReleaseStgMedium(&med);
}
if (pdataobj)
{
pdataobj->Release();
}
if (polecache)
{
polecache->Release();
}
// If all this failed, fall back to the hard way and draw the object
// into a metafile.
if (hMetaPict)
return hMetaPict;
if (lpOleObj->QueryInterface(IID_IViewObject2, (void **)&lpViewObj2))
return NULL;
// Get SIZEL
if (lpSizelHim) {
// Use extents passed by the caller
sizelHim = *lpSizelHim;
} else {
// Get the current extents from the object
hrErr = lpViewObj2->GetExtent(
dwDrawAspect,
-1, /*lindex*/
ptd, /*ptd*/
(LPSIZEL)&sizelHim);
if (hrErr != NOERROR)
sizelHim.cx = sizelHim.cy = 0;
}
hDC = CreateMetaFileA(NULL);
rclHim.left = 0;
rclHim.top = 0;
rclHim.right = sizelHim.cx;
rclHim.bottom = sizelHim.cy;
rcHim.left = (int)rclHim.left;
rcHim.top = (int)rclHim.top;
rcHim.right = (int)rclHim.right;
rcHim.bottom = (int)rclHim.bottom;
SetWindowOrgEx(hDC, rcHim.left, rcHim.top, &point);
SetWindowExtEx(hDC, rcHim.right-rcHim.left, rcHim.bottom-rcHim.top,&size);
hrErr = lpViewObj2->Draw(
dwDrawAspect,
-1,
NULL,
ptd,
NULL,
hDC,
(LPRECTL)&rclHim,
(LPRECTL)&rclHim,
NULL,
0
);
lpViewObj2->Release();
hmf = CloseMetaFile(hDC);
if (hrErr != NOERROR) {
TRACEERRORHR(hrErr);
hMetaPict = NULL;
}
else
{
hMetaPict = GlobalAlloc(GHND|GMEM_SHARE, sizeof(METAFILEPICT));
if (hMetaPict && (lpPict = (LPMETAFILEPICT)GlobalLock(hMetaPict))){
lpPict->hMF = hmf;
lpPict->xExt = (int)sizelHim.cx ;
lpPict->yExt = (int)sizelHim.cy ;
lpPict->mm = MM_ANISOTROPIC;
GlobalUnlock(hMetaPict);
}
}
if (!hMetaPict)
DeleteMetaFile(hmf);
return hMetaPict;
#else
return NULL;
#endif
}
/*
* OleUIDrawShading
*
* Purpose:
* Shade the object when it is in in-place editing. Borders are drawn
* on the Object rectangle. The right and bottom edge of the rectangle
* are excluded in the drawing.
*
* Parameters:
* lpRect Dimensions of Container Object
* hdc HDC for drawing
*
* Return Value: null
*
*/
void OleUIDrawShading(LPRECT lpRect, HDC hdc)
{
#ifndef PEGASUS
HBRUSH hbr;
HBRUSH hbrOld;
HBITMAP hbm;
RECT rc;
WORD wHatchBmp[] = {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};
COLORREF cvText;
COLORREF cvBk;
hbm = CreateBitmap(8, 8, 1, 1, wHatchBmp);
hbr = CreatePatternBrush(hbm);
hbrOld = (HBRUSH)SelectObject(hdc, hbr);
rc = *lpRect;
cvText = SetTextColor(hdc, RGB(255, 255, 255));
cvBk = SetBkColor(hdc, RGB(0, 0, 0));
PatBlt(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
0x00A000C9L /* DPa */ );
SetTextColor(hdc, cvText);
SetBkColor(hdc, cvBk);
SelectObject(hdc, hbrOld);
DeleteObject(hbr);
DeleteObject(hbm);
#endif
}
/*
* AppendString ( szInput, szAppendStr, dBuffSize, dByteUsed )
*
* Purpose:
* Append new string to original string. Check for size of buffer
* and re-allocate a large buffer is necessary
*
* Arguments:
* szInput Original String
* szAppendStr String to be appended to szInput
* dBuffSize Byte size of the buffer for szInput
* dByteUsed Byte used in the buffer for szInput
*
* Returns:
* INT The error code
*/
INT AppendString(
BYTE ** szInput,
BYTE * szAppendStr,
int * dBuffSize,
int * dByteUsed)
{
BYTE *pch;
int cchAppendStr;
pch = *szInput;
// check if we have enough space to append the new string
cchAppendStr = strlen( (char *)szAppendStr );
if ( cchAppendStr + *dByteUsed < cchAppendStr )
return ( ecNoMemory );
if ( cchAppendStr + *dByteUsed >= *dBuffSize )
{
// re-alloc a bigger buffer
int cchNewSize = *dBuffSize + cchAppendStr + 32;
pch = (BYTE *)PvReAlloc( *szInput, cchNewSize );
if ( !pch )
{
return ( ecNoMemory );
}
*dBuffSize = cchNewSize;
*szInput = pch;
}
pch += *dByteUsed;
*dByteUsed += cchAppendStr;
while (*pch++ = *szAppendStr++);
return ecNoError;
}
/*
* CTempBuf::Init
*
* @mfunc Set object to its initial state using the stack buffer
*
*/
void CTempBuf::Init()
{
_pv = (void *) &_chBuf[0];
_cb = MAX_STACK_BUF;
}
/*
* CTempBuf::FreeBuf
*
* @mfunc Free an allocated buffer if there is one
*
*/
void CTempBuf::FreeBuf()
{
if (_pv != &_chBuf[0])
{
delete _pv;
}
}
/*
* CTempBuf::GetBuf
*
* @mfunc Get a buffer for temporary use
*
* @rdesc Pointer to buffer if one could be allocated otherwise NULL.
*
*
*/
void *CTempBuf::GetBuf(
LONG cb) //@parm Size of buffer needed in bytes
{
if (_cb >= cb)
{
// Currently allocated buffer is big enough so use it
return _pv;
}
// Free our current buffer
FreeBuf();
// Allocate a new buffer if we can
_pv = new BYTE[cb];
if (NULL == _pv)
{
// Could not allocate a buffer so reset to our initial state and
// return NULL.
Init();
return NULL;
}
// Store the size of our new buffer.
_cb = cb;
// Returnt he pointer to the buffer.
return _pv;
}
void CSystemParams::Update()
{
CLock clock;
const LONG dxSelBarDefaultSize = 8;
#ifdef DEBUG
extern BOOL fInDllMain;
AssertSz(!fInDllMain, "CSystemParams::Update(): We can't call this function "
"from DllMain, since it includes GDI calls which may "
"lead to deadlock.");
#endif
if(!_fDirty)
{
return;
}
_crAuto = GetSysColor(COLOR_WINDOWTEXT);
_cxBorder = GetSystemMetrics(SM_CXBORDER); // Unsizable window border
_cyBorder = GetSystemMetrics(SM_CYBORDER); // widths
_cxHScroll = GetSystemMetrics(SM_CXHSCROLL); // Scrollbar-arrow bitmap
_cxVScroll = GetSystemMetrics(SM_CXVSCROLL); // dimensions
_cyHScroll = GetSystemMetrics(SM_CYHSCROLL); //
_cyVScroll = GetSystemMetrics(SM_CYVSCROLL); //
_cxDoubleClk = GetSystemMetrics(SM_CXDOUBLECLK);
_cyDoubleClk = GetSystemMetrics(SM_CYDOUBLECLK);
#ifndef MACPORT
_DCT = GetDoubleClickTime();
#else
_DCT = GetDblTime();
#endif
HWND hwnd = GetDesktopWindow();
HDC hdc = ::GetDC(hwnd);
HFONT hfontOld;
TEXTMETRIC tm;
_xPerInchScreenDC = GetDeviceCaps(hdc, LOGPIXELSX);
_yPerInchScreenDC = GetDeviceCaps(hdc, LOGPIXELSY);
int cPalette = GetDeviceCaps(hdc, SIZEPALETTE);
// 256 colors is where we seem to need to use the palette.
if (256 == cPalette)
{
_fUsePalette = TRUE;
}
// calculate a himetric selection bar for the window's host.
_dxSelBar = W32->DXtoHimetricX(dxSelBarDefaultSize, _xPerInchScreenDC);
hfontOld = (HFONT)SelectObject(hdc, GetStockObject(SYSTEM_FONT));
if(hfontOld)
{
W32->GetTextMetrics(hdc, &tm);
_xWidthSys = (INT) tm.tmAveCharWidth;
_yHeightSys = (INT) tm.tmHeight;
SelectObject(hdc, hfontOld);
}
::ReleaseDC(hwnd, hdc);
_fDirty = FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -