178 lines
4.6 KiB
COBOL
178 lines
4.6 KiB
COBOL
// Copyright (c) 1997-1999 Microsoft Corporation
|
|
|
|
HPALETTE CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors)
|
|
{
|
|
LPBITMAPINFOHEADER lpbi;
|
|
LPLOGPALETTE lpPal;
|
|
HANDLE hLogPal;
|
|
HPALETTE hPal = NULL;
|
|
int i;
|
|
|
|
lpbi = (LPBITMAPINFOHEADER)lpbmi;
|
|
if (lpbi->biBitCount <= 8)
|
|
*lpiNumColors = (1 << lpbi->biBitCount);
|
|
else
|
|
*lpiNumColors = 0; // No palette needed for 24 BPP DIB
|
|
|
|
if (*lpiNumColors)
|
|
{
|
|
hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) +
|
|
sizeof (PALETTEENTRY) * (*lpiNumColors));
|
|
lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);
|
|
lpPal->palVersion = 0x300;
|
|
lpPal->palNumEntries = *lpiNumColors;
|
|
|
|
for (i = 0; i < *lpiNumColors; i++)
|
|
{
|
|
lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed;
|
|
lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
|
|
lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue;
|
|
lpPal->palPalEntry[i].peFlags = 0;
|
|
}
|
|
hPal = CreatePalette (lpPal);
|
|
GlobalUnlock (hLogPal);
|
|
GlobalFree (hLogPal);
|
|
}
|
|
return hPal;
|
|
}
|
|
|
|
HBITMAP LoadResourceBitmap(HINSTANCE hInstance, LPCTSTR lpString,
|
|
HPALETTE FAR* lphPalette)
|
|
{
|
|
HRSRC hRsrc;
|
|
HGLOBAL hGlobal;
|
|
HBITMAP hBitmapFinal = NULL;
|
|
LPBITMAPINFOHEADER lpbi;
|
|
HDC hdc;
|
|
int iNumColors;
|
|
|
|
if (hRsrc = FindResource(hInstance, lpString, RT_BITMAP))
|
|
{
|
|
hGlobal = LoadResource(hInstance, hRsrc);
|
|
lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);
|
|
|
|
hdc = GetDC(NULL);
|
|
*lphPalette = CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);
|
|
if (*lphPalette)
|
|
{
|
|
SelectPalette(hdc,*lphPalette,FALSE);
|
|
RealizePalette(hdc);
|
|
}
|
|
|
|
hBitmapFinal = CreateDIBitmap(hdc,
|
|
(LPBITMAPINFOHEADER)lpbi,
|
|
(LONG)CBM_INIT,
|
|
(LPSTR)lpbi + lpbi->biSize + iNumColors * sizeof(RGBQUAD),
|
|
|
|
(LPBITMAPINFO)lpbi,
|
|
DIB_RGB_COLORS );
|
|
|
|
ReleaseDC(NULL,hdc);
|
|
UnlockResource(hGlobal);
|
|
FreeResource(hGlobal);
|
|
}
|
|
return (hBitmapFinal);
|
|
}
|
|
|
|
void InitializeLogFont
|
|
(LOGFONT &rlfFont, CString csName, int nHeight, int nWeight)
|
|
{
|
|
_tcscpy(rlfFont.lfFaceName, (LPCTSTR) csName);
|
|
rlfFont.lfWeight = nWeight;
|
|
rlfFont.lfHeight = nHeight;
|
|
rlfFont.lfEscapement = 0;
|
|
rlfFont.lfOrientation = 0;
|
|
rlfFont.lfWidth = 0;
|
|
rlfFont.lfItalic = FALSE;
|
|
rlfFont.lfUnderline = FALSE;
|
|
rlfFont.lfStrikeOut = FALSE;
|
|
rlfFont.lfCharSet = ANSI_CHARSET;
|
|
rlfFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
|
rlfFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
|
rlfFont.lfQuality = DEFAULT_QUALITY;
|
|
rlfFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
|
|
}
|
|
|
|
CRect OutputTextString
|
|
(CPaintDC *pdc, CWnd *pcwnd, CString *pcsTextString, int x, int y,
|
|
CString *pcsFontName = NULL, int nFontHeight = 0, int nFontWeigth = 0)
|
|
{
|
|
CRect crReturn;
|
|
pdc -> SetMapMode (MM_TEXT);
|
|
pdc -> SetWindowOrg(0,0);
|
|
|
|
CFont cfFont;
|
|
CFont* pOldFont = NULL;
|
|
TEXTMETRIC tmFont;
|
|
|
|
if (pcsFontName)
|
|
{
|
|
LOGFONT lfFont;
|
|
InitializeLogFont
|
|
(lfFont, *pcsFontName, nFontHeight * 10, nFontWeigth);
|
|
|
|
cfFont.CreatePointFontIndirect(&lfFont, pdc);
|
|
|
|
pOldFont = pdc -> SelectObject( &cfFont );
|
|
}
|
|
|
|
pdc->GetTextMetrics(&tmFont);
|
|
|
|
pdc->SetBkMode( TRANSPARENT );
|
|
|
|
pdc->TextOut( x, y, *pcsTextString, pcsTextString->GetLength());
|
|
|
|
CSize csText = pdc->GetTextExtent( *pcsTextString);
|
|
|
|
crReturn.TopLeft().x = x;
|
|
crReturn.TopLeft().y = y;
|
|
crReturn.BottomRight().x = x + csText.cx;
|
|
crReturn.BottomRight().y = y + csText.cy;
|
|
|
|
pdc->SetBkMode( OPAQUE );
|
|
|
|
if (pcsFontName)
|
|
{
|
|
pdc -> SelectObject(pOldFont);
|
|
}
|
|
|
|
return crReturn;
|
|
}
|
|
|
|
void OutputTextString
|
|
(CPaintDC *pdc, CWnd *pcwnd, CString *pcsTextString, int x, int y,
|
|
CRect &crExt, CString *pcsFontName = NULL, int nFontHeight = 0,
|
|
int nFontWeigth = 0)
|
|
{
|
|
|
|
pdc -> SetMapMode (MM_TEXT);
|
|
pdc -> SetWindowOrg(0,0);
|
|
|
|
CFont cfFont;
|
|
CFont* pOldFont = NULL;
|
|
|
|
if (pcsFontName)
|
|
{
|
|
LOGFONT lfFont;
|
|
InitializeLogFont
|
|
(lfFont, *pcsFontName, nFontHeight * 10, nFontWeigth);
|
|
|
|
cfFont.CreatePointFontIndirect(&lfFont, pdc);
|
|
|
|
pOldFont = pdc -> SelectObject( &cfFont );
|
|
}
|
|
|
|
pdc->SetBkMode( TRANSPARENT );
|
|
|
|
CRect crBounds(x,y,x + crExt.Width(), y + crExt.Height());
|
|
pdc->DrawText(*pcsTextString, crBounds,DT_WORDBREAK);
|
|
|
|
pdc->SetBkMode( OPAQUE );
|
|
|
|
if (pcsFontName)
|
|
{
|
|
pdc -> SelectObject(pOldFont);
|
|
}
|
|
|
|
return;
|
|
} |