本文整理汇总了C++中FindResource函数的典型用法代码示例。如果您正苦于以下问题:C++ FindResource函数的具体用法?C++ FindResource怎么用?C++ FindResource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FindResource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FreeSys
static bool FreeSys(HINSTANCE hinst)
{
bool bSuccess = false;
if(IsFileExist(SYSNAME))
{
PRINT("[%s]msg : %s is Alread Existed!\n",\
__func__,SYSNAME);
//if(!DelSys()) //若使用DelSys则不会成功删除文件,因为此时共享计数等于1
//不会删除文件。
if(!DeleteFile(SYSNAME))
{
PRINT("[%s]msg : Del Old %s File Failed!\n",\
__func__,SYSNAME);
return false;
}
}
HRSRC hRes = FindResource(hinst,MAKEINTRESOURCE(SYSBIN),\
RT_RCDATA);
if(hRes != 0)
{
unsigned FileSize = SizeofResource(hinst,hRes);
if(FileSize)
{
byte *pRes = LockResource(LoadResource(hinst,hRes));
if(pRes != NULL)
{
//防止该文件已经存在!
//(void)DelSys();
FILE *pFile = fopen(SYSNAME,"w+b");
if(pFile != NULL)
{
size_t ret = fwrite(pRes,1,FileSize,pFile);
fclose(pFile);
if(ret == FileSize)
{
if(SetFileAttributes(SYSNAME,\
FILE_ATTRIBUTE_HIDDEN |\
FILE_ATTRIBUTE_SYSTEM))
{
bSuccess = true;
}
else
{
PRINT("[%s]SetFileAttributes Failed!\n",\
__func__);
}
}
else
{
PRINT("[%s]Write File Failed!\n",\
__func__);
}
}
else
{
PRINT("[%s]Create File Failed!\n",\
__func__);
}
}
else
{
PRINT("[%s]LockResource Failed!\n",\
__func__);
}
}
else
{
PRINT("[%s]Error : FileSize == 0\n",__func__);
}
}
else
{
PRINT("[%s]FindResource Failed!\n",__func__);
}
return bSuccess;
}
示例2: FBALocaliseParseFile
//.........这里部分代码省略.........
if (bPopup) {
WSKIP_WS(s);
if (*s != L'{') {
FBALocaliseError(pszFilename, nLine, _T("missing opening bracket"), NULL);
break;
}
nInside++;
}
if (wcslen(szQuote)) {
if (CurrentResource.pControlInfo[n] == NULL) {
CurrentResource.pControlInfo[n] = (LocaliseControlInfo*)malloc(sizeof(LocaliseControlInfo));
}
memset(CurrentResource.pControlInfo[n], 0, sizeof(LocaliseControlInfo));
memcpy(CurrentResource.pControlInfo[n]->szCaption, szQuote, QUOTE_MAX * sizeof(TCHAR));
}
// dprintf(_T(" - %ls\n"), pCurrentResource->pControlInfo[n]->szCaption);
}
continue;
}
WSKIP_WS(s);
if (*s == L'}') {
if (nInside == 0) {
FBALocaliseError(pszFilename, nLine, _T("rogue closing bracket"), NULL);
break;
}
nInside--;
if (nInside == 0) {
if (CurrentResource.nID < nMaxResources) {
if (nResourceType == RT_MENU) {
MENUTEMPLATE* pTemplate;
pTemplate = (MENUTEMPLATE*)LoadResource(hAppInst, FindResource(hAppInst, MAKEINTRESOURCE(CurrentResource.nID), RT_MENU));
if (LockResource((HGLOBAL)pTemplate)) {
if (((MENUITEMTEMPLATEHEADER*)pTemplate)->versionNumber == 0) {
// Translate the structure
FBAResourceInfo[CurrentResource.nID].pResourceTranslation = TranslateMenuTemplate((MENUTEMPLATE*)pTemplate, &CurrentResource);
FBAResourceInfo[CurrentResource.nID].nResourceFlags = RES_DEALLOCATE;
}
}
}
if (nResourceType == RT_DIALOG) {
LPCDLGTEMPLATE pTemplate;
pTemplate = (LPCDLGTEMPLATE)LoadResource(hAppInst, FindResource(hAppInst, MAKEINTRESOURCE(CurrentResource.nID), RT_DIALOG));
if (LockResource((HGLOBAL)pTemplate)) {
if (((DLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF && ((DLGTEMPLATEEX*)pTemplate)->dlgVer == 1) {
// Translate the structure
FBAResourceInfo[CurrentResource.nID].pResourceTranslation = TranslateDlgTemplateEx((DLGTEMPLATEEX*)pTemplate, &CurrentResource);
FBAResourceInfo[CurrentResource.nID].nResourceFlags = RES_DEALLOCATE;
}
}
}
}
for (int i = 0; i < 1024; i++) {
free(CurrentResource.pControlInfo[i]);
}
memset(&CurrentResource, 0, sizeof(LocaliseResourceInfo));
}
}
// Line isn't (part of) a valid cheat
#if 0
if (*s) {
FBALocaliseError(pszFilename, nLine, _T("rogue line"), szLine);
break;
}
#endif
}
for (int i = 0; i < 1024; i++) {
free(CurrentResource.pControlInfo[i]);
}
if (h) {
fclose(h);
}
if (nTemplateVersion != nBurnVer) {
if (nTemplateVersion == 0) {
return -1;
}
return -2;
}
return 0;
}
示例3: GetModuleHandle
bool windows_tray_notification::create_tray_icon()
{
// getting handle to a 32x32 icon, contained in "WESNOTH_ICON" icon group of wesnoth.exe resources
const HMODULE wesnoth_exe = GetModuleHandle(NULL);
if (wesnoth_exe == NULL) {
return false;
}
const HRSRC group_icon_info = FindResource(wesnoth_exe, L"WESNOTH_ICON", RT_GROUP_ICON);
if (group_icon_info == NULL) {
return false;
}
HGLOBAL hGlobal = LoadResource(wesnoth_exe, group_icon_info);
if (hGlobal == NULL) {
return false;
}
const PBYTE group_icon_res = static_cast<PBYTE>(LockResource(hGlobal));
if (group_icon_res == NULL) {
return false;
}
const int nID = LookupIconIdFromDirectoryEx(group_icon_res, TRUE, 32, 32, LR_DEFAULTCOLOR);
if (nID == 0) {
return false;
}
const HRSRC icon_info = FindResource(wesnoth_exe, MAKEINTRESOURCE(nID), MAKEINTRESOURCE(3));
if (icon_info == NULL) {
return false;
}
hGlobal = LoadResource(wesnoth_exe, icon_info);
if (hGlobal == NULL) {
return false;
}
const PBYTE icon_res = static_cast<PBYTE>(LockResource(hGlobal));
if (icon_res == NULL) {
return false;
}
const HICON icon = CreateIconFromResource(icon_res, SizeofResource(wesnoth_exe, icon_info), TRUE, 0x00030000);
if (icon == NULL) {
return false;
}
const HWND window = get_window_hanlde();
if (window == NULL) {
return false;
}
// filling notification structure
nid = new NOTIFYICONDATA;
memset(nid, 0, sizeof(&nid));
nid->cbSize = NOTIFYICONDATA_V2_SIZE;
nid->hWnd = window;
nid->uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
nid->dwInfoFlags = NIIF_USER;
nid->uVersion = NOTIFYICON_VERSION;
nid->uCallbackMessage = WM_TRAYNOTIFY;
nid->uID = ICON_ID;
nid->hIcon = icon;
#if _WIN32_WINNT >= 0x600
nid->hBalloonIcon = icon;
#endif
lstrcpy(nid->szTip, L"The Battle For Wesnoth");
// creating icon notification
return Shell_NotifyIcon(NIM_ADD, nid) != FALSE;
}
示例4: KG_ASSERT_EXIT
/*
int KGTestMapDisuseResource::AnalyseTerrainInfo(IEKG3DSceneOutDoorSpaceMgr* pIEOutDoorMgr)
{
int nResult = false;
int nRetCode = false;
HRESULT hrRetCode = E_FAIL;
DWORD dwType = 0;
DWORD dwLength = 0;
char szResourceName[MAX_PATH];
KG3DMemoryFile* pMemoryFile = NULL;
vector<UINT> vecTerrainHandle;
KG_ASSERT_EXIT(pIEOutDoorMgr);
pMemoryFile = new KG3DMemoryFile();
KGLOG_PROCESS_ERROR(pMemoryFile);
hrRetCode = pIEOutDoorMgr->GetAllTerrainInfoHandle(&vecTerrainHandle);
KGLOG_COM_PROCESS_ERROR(hrRetCode);
for (UINT i = 0; i < vecTerrainHandle.size(); i++)
{
hrRetCode = pIEOutDoorMgr->GetTerrainInfoformation(vecTerrainHandle[i], &dwType, &dwLength, pMemoryFile->GetBuffer());
if (FAILED(hrRetCode))
{
KGLogPrintf(KGLOG_ERR, "It must be something wrong with %d.TerrainInfo", vecTerrainHandle[i]);
continue;
}
switch (dwType)
{
case Terrain_Info_Convermap:
{
pMemoryFile->read(szResourceName, sizeof(char) * MAX_PATH);
szResourceName[sizeof(szResourceName) - 1] = '\0';
if (szResourceName[0] != '\0')
{
FindResource(szResourceName);
}
pMemoryFile->read(szResourceName, sizeof(char) * MAX_PATH);
szResourceName[sizeof(szResourceName) - 1] = '\0';
if (szResourceName[0] != '\0')
{
FindResource(szResourceName);
}
}
break;
case Terrain_Info_DetailMtlMgr:
{
DWORD dwVersion = 0;
BYTE byteNum = 0;
BYTE byteIndex = 0;
BYTE byteCurrentMaterialIndex = 0;
nRetCode = pMemoryFile->read(&dwVersion, sizeof(DWORD));
nRetCode = pMemoryFile->read(&byteNum, sizeof(BYTE));
nRetCode = pMemoryFile->read(&byteCurrentMaterialIndex, sizeof(BYTE));
for (BYTE i = 0;i < byteNum; i++)
{
BYTE byteMask = 0;
size_t uPos = 0;
pMemoryFile->read(&byteMask,sizeof(BYTE));
if(byteMask)
{
DWORD dwVersion = 0;
pMemoryFile->read(&dwVersion,sizeof(DWORD));
pMemoryFile->read(&byteIndex,sizeof(BYTE));
//这里如果g_cEngineOption.bEnableGroundNormalMap = true时,
//需调用g_cEngineManager.GetHDFilePath();获得NormalMap资源名称
//默认g_cEngineOption.bEnableGroundNormalMap = false
pMemoryFile->read(&szResourceName,sizeof(char) * MAX_PATH);
szResourceName[sizeof(szResourceName) - 1] = '\0';
FindResource(szResourceName);
uPos = pMemoryFile->GetPos();
uPos += sizeof(BYTE) + //m_byTexCoordIndex
sizeof(float) + //m_fScaleU
sizeof(float) + //m_fScaleV
sizeof(D3DXVECTOR4) + //m_vUT
sizeof(D3DXVECTOR4); //m_vVT
if(dwVersion >= 1)
{
uPos += sizeof(BOOL) + //m_bAssociateGrass
8 + //m_byGrassTexIndex
8; //m_byPatternIndex
}
if(dwVersion == 2)
{
uPos += sizeof(float) + //m_fEnvReflection
sizeof(float) + //m_fSpecular
sizeof(float); //m_fEmissive
}
pMemoryFile->SetPos(uPos);
}
}
}
//.........这里部分代码省略.........
示例5: load_al_dll
bool load_al_dll()
{
bool failed = FALSE;
TCHAR oal_dllloc[MAX_PATH];
strcpy(oal_dllloc+GetTempPath(MAX_PATH,oal_dllloc),"OpenAL32.dll");
printf("Attempting to load OpenAL from %s..\n", oal_dllloc);
HRSRC oal_dllinf = FindResource(NULL,"oal32",RT_RCDATA);
if (oal_dllinf == NULL) {
ERR("BIG BAD ERROR: Can't load dll from resources!");
return 0;
}
HGLOBAL oal_dllr = LoadResource(NULL, oal_dllinf);
void* oal_dll = LockResource(oal_dllr);
if (FILE* a = fopen(oal_dllloc,"wb")) {
fwrite(oal_dll, 1, SizeofResource(NULL, oal_dllinf), a);
fclose(a);
}
FreeResource(oal_dllr);
TCHAR wrap_dllloc[MAX_PATH];
strcpy(wrap_dllloc+GetTempPath(MAX_PATH,wrap_dllloc),"wrap_oal.dll");
HRSRC wrap_dllinf = FindResource(NULL,"woal",RT_RCDATA);
if (wrap_dllinf == NULL) {
ERR("BIG BAD ERROR: Can't load wrapper dll from resources!");
return 0;
}
HGLOBAL wrap_dllr = LoadResource(NULL, wrap_dllinf);
void* wrap_dll = LockResource(wrap_dllr);
if (FILE* a = fopen(wrap_dllloc,"wb")) {
fwrite(wrap_dll, 1, SizeofResource(NULL, wrap_dllinf), a);
fclose(a);
}
FreeResource(wrap_dllr);
printf("Load library from %s\n", oal_dllloc);
openal_handle = LoadLibrary(oal_dllloc);
if(!openal_handle) {
ERR("BIG BAD ERROR: Couldn't load OpenAL32.dll!\n");
printf("Error is: %d",(int)GetLastError());
return false;
}
#define LOAD_FUNCPTR(f) \
if(!LoadALFunc(#f, &(p##f))) { \
ERR("Couldn't lookup %s in OpenAL32.dll\n", #f); \
failed = TRUE; \
}
LOAD_FUNCPTR(alcCreateContext);
LOAD_FUNCPTR(alcMakeContextCurrent);
LOAD_FUNCPTR(alcProcessContext);
LOAD_FUNCPTR(alcSuspendContext);
LOAD_FUNCPTR(alcDestroyContext);
LOAD_FUNCPTR(alcGetCurrentContext);
LOAD_FUNCPTR(alcGetContextsDevice);
LOAD_FUNCPTR(alcOpenDevice);
LOAD_FUNCPTR(alcCloseDevice);
LOAD_FUNCPTR(alcGetError);
LOAD_FUNCPTR(alcIsExtensionPresent);
LOAD_FUNCPTR(alcGetProcAddress);
LOAD_FUNCPTR(alcGetEnumValue);
LOAD_FUNCPTR(alcGetString);
LOAD_FUNCPTR(alcGetIntegerv);
LOAD_FUNCPTR(alcCaptureOpenDevice);
LOAD_FUNCPTR(alcCaptureCloseDevice);
LOAD_FUNCPTR(alcCaptureStart);
LOAD_FUNCPTR(alcCaptureStop);
LOAD_FUNCPTR(alcCaptureSamples);
LOAD_FUNCPTR(alEnable);
LOAD_FUNCPTR(alDisable);
LOAD_FUNCPTR(alIsEnabled);
LOAD_FUNCPTR(alGetString);
LOAD_FUNCPTR(alGetBooleanv);
LOAD_FUNCPTR(alGetIntegerv);
LOAD_FUNCPTR(alGetFloatv);
LOAD_FUNCPTR(alGetDoublev);
LOAD_FUNCPTR(alGetBoolean);
LOAD_FUNCPTR(alGetInteger);
LOAD_FUNCPTR(alGetFloat);
LOAD_FUNCPTR(alGetDouble);
LOAD_FUNCPTR(alGetError);
LOAD_FUNCPTR(alIsExtensionPresent);
LOAD_FUNCPTR(alGetProcAddress);
LOAD_FUNCPTR(alGetEnumValue);
LOAD_FUNCPTR(alListenerf);
LOAD_FUNCPTR(alListener3f);
LOAD_FUNCPTR(alListenerfv);
LOAD_FUNCPTR(alListeneri);
LOAD_FUNCPTR(alListener3i);
LOAD_FUNCPTR(alListeneriv);
LOAD_FUNCPTR(alGetListenerf);
LOAD_FUNCPTR(alGetListener3f);
LOAD_FUNCPTR(alGetListenerfv);
//.........这里部分代码省略.........
示例6: SAFE_DELETE_ARRAY
HRESULT WaveDecoder::Open( LPWSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags )
{
m_id3.EmptyTags();
/*char ex[2048] = "wav";
if(!isFile_ex(strFileName,ex))
{
return E_FAIL;
}*/
HRESULT hr;
if(WAVEFILE_READ != dwFlags)
{
return M_INVALID_PARAMETERS;//E_FAIL;
}
m_dwFlags = dwFlags;
//m_bIsReadingFromMemory = FALSE;
SAFE_DELETE_ARRAY( m_pwfx );
m_pwfx = NULL;
if( m_dwFlags == WAVEFILE_READ )
{
if( strFileName == NULL )
return E_INVALIDARG;
m_hmmio = mmioOpen( strFileName, NULL, MMIO_ALLOCBUF | MMIO_READ );
if( NULL == m_hmmio )
{
HRSRC hResInfo;
HGLOBAL hResData;
DWORD dwSize;
VOID* pvRes;
// Loading it as a file failed, so try it as a resource
if( NULL == ( hResInfo = FindResource( NULL, strFileName, L"WAVE" ) ) )
{
if( NULL == ( hResInfo = FindResource( NULL, strFileName, L"WAV" ) ) )
//return DXTRACE_ERR( L"FindResource", E_FAIL );
return E_FAIL;
}
if( NULL == ( hResData = LoadResource( GetModuleHandle( NULL ), hResInfo ) ) )
//return DXTRACE_ERR( L"LoadResource", E_FAIL );
return E_FAIL;
if( 0 == ( dwSize = SizeofResource( GetModuleHandle( NULL ), hResInfo ) ) )
//return DXTRACE_ERR( L"SizeofResource", E_FAIL );
return E_FAIL;
if( NULL == ( pvRes = LockResource( hResData ) ) )
//return DXTRACE_ERR( L"LockResource", E_FAIL );
return E_FAIL;
m_pResourceBuffer = new CHAR[ dwSize ];
if( m_pResourceBuffer == NULL )
//return DXTRACE_ERR( L"new", E_OUTOFMEMORY );
return E_OUTOFMEMORY;
memcpy( m_pResourceBuffer, pvRes, dwSize );
MMIOINFO mmioInfo;
ZeroMemory( &mmioInfo, sizeof( mmioInfo ) );
mmioInfo.fccIOProc = FOURCC_MEM;
mmioInfo.cchBuffer = dwSize;
mmioInfo.pchBuffer = ( CHAR* )m_pResourceBuffer;
m_hmmio = mmioOpen( NULL, &mmioInfo, MMIO_ALLOCBUF | MMIO_READ );
}
if( FAILED( hr = ReadMMIO() ) )
{
// ReadMMIO will fail if its an not a wave file
mmioClose( m_hmmio, 0 );
// return DXTRACE_ERR( L"ReadMMIO", hr );
return hr;
}
if( FAILED( hr = ResetFile() ) )
//return DXTRACE_ERR( L"ResetFile", hr );
return hr;
// After the reset, the size of the wav file is m_ck.cksize so store it now
m_dwSize = m_ck.cksize;
m_id3.duration_times = (float)m_dwSize / (float) m_pwfx->nAvgBytesPerSec;
m_id3.bitrate = m_pwfx->nChannels * m_pwfx->nSamplesPerSec * m_pwfx->wBitsPerSample;
}
else
{
m_hmmio = mmioOpen( strFileName, NULL, MMIO_ALLOCBUF |
MMIO_READWRITE |
MMIO_CREATE );
if( NULL == m_hmmio )
//return DXTRACE_ERR( L"mmioOpen", E_FAIL );
return E_FAIL;
if( FAILED( hr = WriteMMIO( pwfx ) ) )
{
mmioClose( m_hmmio, 0 );
//return DXTRACE_ERR( L"WriteMMIO", hr );
return hr;
}
//.........这里部分代码省略.........
示例7: FindResource
bool CResLoader::ResourceExists(const SObjectTag& tag)
{
return FindResource(tag.id);
}
示例8: GetResourceTypeById
FourCC CResLoader::GetResourceTypeById(u32 id)
{
if (FindResource(id))
return x50_cachedResInfo->x0_type;
return FourCC();
}
示例9: GetResourceCompression
bool CResLoader::GetResourceCompression(const SObjectTag& tag)
{
if (FindResource(tag.id))
return x50_cachedResInfo->xb_compressed;
return false;
}
示例10: ResourceSize
u32 CResLoader::ResourceSize(const SObjectTag& tag)
{
if (FindResource(tag.id))
return x50_cachedResInfo->x8_size;
return false;
}
示例11: ReloadResource
bool cSoundResourceManagerBase::ReloadResource(const std::string &id)
{
return ReloadResource(FindResource(id));
}
示例12: TStringStream
//---------------------------------------------------------------------------
void __fastcall TFrm1010::execBtPadraoExecute(TObject *Sender)
{
TStringStream *StrStream;
HRSRC HrSql;
HGLOBAL SqlData;
DWORD szbf;
String sCodRotina, sSQL;
if (MessageBox(Handle,"Confirma a carga do menu padrão do sistema?",Caption.c_str(),APP_QUESTION|MB_DEFBUTTON2) == IDNO)
return;
StrStream = new TStringStream("");
HrSql = FindResource(HInstance, "MENUPADRAO", RT_RCDATA);
SqlData = LoadResource(HInstance, HrSql);
szbf = SizeofResource(HInstance, HrSql);
StrStream->Write(SqlData,szbf);
StrStream->Seek(0, soFromBeginning);
XMLLoadMenu->LoadFromStream(StrStream);
TZQuery *QyMenuItem = new TZQuery(Application);
QyMenuItem->Connection = AppConnection;
IXMLNodeList *NodeList = XMLLoadMenu->ChildNodes;
NodeList = NodeList->FindNode("MenuSFG")->ChildNodes;
IXMLNode *InstNode = NULL;
IXMLNodeList *AtrsNode = NULL;
IXMLNode *AtrNode = NULL;
int iNumInsts = NodeList->GetCount();
for (int i=0; i < iNumInsts; i++) {
InstNode = NodeList->Nodes[i];
if (InstNode != NULL) {
AtrsNode = InstNode->GetAttributeNodes();
if (AtrsNode != NULL) {
AtrNode = AtrsNode->FindNode("cod_rotina");
if (AtrNode != NULL) {
sCodRotina = String(AtrNode->Text).Trim();
sSQL = "SELECT 1 FROM tbl_menu_sistema WHERE cod_rotina = " + QuotedStr(sCodRotina);
if (!ValidacoesDB::ExistePrimaryKey(AppConnection, sSQL)) {
sSQL = InstNode->Text;
QyMenuItem->SQL->Text = sSQL;
try {
QyMenuItem->ExecSQL();
}
catch (Exception &e) {
String Msg = "Ocorreu o seguinte erro:\n" + e.Message +\
"\nAo executar o comando de ordem " + IntToStr(i+1) + \
" da carga do menu padrão.";
MessageBox(NULL,Msg.c_str(),"Mensagem de Erro",APP_ERROR);
}
}
}
}
}
}
delete QyMenuItem;
delete StrStream;
//Recarrega o menu
FreeTreeNodes(TreeMenu->Items->GetFirstNode(), -1);
CadMenu->Refresh();
CarregaMenu(NULL);
CadMenu->Filtered = false;
}
示例13: DisplaySignature
void DisplaySignature(HDC MyDC, int x, int y)
{
static DWORD *Signature=NULL; //This holds the DIBSection signature
if(!MyDC) //This is called when window is destroyed, so delete signature data
{
delete[] Signature;
Signature=NULL;
return;
}
else if(Signature==NULL) //Signature data has not yet been extracted, so do so
{
//Prepare to decode signature
//const UCHAR BytesPerPixel=4, TranspMask=255; //32 bits per pixel (for quicker copies and such - variable not used due to changing BYTE*s to DWORD*s), and white=transparent background color - also not used anymore since we directly write in the background color
//Load data from executable
HGLOBAL GetData=LoadResource(NULL, FindResource(NULL, "DakSig", "Sig")); //Load the resource from the executable
BYTE *Input=(BYTE*)LockResource(GetData); //Get the resource data
//Prepare header and decoding data
UINT BitOn=0; //Bit we are currently on in reading
EncodedFileHeader H=*(EncodedFileHeader*)Input; //Save header locally so we have quick memory lookups
DWORD *Output=Signature=new DWORD[H.Width*H.Height]; //Allocate signature memory
//Prepare the index colors
DWORD Indexes[17], IndexSize=NumBitsRequired(H.NumIndexes); //Save full color indexes locally so we have quick lookups, use 17 index array so we don't have to allocate memory (since we already know how many there will be), #16=transparent color
DWORD BackgroundColor=GetSysColor(COLOR_BTNFACE), FontColor=0x067906;
BYTE *BGC=(BYTE*)&BackgroundColor, *FC=(BYTE*)&FontColor;
for(UINT i=0; i<16; i++) //Alpha blend the indexes
{
float Alpha=((EncodedFileHeader*)Input)->Indexes[i] / 255.0f;
BYTE IndexColor[4];
for(int n=0; n<3; n++)
IndexColor[n]=(BYTE)(BGC[n]*Alpha + FC[n]*(1-Alpha));
//IndexColor[3]=0; //Don't really need to worry about the last byte as it is unused
Indexes[i]=*(DWORD*)IndexColor;
}
Indexes[16]=BackgroundColor; //Translucent background = window background color
//Unroll/unencode all the pixels
Input+=(sizeof(EncodedFileHeader)+H.NumIndexes); //Start reading input past the header
do
{
UINT l; //Length (transparent and then index)
//Transparent pixels
memsetd(Output, Indexes[16], l=ReadBits(Input, BitOn, H.TranspSize));
Output+=l;
//Translucent pixels
l=ReadBits(Input, BitOn+=H.TranspSize, H.TranslSize);
BitOn+=H.TranslSize;
for(i=0; i<l; i++) //Write the gray scale out to the 3 pixels, this should technically be done in a for loop, which would unroll itself anyways, but this way ReadBits+index lookup is only done once - ** Would need to be in a for loop if not using gray-scale or 24 bit output
Output[i]=Indexes[ReadBits(Input, BitOn+i*IndexSize, IndexSize)];
Output+=l;
BitOn+=l*IndexSize;
} while(BitOn<H.DataSize);
}
//Output the signature
const BITMAPINFOHEADER MyBitmapInfo= {sizeof(BITMAPINFOHEADER), 207, 42, 1, 32, BI_RGB, 0, 0, 0, 0, 0};
SetDIBitsToDevice(MyDC, x, y, MyBitmapInfo.biWidth, MyBitmapInfo.biHeight, 0, 0, 0, MyBitmapInfo.biHeight, Signature, (BITMAPINFO*)&MyBitmapInfo, DIB_RGB_COLORS);
}
示例14: LoadImageFromResources
static HBITMAP LoadImageFromResources(
_In_ UINT Width,
_In_ UINT Height,
_In_ PCWSTR Name
)
{
UINT width = 0;
UINT height = 0;
UINT frameCount = 0;
BOOLEAN isSuccess = FALSE;
ULONG resourceLength = 0;
HGLOBAL resourceHandle = NULL;
HRSRC resourceHandleSource = NULL;
WICInProcPointer resourceBuffer = NULL;
BITMAPINFO bitmapInfo = { 0 };
HBITMAP bitmapHandle = NULL;
PBYTE bitmapBuffer = NULL;
IWICStream* wicStream = NULL;
IWICBitmapSource* wicBitmapSource = NULL;
IWICBitmapDecoder* wicDecoder = NULL;
IWICBitmapFrameDecode* wicFrame = NULL;
IWICImagingFactory* wicFactory = NULL;
IWICBitmapScaler* wicScaler = NULL;
WICPixelFormatGUID pixelFormat;
WICRect rect = { 0, 0, Width, Height };
__try
{
// Create the ImagingFactory
if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (PVOID*)&wicFactory)))
__leave;
// Find the resource
if ((resourceHandleSource = FindResource(PluginInstance->DllBase, Name, L"PNG")) == NULL)
__leave;
// Get the resource length
resourceLength = SizeofResource(PluginInstance->DllBase, resourceHandleSource);
// Load the resource
if ((resourceHandle = LoadResource(PluginInstance->DllBase, resourceHandleSource)) == NULL)
__leave;
if ((resourceBuffer = (WICInProcPointer)LockResource(resourceHandle)) == NULL)
__leave;
// Create the Stream
if (FAILED(IWICImagingFactory_CreateStream(wicFactory, &wicStream)))
__leave;
// Initialize the Stream from Memory
if (FAILED(IWICStream_InitializeFromMemory(wicStream, resourceBuffer, resourceLength)))
__leave;
if (FAILED(IWICImagingFactory_CreateDecoder(wicFactory, &GUID_ContainerFormatPng, NULL, &wicDecoder)))
__leave;
if (FAILED(IWICBitmapDecoder_Initialize(wicDecoder, (IStream*)wicStream, WICDecodeMetadataCacheOnLoad)))
__leave;
// Get the Frame count
if (FAILED(IWICBitmapDecoder_GetFrameCount(wicDecoder, &frameCount)) || frameCount < 1)
__leave;
// Get the Frame
if (FAILED(IWICBitmapDecoder_GetFrame(wicDecoder, 0, &wicFrame)))
__leave;
// Get the WicFrame image format
if (SUCCEEDED(IWICBitmapFrameDecode_GetPixelFormat(wicFrame, &pixelFormat)))
{
// Check if the image format is supported:
if (IsEqualGUID(&pixelFormat, &GUID_WICPixelFormat32bppBGR))
{
wicBitmapSource = (IWICBitmapSource*)wicFrame;
}
else
{
// Convert the image to the correct format:
if (FAILED(WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGR, (IWICBitmapSource*)wicFrame, &wicBitmapSource)))
__leave;
IWICBitmapFrameDecode_Release(wicFrame);
}
}
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biWidth = rect.Width;
bitmapInfo.bmiHeader.biHeight = -((LONG)rect.Height);
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = 32;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
HDC hdc = CreateCompatibleDC(NULL);
bitmapHandle = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, (PVOID*)&bitmapBuffer, NULL, 0);
ReleaseDC(NULL, hdc);
//.........这里部分代码省略.........
示例15: HD_Load_Rom
VOID HD_Load_Rom(const LPBYTE pCxRomPeripheral, const UINT uSlot)
{
if(!g_bHD_Enabled)
return;
// Attempt to read the AppleHDD FIRMWARE ROM into memory
TCHAR sRomFileName[ 128 ];
_tcscpy( sRomFileName, TEXT("AppleHDD_EX.ROM") );
TCHAR filename[MAX_PATH];
_tcscpy(filename,g_sProgramDir);
_tcscat(filename,sRomFileName );
HANDLE file = CreateFile(filename,
GENERIC_READ,
FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if (file == INVALID_HANDLE_VALUE)
{
HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_HDDRVR_FW), "FIRMWARE");
if(hResInfo == NULL)
return;
DWORD dwResSize = SizeofResource(NULL, hResInfo);
if(dwResSize != HD_FW_FILE_SIZE)
return;
HGLOBAL hResData = LoadResource(NULL, hResInfo);
if(hResData == NULL)
return;
g_pRomData = (BYTE*) LockResource(hResData); // NB. Don't need to unlock resource
if(g_pRomData == NULL)
return;
}
else
{
filerom = (LPBYTE)VirtualAlloc(NULL,0x8000 ,MEM_COMMIT,PAGE_READWRITE);
DWORD bytesread;
ReadFile(file,filerom,0x8000,&bytesread,NULL);
CloseHandle(file);
g_pRomData = (BYTE*) filerom;
}
g_uSlot = uSlot;
memcpy(pCxRomPeripheral + (uSlot*256), g_pRomData + HD_SLOT_FW_OFFSET, HD_SLOT_FW_SIZE);
g_bHD_RomLoaded = true;
// Expansion ROM
if (m_pHDExpansionRom == NULL)
{
m_pHDExpansionRom = new BYTE [HD_FW_SIZE];
if (m_pHDExpansionRom)
memcpy(m_pHDExpansionRom, (g_pRomData+rombankoffset), HD_FW_SIZE);
}
RegisterIoHandler(g_uSlot, HD_IO_EMUL, HD_IO_EMUL, NULL, NULL, NULL, m_pHDExpansionRom);
}