📄 scpalette.cpp
字号:
/*
* This file is part of the EMFexplorer projet.
* Copyright (C) 2004 Smith Charles.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* Extension: for commercial use, apply the Equity Public License, which
* adds to the normal terms of the GLPL a condition of donation to the author.
* If you are interested in support for this source code,
* contact Smith Charles <smith.charles@free.fr> for more information.
*/
#include "stdafx.h"
#include "SCPalette.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Create a copy of the current system palette.
HPALETTE SCGetSystemPalette()
{
HDC hDC;
HPALETTE hPal;
LPLOGPALETTE lpLogPal;
// Get a DC for the desktop.
hDC = GetDC(NULL);
// Check to see if you are a running in a palette-based video mode.
if (!(GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE))
{
ReleaseDC(NULL, hDC);
return NULL;
}
// Allocate memory for the palette.
lpLogPal = (LPLOGPALETTE)GlobalAlloc(GPTR, sizeof(LOGPALETTE) + 256 *
sizeof(PALETTEENTRY));
if (!lpLogPal)
{
TRACE(_T("SCGetSystemPalette.GlobalAlloc->NULL"));
return NULL;
}
// Initialize.
lpLogPal->palVersion = 0x300;
lpLogPal->palNumEntries = 256;
// Copy the current system palette into the logical palette.
::GetSystemPaletteEntries(hDC, 0, 256,
(LPPALETTEENTRY)(lpLogPal->palPalEntry));
// Create the palette.
hPal = CreatePalette(lpLogPal);
// Clean up.
GlobalFree(lpLogPal);
ReleaseDC(NULL, hDC);
return hPal;
}
// Create a copy of an enhanced metafile palette.
HPALETTE SCGetEMFPalette(HENHMETAFILE hEmf)
{
// Get the number of palette entries
UINT uEntries = 0;
uEntries = GetEnhMetaFilePaletteEntries(hEmf, 0, NULL);
if (!uEntries)
return NULL;
// Create the logical palette based on the entries
// Allocate memory for the palette.
LPLOGPALETTE lpLogPal;
lpLogPal = (LPLOGPALETTE)GlobalAlloc(GPTR, sizeof(LOGPALETTE) + uEntries *
sizeof(PALETTEENTRY));
if (!lpLogPal)
return NULL;
// Initialize.
lpLogPal->palVersion = 0x300;
lpLogPal->palNumEntries = uEntries;
// Copy the EMF palette into the logical palette.
if (GetEnhMetaFilePaletteEntries(hEmf, uEntries, (LPPALETTEENTRY)(lpLogPal->palPalEntry))==GDI_ERROR)
return NULL;
// Create the palette.
HPALETTE hPal = CreatePalette(lpLogPal);
// Clean up.
GlobalFree(lpLogPal);
return hPal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -