HBITMAP LoadResourceBitmap(HINSTANCE hInstance, LPTSTR 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); }
BOOL CXTPPropertyPage::LoadTemplate(HGLOBAL& hTemplate, HINSTANCE& hInst) { hTemplate = 0; hInst = AfxGetInstanceHandle(); if ((m_psp.dwFlags & PSP_DLGINDIRECT) && m_psp.pResource) { CDialogTemplate dlgTemp((LPCDLGTEMPLATE)m_psp.pResource); hTemplate = dlgTemp.Detach(); } else { hInst = AfxFindResourceHandle(m_psp.pszTemplate, RT_DIALOG); if (!hInst) return FALSE; HRSRC hResource = ::FindResource(hInst, m_psp.pszTemplate, RT_DIALOG); if (!hResource) return FALSE; hTemplate = LoadResource(hInst, hResource); if (!hTemplate) return FALSE; DLGTEMPLATE* pTemplate = (DLGTEMPLATE*)LockResource(hTemplate); CDialogTemplate dlgTemp(pTemplate); UnlockResource(hTemplate); FreeResource(hTemplate); hTemplate = dlgTemp.Detach(); } return TRUE; }
int WINAPI DialogBoxParam(HINSTANCE hInst, LPCSTR lpDlg, HWND hWnd, DLGPROC lpFunc, LPARAM lParam) { HWND hDlg; HRSRC hDialog; HGLOBAL hTemplate; DIALOGDATA *lpdd; LPDLGTEMPLATE lpTemplate; if (!(hDialog = FindResource(hInst, lpDlg, RT_DIALOG))) return -1; if (!(hTemplate = LoadResource(hInst, hDialog))) return -1; if (!(lpTemplate = (LPDLGTEMPLATE)LockResource(hTemplate))) return -1; /* modal dialogs are always visible */ lpTemplate->style |= WS_VISIBLE; lpdd = (DIALOGDATA *)ConvertDlgTemplate(hInst, lpTemplate); hDlg = InternalCreateDialog(hInst,(LPSTR)lpdd,hWnd,lpFunc,lParam); CleanupDialog((LPBYTE)lpdd); if(UnlockResource(hTemplate) == 0) FreeResource(hTemplate); if (!hDlg) return -1; if (hWnd) EnableWindow(hWnd,FALSE); return InternalDialog(hDlg); }
ScreenInfo * CHubResourceManager::GetTable(UINT ID) { HRSRC hrsrc; if (m_ScreenInfo == NULL) { if ((hrsrc = FindResource(m_InstDLL, MAKEINTRESOURCE(ID), "HUBTABLE")) != NULL) { DWORD Size = SizeofResource(m_InstDLL, hrsrc); ASSERT(Size > 0); HGLOBAL hglobal; if ((hglobal = LoadResource(m_InstDLL, hrsrc)) != NULL) { BYTE *lpRes; if ((lpRes = (unsigned char *)LockResource(hglobal)) != NULL) { TRY { m_ScreenInfo = (ScreenInfo *)new BYTE [Size]; memcpy(m_ScreenInfo, lpRes, (int)Size); SetTablePointers(m_ScreenInfo); } CATCH_ALL(e) { } END_CATCH_ALL UnlockResource(hglobal); } FreeResource(hglobal); }
//*********************************************************************** BOOL CLGBApp::InitInstance() //*********************************************************************** { HGLOBAL hData; LPSTR lpTableData; // load the scene table lpTableData = GetResourceData(IDR_SCENETABLE, "gametbl", &hData); if (lpTableData) { CSceneTableParser parser(lpTableData); if (m_nScenes = parser.GetNumEntries()) { m_pSceneTable = new CSceneEntry[m_nScenes]; if (m_pSceneTable) parser.ParseTable((DWORD)m_pSceneTable); } } if (hData) { UnlockResource( hData ); FreeResource( hData ); } if (!m_pSceneTable) return(FALSE); m_Language = (Language)GetSettingInt("Language", English); m_nBookmark = GetSettingInt("Bookmark", 0); if (m_Language != English && m_Language != Spanish) m_Language = English; if (!CPHApp::InitInstance()) return(FALSE); m_hAccel = LoadAccelerators(GetInstance(), MAKEINTRESOURCE(IDR_ACCEL)); return TRUE; }
BOOL CResModule::ReplaceString(UINT nID, WORD wLanguage) { HRSRC hrsrc = FindResourceEx(m_hResDll, RT_STRING, MAKEINTRESOURCE(nID), wLanguage); HGLOBAL hglStringTable; LPWSTR p; if (!hrsrc) MYERROR; hglStringTable = LoadResource(m_hResDll, hrsrc); if (!hglStringTable) goto DONE_ERROR; p = (LPWSTR)LockResource(hglStringTable); if (p == NULL) goto DONE_ERROR; /* [Block of 16 strings. The strings are Pascal style with a WORD length preceding the string. 16 strings are always written, even if not all slots are full. Any slots in the block with no string have a zero WORD for the length.] */ //first check how much memory we need size_t nMem = 0; LPWSTR pp = p; for (int i=0; i<16; ++i) { nMem++; size_t len = GET_WORD(pp); pp++; std::wstring msgid = std::wstring(pp, len); WCHAR * pBuf = new WCHAR[MAX_STRING_LENGTH*2]; SecureZeroMemory(pBuf, MAX_STRING_LENGTH*2*sizeof(WCHAR)); wcscpy(pBuf, msgid.c_str()); CUtils::StringExtend(pBuf); msgid = std::wstring(pBuf); RESOURCEENTRY resEntry; resEntry = m_StringEntries[msgid]; wcscpy(pBuf, resEntry.msgstr.c_str()); CUtils::StringCollapse(pBuf); size_t newlen = wcslen(pBuf); if (newlen) nMem += newlen; else nMem += len; pp += len; delete [] pBuf; } WORD * newTable = new WORD[nMem + (nMem % 2)]; SecureZeroMemory(newTable, (nMem + (nMem % 2))*2); size_t index = 0; for (int i=0; i<16; ++i) { int len = GET_WORD(p); p++; std::wstring msgid = std::wstring(p, len); WCHAR * pBuf = new WCHAR[MAX_STRING_LENGTH*2]; SecureZeroMemory(pBuf, MAX_STRING_LENGTH*2*sizeof(WCHAR)); wcscpy(pBuf, msgid.c_str()); CUtils::StringExtend(pBuf); msgid = std::wstring(pBuf); RESOURCEENTRY resEntry; resEntry = m_StringEntries[msgid]; wcscpy(pBuf, resEntry.msgstr.c_str()); CUtils::StringCollapse(pBuf); size_t newlen = wcslen(pBuf); if (newlen) { newTable[index++] = (WORD)newlen; wcsncpy((wchar_t *)&newTable[index], pBuf, newlen); index += newlen; m_bTranslatedStrings++; } else { newTable[index++] = (WORD)len; if (len) wcsncpy((wchar_t *)&newTable[index], p, len); index += len; if (len) m_bDefaultStrings++; } p += len; delete [] pBuf; } if (!UpdateResource(m_hUpdateRes, RT_STRING, MAKEINTRESOURCE(nID), (m_wTargetLang ? m_wTargetLang : wLanguage), newTable, (DWORD)(nMem + (nMem % 2))*2)) { delete [] newTable; goto DONE_ERROR; } if ((m_wTargetLang)&&(!UpdateResource(m_hUpdateRes, RT_STRING, MAKEINTRESOURCE(nID), wLanguage, NULL, 0))) { delete [] newTable; goto DONE_ERROR; } delete [] newTable; UnlockResource(hglStringTable); FreeResource(hglStringTable); return TRUE; DONE_ERROR: UnlockResource(hglStringTable); FreeResource(hglStringTable); MYERROR; }
BOOL CResModule::ExtractMenu(UINT nID) { HRSRC hrsrc = FindResource(m_hResDll, MAKEINTRESOURCE(nID), RT_MENU); HGLOBAL hglMenuTemplate; WORD version, offset; DWORD dwHelpId; const WORD *p, *p0; if (!hrsrc) MYERROR; hglMenuTemplate = LoadResource(m_hResDll, hrsrc); if (!hglMenuTemplate) MYERROR; p = (const WORD*)LockResource(hglMenuTemplate); if (p == NULL) MYERROR; // Standard MENU resource //struct MenuHeader { // WORD wVersion; // Currently zero // WORD cbHeaderSize; // Also zero //}; // MENUEX resource //struct MenuExHeader { // WORD wVersion; // One // WORD wOffset; // DWORD dwHelpId; //}; p0 = p; version = GET_WORD(p); p++; switch (version) { case 0: { offset = GET_WORD(p); p += offset; p++; if (!ParseMenuResource(p)) goto DONE_ERROR; } break; case 1: { offset = GET_WORD(p); p++; dwHelpId = GET_DWORD(p); if (!ParseMenuExResource(p0 + offset)) goto DONE_ERROR; } break; default: goto DONE_ERROR; } UnlockResource(hglMenuTemplate); FreeResource(hglMenuTemplate); return TRUE; DONE_ERROR: UnlockResource(hglMenuTemplate); FreeResource(hglMenuTemplate); MYERROR; }
/* * About_InfoCredz_DlgProc() [internal] * * The DlgProc of the Info And Credits about tab. Called by windows. */ static BOOL CALLBACK About_InfoCredz_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { LPTSTR pszTextResource; LPTSTR pszPage; FADECTRLPAGE fcp; HGLOBAL hResource; HWND hwndFader; hwndFader = GetDlgItem(hwndDlg, IDC_FADER_ABOUT); /* load the ascii picture resource */ hResource = LoadResource(g_hInstance, FindResource(g_hInstance, MAKEINTRESOURCE(IDR_ABOUTASCII), _T("ASCIIPIC"))); pszTextResource = (LPTSTR)LockResource(hResource); INITSTRUCT(fcp, FALSE); fcp.crBackground = RGB(0, 0, 0); fcp.crFadeTo = RGB(40, 125, 205); fcp.nFadeInWaitTime = -1; fcp.nFadeOutWaitTime = -1; fcp.nFadePercent = -1; fcp.nPercentageDelta = -1; /* the ascii pics pages are split by the character */ for (pszPage = _tcstok(pszTextResource, _T("")); pszPage != NULL; pszPage = _tcstok(NULL, _T(""))) { fcp.pszPageText = pszPage; FadeCtrl_AddPage(hwndFader, &fcp); } /* clean up */ UnlockResource(hResource); FreeResource(hResource); FadeCtrl_Activate(hwndFader); } return (TRUE); case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case PSN_SETACTIVE: FadeCtrl_Activate(hwndFader); SetWindowLong(hwndDlg, DWL_MSGRESULT, 0); return (TRUE); case PSN_KILLACTIVE: FadeCtrl_Deactivate(hwndFader); SetWindowLong(hwndDlg, DWL_MSGRESULT, FALSE); return (TRUE); } break; } return (FALSE); }
BOOL CResModule::ExtractDialog(UINT nID) { const WORD* lpDlg; const WORD* lpDlgItem; DIALOGINFO dlg; DLGITEMINFO dlgItem; WORD bNumControls; HRSRC hrsrc; HGLOBAL hGlblDlgTemplate; hrsrc = FindResource(m_hResDll, MAKEINTRESOURCE(nID), RT_DIALOG); if (hrsrc == NULL) MYERROR; hGlblDlgTemplate = LoadResource(m_hResDll, hrsrc); if (hGlblDlgTemplate == NULL) MYERROR; lpDlg = (const WORD*) LockResource(hGlblDlgTemplate); if (lpDlg == NULL) MYERROR; lpDlgItem = (const WORD*) GetDialogInfo(lpDlg, &dlg); bNumControls = dlg.nbItems; if (dlg.caption) { TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH]; SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR)); _tcscpy(pBuf, dlg.caption); CUtils::StringExtend(pBuf); std::wstring wstr = std::wstring(pBuf); RESOURCEENTRY entry = m_StringEntries[wstr]; entry.resourceIDs.insert(nID); m_StringEntries[wstr] = entry; delete [] pBuf; } while (bNumControls-- != 0) { TCHAR szTitle[500]; SecureZeroMemory(szTitle, sizeof(szTitle)); BOOL bCode; lpDlgItem = GetControlInfo((WORD *) lpDlgItem, &dlgItem, dlg.dialogEx, &bCode); if (bCode == FALSE) _tcscpy(szTitle, dlgItem.windowName); if (_tcslen(szTitle) > 0) { CUtils::StringExtend(szTitle); std::wstring wstr = std::wstring(szTitle); RESOURCEENTRY entry = m_StringEntries[wstr]; entry.resourceIDs.insert(dlgItem.id); m_StringEntries[wstr] = entry; } } UnlockResource(hGlblDlgTemplate); FreeResource(hGlblDlgTemplate); return (TRUE); }
int WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAcc, LPMSG lpMsg) { ACCELENTRY *lpData; WORD wEvent; int rc,code; int keystate; /* we must have an accelerator table. */ if(hAcc == 0) return 0; /* must be one of keydown or syskey down, we do not do keyup */ if(lpMsg->message == WM_KEYDOWN || lpMsg->message == WM_SYSKEYDOWN) { int char_code = DRVCALL_KEYBOARD(PKH_GETCHAR, lpMsg->wParam, 0, 0); /* these don't generate accelerators */ if (lpMsg->wParam == VK_SHIFT) return 0; if (lpMsg->wParam == VK_CONTROL) return 0; if (lpMsg->wParam == 0x2a) return 0; /* lock the handle to the accelerators */ lpData = (ACCELENTRY *) LockResource(hAcc); /* if we have one, then lets try to match it up */ if(lpData) { /* setup initial state of keyboard */ if (GetKeyState(VK_CONTROL)) keystate = 8; else keystate = 0; /* what is initial keystate */ if (GetKeyState(VK_SHIFT)) keystate |= 4; /* loop through the accelerators */ while (TRUE) { /* what event are we looking for */ rc = 0; code = 0; wEvent = lpMsg->wParam; /* vk_key or ascii event */ if ((lpData->fFlags & 1) == 0) { /* the event we match will be ascii */ if (char_code != 0) /* compare with ascii code */ wEvent = char_code; if ((keystate & 0x8)) /* control key down */ wEvent &= 0x1f; /* mask off to ctrl range */ } else { /* the following applies to VK's only */ /* Account for control & shift */ rc |= (keystate & 0xc); /* test alt key */ if (lpMsg->lParam & 0x20000000) rc |= 0x10; /* Account for acc. needing shift, ctrl, alt. */ code |= (lpData->fFlags & 0x1c); } /* if we matched the event */ /* we should have done this first */ /* after checking for ascii vs. virtual */ if (wEvent != lpData->wEvent) rc = -1; /* we have a matching key combination */ /* and the event matches */ if (rc == code) { /* send the corresponding event */ SendMessage(hWnd,WM_COMMAND, GET_WM_COMMAND_MPS(lpData->wId,0,1)); /* unlock table and return TRUE */ UnlockResource(hAcc); return 1; } if (lpData->fFlags & 0x80) break; else lpData++; } UnlockResource(hAcc); } } return 0; }
void force_play_sound(short which) { short i, num_fails = 0; char snd_name[30]; Boolean asyn = FALSE,a_sound_did_get_played = FALSE; Boolean check_sound; HRSRC h; if ((sounds_messed == TRUE) || (play_sounds == FALSE)) return; if (which < 0) { asyn = TRUE; which = which * -1; } if (which >= 100) return; if ((always_asynch[which] == TRUE) && ((can_ignore[which] == 1) || (can_ignore[which] >= 3))) asyn = TRUE; // if ((can_ignore[which] > 0) && (can_ignore[which] < 5) && (party.stuff_done[305][5] == 1)) // return; if ((can_ignore[which] != 1) && (can_ignore[which] < 3)) asyn = FALSE; // if ((party.stuff_done[305][5] == 1) && (can_ignore[which] < 5)) // asyn = FALSE; //print_nums(1000 + can_ignore[which],which,(short) asyn); if ((load_when_play[which] == TRUE) && (sound_handles[which] == NULL)) { // if (can_ignore[which] != 4) asyn = FALSE; sprintf((char *)snd_name,"#%d",(int)(which + 1)); h = FindResource(store_hInstance,snd_name,"#100"); sound_handles[which] = LoadResource(store_hInstance,h); snds[which] = (char *) LockResource(sound_handles[which]); // ASB("Loaded sound:"); // print_nums(0,0,which); } if (store_last_sound_played == 6) { //ASB("Interrupted snd."); sndPlaySound(NULL,0); } if (asyn == TRUE) { if (can_ignore[which] >= 4) check_sound = (Boolean)sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP); else check_sound = (Boolean)sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY); while (check_sound == FALSE) { if (can_ignore[store_last_sound_played] == 4) {// then sound goes away //ASB("Sound overruled by asynch sound."); return; } num_fails++; if (num_fails < 40) pause(25); else { MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error a. Game can still be played, but quietly.", "Sound Error",MB_OK | MB_ICONEXCLAMATION); //print_nums(111,which,num_fails); //sounds_messed = TRUE; return; } //ASB ("Asynch clearing buffer!!!"); //check_sound = sndPlaySound(snds[99],SND_SYNC | SND_MEMORY); sndPlaySound(NULL,0); if (can_ignore[which] >= 4) check_sound = (Boolean)sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP); else check_sound = (Boolean)sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY); } a_sound_did_get_played = TRUE; } else { if (can_ignore[which] >= 4) check_sound = (Boolean)sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP); else check_sound = (Boolean)sndPlaySound(snds[which],SND_SYNC | SND_MEMORY); while (check_sound == FALSE) { if (can_ignore[store_last_sound_played] == 4) {// then sound goes away //ASB("Sound overruled by asynch sound."); return; } num_fails++; if (num_fails < 40) pause(25); else { MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error b. Game can still be played, but quietly.", "Sound Error",MB_OK | MB_ICONEXCLAMATION); //print_nums(222,which,num_fails); //sounds_messed = TRUE; return; } //ASB ("Asynch clearing buffer!!!"); //check_sound = sndPlaySound(snds[99],SND_SYNC | SND_MEMORY); sndPlaySound(NULL,0); if (can_ignore[which] >= 4) check_sound = (Boolean)sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP); else check_sound = (Boolean)sndPlaySound(snds[which],SND_SYNC | SND_MEMORY); } a_sound_did_get_played = TRUE; } store_last_sound_played = which; if ((load_when_play[which] == TRUE) && (asyn == FALSE)) { // deleted a seemingly extraneous LoadResource here //ASB("Dumped a sound."); UnlockResource(sound_handles[which]); FreeResource(sound_handles[which]); sound_handles[which] = NULL; } //else if (load_when_play[which] == TRUE) ASB("Kept a temp. sound."); for (i = 0; i < NUM_SOUNDS; i++) if ((load_when_play[which] == TRUE) && (sound_handles[which] != NULL) && (a_sound_did_get_played == TRUE) && (i != which)){ // deleted a seemingly extraneous LoadResource here UnlockResource(sound_handles[i]); FreeResource(sound_handles[i]); sound_handles[i] = NULL; //ASB("Kept sound dumped:"); //print_nums(0,0,i); } }
//******************************************************************************* BOOL CBCGPTagManager::LoadFromResource (LPCTSTR lpszResID, LPCTSTR lpszResType) { if (lpszResID == NULL) { ASSERT (FALSE); return FALSE; } if (lpszResType == NULL) { ASSERT (FALSE); return FALSE; } BOOL bRes = FALSE; HINSTANCE hInst = AfxFindResourceHandle(lpszResID, lpszResType); HRSRC hRsrc = ::FindResource(hInst, lpszResID, lpszResType); if (hRsrc == NULL) { return FALSE; } HGLOBAL hGlobal = LoadResource(hInst, hRsrc); if (hGlobal == NULL) { return FALSE; } #ifdef _UNICODE LPWSTR lpChars = NULL; LPSTR lpa = (LPSTR) LockResource (hGlobal); VERIFY(lpa != NULL); const size_t nChars = strlen (lpa) + 1; lpChars = (LPWSTR) new WCHAR[nChars]; LPCTSTR lpszXML = AfxA2WHelper (lpChars, lpa, (int)nChars); #else LPCTSTR lpszXML = (LPCTSTR) LockResource (hGlobal); #endif if (lpszXML != NULL) { SetBuffer (lpszXML); bRes = TRUE; } UnlockResource (hGlobal); FreeResource (hGlobal); #ifdef _UNICODE if (lpChars != NULL) { delete [] lpChars; lpChars = NULL; } #endif return bRes; }
// **************************************************************************** // // Function Name: LoadResourceBitmap( ) // // Description: Load DIB from resource and get it's palette // // Returns: bitmap handle or NULL on failure // // Exceptions: None // // **************************************************************************** // HBITMAP LoadResourceBitmap(HINSTANCE hInstance, LPSTR lpString, HPALETTE FAR* lphPalette) { // initialise all our variables HRSRC hRsrc = NULL; HGLOBAL hGlobal = NULL; HGLOBAL hTemp = NULL; DWORD dwSize = 0; HBITMAP hBitmapFinal = NULL; HPALETTE hPalOld = NULL; LPSTR lpRes = NULL; LPSTR lpNew = NULL; HDC hdc = NULL; int iNumColors = 0; LPBITMAPINFOHEADER lpbi = NULL; // find the resource in the resource file hRsrc = FindResource(hInstance, lpString, RT_BITMAP); if ( hRsrc != NULL ) { // get a handle to the resource data hTemp = LoadResource(hInstance, hRsrc); if ( hTemp != NULL ) { // get it's size dwSize = SizeofResource(hInstance, hRsrc); // lock the resource data lpRes = (char*) LockResource(hTemp); if ( lpRes != NULL ) { // allocate memory to copy the data hGlobal = GlobalAlloc(GHND, dwSize); if ( hGlobal != NULL ) { // lock the allocated memory lpNew = (char*)GlobalLock(hGlobal); if ( lpNew != NULL ) { // copy the data memcpy(lpNew, lpRes, dwSize); // unlock and free the resource UnlockResource(hTemp); FreeResource(hTemp); lpbi = (LPBITMAPINFOHEADER)lpNew; // get a screen DC compatible with the screen hdc = GetDC(NULL); // create a palette from the bitmap info header *lphPalette = CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors); // select the palette into the DC if (*lphPalette) { hPalOld = SelectPalette(hdc,*lphPalette,FALSE); RealizePalette(hdc); } // create the DIB bitmap using the DC's palette hBitmapFinal = CreateDIBitmap( hdc, (LPBITMAPINFOHEADER)lpbi, (LONG) CBM_INIT, (LPSTR)lpbi + lpbi->biSize + iNumColors * sizeof(RGBQUAD), (LPBITMAPINFO)lpbi, DIB_RGB_COLORS ); if ( *lphPalette && hPalOld ) SelectPalette(hdc,hPalOld,FALSE); // release the HDC ReleaseDC(NULL,hdc); // unlock the allocated bitmap data GlobalUnlock(hGlobal); } // GlobalLock failed // free the bitmpa data GlobalFree(hGlobal); } // GlobalAlloc failed } // LockResource failed } // LoadResource failed } // FindResource failed // return the bitmap return hBitmapFinal; }
//将二进制资源保存为文件 //saveAsFileName:保存文件为该名称,resID:资源ID,folder:文件夹;bSubPathOfExe:是否放在应用程序文件夹下,true:是 BOOL CUtil::saveBinResourceAsFile(CString saveAsFileName,UINT resID,CString folder,BOOL bSubPathOfExe) { // HRSRC hsrc=::FindResource(NULL,MAKEINTRESOURCE(resID),TEXT("BIN"));//定位资源 if(NULL==hsrc) { return FALSE; }//end if DWORD dwSize=::SizeofResource(NULL,hsrc);//获取资源大小 if(0==dwSize) { return FALSE; }//end if HGLOBAL hGlobal=::LoadResource(NULL,hsrc);//加载资源 if(NULL==hGlobal) { return FALSE; }//end if LPBYTE p; p=(LPBYTE)GlobalAlloc(GPTR,dwSize);//分配内存 if(NULL==p) { //AfxMessageBox(_T("内存分配失败")); return FALSE; }//end if ::CopyMemory((LPVOID)p,(LPCVOID)::LockResource(hGlobal),dwSize);//复制数据到p GlobalUnlock(hGlobal); CString path; //构造文件路径 if(bSubPathOfExe)//放在应用程序文件夹下 { if(""==folder)//直接放在应用程序文件夹下 { path.Format(_T("%s\\%s"),getExePath(),saveAsFileName); } else { path.Format(_T("%s\\%s\\%s"),getExePath(),folder,saveAsFileName); }//end if } else//放在自己选择的文件夹下 { if(""==folder) { path.Format(_T("%s"),saveAsFileName);//此时包含文件夹和文件名 } else { path.Format(_T("%s\\%s"),folder,saveAsFileName); }//end if }//end if CFile file(path,CFile::modeCreate|CFile::modeWrite); file.Write(p,dwSize);//写入 file.Close();//关闭 //释放资源 UnlockResource(hGlobal); FreeResource(hGlobal); ::GlobalFree((HGLOBAL)p); return TRUE; }
//-------------------------------------------------------------------------------------- //LoadShaderFromResource // //loads shader given a resource id //-------------------------------------------------------------------------------------- HRESULT CEffect::LoadShaderFromResource(uint32 a_ResourceID, IDirect3DDevice9 *a_pDevice) { HRESULT hr; ID3DXBuffer *errorBuffer; HRSRC resourceInfo; HGLOBAL resourceData; char8 *shaderText; m_pDevice = a_pDevice; //delete old effect if multiple calls to load shader are made SAFE_RELEASE(m_pEffect); // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the // shader debugger. Debugging vertex shaders requires either REF or software vertex // processing, and debugging pixel shaders requires REF. The // D3DXSHADER_FORCE_*_SOFTWARE_NOOPT flag improves the debug experience in the // shader debugger. It enables source level debugging, prevents instruction // reordering, prevents dead code elimination, and forces the compiler to compile // against the next higher available software target, which ensures that the // unoptimized shaders do not exceed the shader model limitations. Setting these // flags will cause slower rendering since the shaders will be unoptimized and // forced into software. See the DirectX documentation for more information about // using the shader debugger. DWORD dwShaderFlags = 0; #ifdef DEBUG_VS dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT; #endif #ifdef DEBUG_PS dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT; #endif //load shadertext from resource resourceInfo = FindResource(NULL, MAKEINTRESOURCE(a_ResourceID), L"EFFECTFILE"); if(resourceInfo == NULL) { _snwprintf_s(m_ErrorMsg, MAX_ERROR_MSG, MAX_ERROR_MSG, L"Resource %d of type ''EFFECTFILE'' not found.", a_ResourceID ); } resourceData = LoadResource(NULL, resourceInfo ); shaderText = (char8 *)LockResource( resourceData); //Create effect from text loaded from resource // load and compile .fx file // If this fails, there should be debug output as to // why the .fx file failed to compile hr = D3DXCreateEffect( m_pDevice, //LPDIRECT3DDEVICE9 pDevice, shaderText, //LPCVOID pSrcData, (uint32)SizeofResource(NULL, resourceInfo), //UINT SrcDataLen, NULL, //const D3DXMACRO *pDefines, NULL, //LPD3DXINCLUDE pInclude, 0, //DWORD Flags, NULL, //LPD3DXEFFECTPOOL pPool, &m_pEffect, //LPD3DXEFFECT *ppEffect, &errorBuffer //LPD3DXBUFFER *ppCompilationErrors ); UnlockResource( resourceData ); FreeResource( resourceData ); //return failure and record error message if failure if(FAILED(hr)) { //error is in 8-bit character format, so for swprintf to use the string, %S (capital S) is used. if(errorBuffer != NULL) { _snwprintf_s(m_ErrorMsg, MAX_ERROR_MSG, MAX_ERROR_MSG, L"Shader Compile Error: %S.", errorBuffer->GetBufferPointer() ); } else { _snwprintf_s(m_ErrorMsg, MAX_ERROR_MSG, MAX_ERROR_MSG, L"Shader Compile Error: no output from D3DXCreateEffectFromResource." ); } SAFE_RELEASE(errorBuffer); return hr; } _snwprintf_s(m_ErrorMsg, MAX_ERROR_MSG, MAX_ERROR_MSG, L"FX file in Resource %d Compiled Successfully.", a_ResourceID); return S_OK; }
int THelp :: AddHelp ( THelpApply appliesto, void * object, char * helpfile, TResId id ) { char Buffer [ MAX_PARAMETER_LENGTH ] ; HGLOBAL hGlobal ; HRSRC hResource ; char far * p, * ResourceEnd ; char * q ; THelpEntry * Entries = NULL ; THelpEntry NewEntry ; int EntryCount = 0 ; DWORD ResourceSize ; BOOL Break = FALSE ; // Accéder à la ressource hResource = FindResource ( * :: Module, id, HELP_RESOURCE ) ; ResourceSize = SizeofResource ( * :: Module, hResource ) ; if ( ! hResource ) return ( -1 ) ; hGlobal = LoadResource ( * :: Module, hResource ) ; p = ( char far * ) LockResource ( hGlobal ) ; ResourceEnd = p + ( unsigned int ) ResourceSize ; // Parcours de la resource while ( p < ResourceEnd ) { switch ( * p ) { // DEFINE_WINDOW : 1 seul octet case DEFWINTYPE - '0' : NewEntry. Id = 0 ; NewEntry. Type = WindowStart ; NewEntry. ContextParam = 0L ; p ++ ; break ; // END_WINDOW : 1 seul octet case ENDWINTYPE - '0' : NewEntry. Id = 0 ; NewEntry. Type = WindowEnd ; NewEntry. ContextParam = 0L ; p ++ ; break ; // DEFINE_MENU : 1 octet + 1 chaîne case DEFMENUTYPE - '0' : NewEntry. Id = 0 ; NewEntry. Type = MenuStart ; p ++ ; q = Buffer ; while ( p < ResourceEnd && q < Buffer + sizeof ( Buffer ) - 1 && * p ) * q ++ = * p ++ ; * q = 0 ; p ++ ; // Sauter le zéro NewEntry. ContextParam = ( DWORD ) strdup ( Buffer ) ; break ; // END_MENU : 1 octet case ENDMENUTYPE - '0' : NewEntry. Id = 0 ; NewEntry. Type = MenuEnd ; NewEntry. ContextParam = 0L ; p ++ ; break ; // DEFINE_CONTROL : 1 seul octet case DEFCONTROLTYPE - '0' : NewEntry. Id = 0 ; NewEntry. Type = ControlStart ; NewEntry. ContextParam = 0L ; p ++ ; break ; // END_CONTROL : 1 seul octet case ENDCONTROLTYPE - '0' : NewEntry. Id = 0 ; NewEntry. Type = ControlEnd ; NewEntry. ContextParam = 0L ; p ++ ; break ; // HELPID : 1 octet, id sur 16 bits, contexte sur 32 case BYIDTYPE - '0' : CHECKBOUND ( p, ResourceEnd, 1 + sizeof ( short int ) + sizeof ( long int ) ) ; p ++ ; NewEntry. Id = * ( ( short int * ) p ) ; p += sizeof ( short int ) ; NewEntry. ContextParam = * ( ( long int * ) p ) ; p += sizeof ( long int ) ; break ; // HELPKEY : 1 octet, id sur 16 bits, chaîne case BYKEYTYPE - '0' : CHECKBOUND ( p, ResourceEnd, 1 + sizeof ( short int ) ) ; p ++ ; NewEntry. Id = * ( ( short int * ) p ) ; p += sizeof ( short int ) ; q = Buffer ; while ( p < ResourceEnd && q < Buffer + sizeof ( Buffer ) - 1 && * p ) * q ++ = * p ++ ; * q = 0 ; p ++ ; // Sauter le zéro NewEntry. ContextParam = ( DWORD ) strdup ( Buffer ) ; break ; // Zéro : c'est la fin de la ressource (normalement...) case 0 : NewEntry. Id = 0 ; NewEntry. Type = EndOfTable ; NewEntry. ContextParam = 0L ; Break = TRUE ; break ; // Autre : y a une douille dans le pâté default : p ++ ; continue ; } // Le type de l'entrée a été déterminé : on l'ajoute à notre table if ( ! EntryCount ) Entries = ( THelpEntry * ) malloc ( REALLOC_INCREMENT * sizeof ( THelpEntry ) ) ; else if ( ! ( ( EntryCount + 1 ) % REALLOC_INCREMENT ) ) Entries = ( THelpEntry * ) realloc ( Entries, ( EntryCount + 1 + REALLOC_INCREMENT ) * sizeof ( THelpEntry ) ) ; if ( Entries == NULL ) throw xmsg ( string ( "Erreur d'allocation mémoire durant la lecture" " d'une ressource HELPTABLE" ) ) ; Entries [ EntryCount ++ ] = NewEntry ; // On est tombé sur le zéro de fin... if ( Break ) break ; } EndOfLoop : UnlockResource ( hGlobal ) ; FreeResource ( hGlobal ) ; // On arrive ici, que la lecture se soit bien passée ou non if ( ! EntryCount ) // Léger problème... return ( -1 ) ; else return ( AddHelp ( appliesto, object, helpfile, Entries ) ) ; }
static BOOL IncResourceIterator( struct ResourceIterator* iter, struct ResourceContext* ctx ) { BOOL rc = FALSE; UnlockResource( iter, ctx ); switch( iter->m_Resource->isapnpr_Type ) { case ISAPNP_NT_IRQ_RESOURCE: { struct ISAPNP_IRQResource* r; r = (struct ISAPNP_IRQResource*) iter->m_Resource; while( ! rc && iter->m_IRQBit < 16 ) { ++iter->m_IRQBit; if( r->isapnpirqr_IRQMask & ( 1 << iter->m_IRQBit ) ) { rc = LockResource( iter, ctx ); } } break; } case ISAPNP_NT_DMA_RESOURCE: { struct ISAPNP_DMAResource* r; r = (struct ISAPNP_DMAResource*) iter->m_Resource; while( ! rc && iter->m_ChannelBit < 8 ) { ++iter->m_ChannelBit; if( r->isapnpdmar_ChannelMask & ( 1 << iter->m_ChannelBit ) ) { rc = LockResource( iter, ctx ); } } break; } case ISAPNP_NT_IO_RESOURCE: { struct ISAPNP_IOResource* r; r = (struct ISAPNP_IOResource*) iter->m_Resource; while( ! rc && iter->m_Base <= r->isapnpior_MaxBase ) { iter->m_Base += r->isapnpior_Alignment; if( iter->m_Base <= r->isapnpior_MaxBase ) { rc = LockResource( iter, ctx ); } } break; } case ISAPNP_NT_MEMORY_RESOURCE: default: break;; } return rc; }
void CPluginTestDlg::OnSearch() { // If it has already been setup, get rid of it if ( m_lpPluginList ) FreeUpPluginList(); m_listPlugins.ResetContent(); int iListIndex = 0; // Loop through the plugin search path, and add any plugins to the list CString szFileSpec; m_editSearchPath.GetWindowText(szFileSpec); if (szFileSpec.GetAt(szFileSpec.GetLength()-1) != '\\') szFileSpec += "\\"; szFileSpec += "*.8b?"; CFileFind FileFind; int bOK = FileFind.FindFile(szFileSpec); if (bOK) bOK = FileFind.FindNextFile(); // Walk the directory... BeginWaitCursor(); while (bOK) { if (FileFind.IsDirectory()) { // Skip over directories bOK = FileFind.FindNextFile(); continue; } CString szName = FileFind.GetFileName(); char LastChar = szName.GetAt(szName.GetLength()-1); if ( isupper( LastChar )) LastChar = tolower( LastChar ); // Process the matching file CString szDLL = FileFind.GetFilePath(); HMODULE hModule; if ( hModule = (HMODULE)LoadLibrary( szDLL )) { // Do module specifics here... STRING szResType; szResType[0] = '\0'; PLUGIN_TYPE piType = PIT_FILTER; if ( LastChar == 'f' ) { strcpy( szResType, "_8BFM" ); piType = PIT_FILTER; } else if ( LastChar == 'e' ) { strcpy( szResType, "_8BEM" ); piType = PIT_EXPORT; } else if ( LastChar == 'a' ) { strcpy( szResType, "_8BAM" ); piType = PIT_ACQUIRE; } else { } HRSRC hResource = FindResource( hModule, (LPCSTR)"#1", (LPCSTR)szResType ); // if hResource != NULL, then the plugin is the OLD style bool bOldStyle; CString szFilterName; if ( hResource ) { bOldStyle = true; HGLOBAL hResData = LoadResource( hModule, hResource ); LPSTR lpResData = (LPSTR)LockResource( hResData ); szFilterName = (LPSTR)&lpResData[2]; UnlockResource( hResData ); FreeResource( hResData ); } else { if (hResource = FindResource( hModule, MAKEINTRESOURCE(16000), (LPCSTR)"PIPL" )) { bOldStyle = false; HGLOBAL hResData = LoadResource( hModule, hResource ); LPSTR lpResData = (LPSTR)LockResource( hResData ); szFilterName = (LPSTR)&lpResData[47]; UnlockResource( hResData ); FreeResource( hResData ); } } // If we found the resource we were looming for... if (hResource) { AddFilter( szFilterName, szDLL, bOldStyle, piType, iListIndex++ ); m_listPlugins.AddString(szName); } FreeLibrary( hModule ); } bOK = FileFind.FindNextFile(); } FileFind.Close(); EndWaitCursor(); }
BOOL CResModule::ReplaceMenu(UINT nID, WORD wLanguage) { HRSRC hrsrc = FindResourceEx(m_hResDll, RT_MENU, MAKEINTRESOURCE(nID), wLanguage); HGLOBAL hglMenuTemplate; WORD version, offset; LPWSTR p; WORD *p0; DWORD dwHelpId; if (!hrsrc) MYERROR; //just the language wasn't found hglMenuTemplate = LoadResource(m_hResDll, hrsrc); if (!hglMenuTemplate) MYERROR; p = (LPWSTR)LockResource(hglMenuTemplate); if (p == NULL) MYERROR; //struct MenuHeader { // WORD wVersion; // Currently zero // WORD cbHeaderSize; // Also zero //}; // MENUEX resource //struct MenuExHeader { // WORD wVersion; // One // WORD wOffset; // DWORD dwHelpId; //}; p0 = (WORD *)p; version = GET_WORD(p); p++; switch (version) { case 0: { offset = GET_WORD(p); p += offset; p++; size_t nMem = 0; if (!CountMemReplaceMenuResource((WORD *)p, &nMem, NULL)) goto DONE_ERROR; WORD * newMenu = new WORD[nMem + (nMem % 2)+2]; SecureZeroMemory(newMenu, (nMem + (nMem % 2)+2)*2); size_t index = 2; // MenuHeader has 2 WORDs zero if (!CountMemReplaceMenuResource((WORD *)p, &index, newMenu)) { delete [] newMenu; goto DONE_ERROR; } if (!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), (m_wTargetLang ? m_wTargetLang : wLanguage), newMenu, (DWORD)(nMem + (nMem % 2)+2)*2)) { delete [] newMenu; goto DONE_ERROR; } if ((m_wTargetLang)&&(!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), wLanguage, NULL, 0))) { delete [] newMenu; goto DONE_ERROR; } delete [] newMenu; } break; case 1: { offset = GET_WORD(p); p++; dwHelpId = GET_DWORD(p); size_t nMem = 0; if (!CountMemReplaceMenuExResource((WORD *)(p0 + offset), &nMem, NULL)) goto DONE_ERROR; WORD * newMenu = new WORD[nMem + (nMem % 2) + 4]; SecureZeroMemory(newMenu, (nMem + (nMem % 2) + 4) * 2); CopyMemory(newMenu, p0, 2 * sizeof(WORD) + sizeof(DWORD)); size_t index = 4; // MenuExHeader has 2 x WORD + 1 x DWORD if (!CountMemReplaceMenuExResource((WORD *)(p0 + offset), &index, newMenu)) { delete [] newMenu; goto DONE_ERROR; } if (!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), (m_wTargetLang ? m_wTargetLang : wLanguage), newMenu, (DWORD)(nMem + (nMem % 2) + 4) * 2)) { delete [] newMenu; goto DONE_ERROR; } if ((m_wTargetLang)&&(!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), wLanguage, NULL, 0))) { delete [] newMenu; goto DONE_ERROR; } delete [] newMenu; } break; default: goto DONE_ERROR; } UnlockResource(hglMenuTemplate); FreeResource(hglMenuTemplate); return TRUE; DONE_ERROR: UnlockResource(hglMenuTemplate); FreeResource(hglMenuTemplate); MYERROR; }
int CDialog::DoModal() { // can be constructed with a resource template or InitModalIndirect ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL || m_lpDialogTemplate != NULL); // load resource as necessary LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate; HGLOBAL hDialogTemplate = m_hDialogTemplate; HINSTANCE hInst = AfxGetResourceHandle(); if (m_lpszTemplateName != NULL) { hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG); HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG); hDialogTemplate = LoadResource(hInst, hResource); } if (hDialogTemplate != NULL) lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate); // return -1 in case of failure to load the dialog template resource if (lpDialogTemplate == NULL) return -1; // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); bEnableParent = TRUE; } TRY { // create modeless dialog AfxHookWindowCreate(this); if (CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), hInst)) { if (m_nFlags & WF_CONTINUEMODAL) { // enter modal loop DWORD dwFlags = MLF_SHOWONIDLE; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } // hide the window before enabling the parent, etc. if (m_hWnd != NULL) SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW| SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER); } } CATCH_ALL(e) { DELETE_EXCEPTION(e); m_nModalResult = -1; } END_CATCH_ALL if (bEnableParent) ::EnableWindow(hWndParent, TRUE); if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd) ::SetActiveWindow(hWndParent); // destroy modal window DestroyWindow(); PostModal(); // unlock/free resources as necessary if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL) UnlockResource(hDialogTemplate); if (m_lpszTemplateName != NULL) FreeResource(hDialogTemplate); return m_nModalResult; }
BOOL CResModule::ExtractAccelerator(UINT nID) { HRSRC hrsrc = FindResource(m_hResDll, MAKEINTRESOURCE(nID), RT_ACCELERATOR); HGLOBAL hglAccTable; WORD fFlags, wAnsi, wID; const WORD* p; bool bEnd(false); if (!hrsrc) MYERROR; hglAccTable = LoadResource(m_hResDll, hrsrc); if (!hglAccTable) goto DONE_ERROR; p = (const WORD*)LockResource(hglAccTable); if (p == NULL) MYERROR; /* struct ACCELTABLEENTRY { WORD fFlags; FVIRTKEY, FSHIFT, FCONTROL, FALT, 0x80 - Last in a table WORD wAnsi; ANSI character WORD wId; Keyboard accelerator passed to windows WORD padding; # bytes added to ensure aligned to DWORD boundary }; */ do { fFlags = GET_WORD(p); p++; wAnsi = GET_WORD(p); p++; wID = GET_WORD(p); p++; p++; // Skip over padding if ((fFlags & 0x80) == 0x80) { // 0x80 bEnd = true; } if ((wAnsi < 0x30) || (wAnsi > 0x5A) || (wAnsi >= 0x3A && wAnsi <= 0x40)) continue; TCHAR * pBuf = new TCHAR[1024]; SecureZeroMemory(pBuf, 1024 * sizeof(TCHAR)); // include the menu ID in the msgid to make sure that 'duplicate' // accelerator keys are listed in the po-file. // without this, we would get entries like this: //#. Accelerator Entry for Menu ID:32809; '&Filter' //#. Accelerator Entry for Menu ID:57636; '&Find' //#: Corresponding Menu ID:32771; '&Find' //msgid "V C +F" //msgstr "" // // Since "filter" and "find" are most likely translated to words starting // with different letters, we need to have a separate accelerator entry // for each of those _stprintf(pBuf, _T("ID:%d:"), wID); // EXACTLY 5 characters long "ACS+X" // V = Virtual key (or blank if not used) // A = Alt key (or blank if not used) // C = Ctrl key (or blank if not used) // S = Shift key (or blank if not used) // X = upper case character // e.g. "V CS+Q" == Ctrl + Shift + 'Q' if ((fFlags & FVIRTKEY) == FVIRTKEY) // 0x01 _tcscat(pBuf, _T("V")); else _tcscat(pBuf, _T(" ")); if ((fFlags & FALT) == FALT) // 0x10 _tcscat(pBuf, _T("A")); else _tcscat(pBuf, _T(" ")); if ((fFlags & FCONTROL) == FCONTROL) // 0x08 _tcscat(pBuf, _T("C")); else _tcscat(pBuf, _T(" ")); if ((fFlags & FSHIFT) == FSHIFT) // 0x04 _tcscat(pBuf, _T("S")); else _tcscat(pBuf, _T(" ")); _stprintf(pBuf, _T("%s+%c"), pBuf, wAnsi); std::wstring wstr = std::wstring(pBuf); RESOURCEENTRY AKey_entry = m_StringEntries[wstr]; TCHAR szTempBuf[1024]; SecureZeroMemory(szTempBuf, 1024 * sizeof(TCHAR)); std::wstring wmenu = _T(""); pME_iter = m_MenuEntries.find(wID); if (pME_iter != m_MenuEntries.end()) { wmenu = pME_iter->second.msgstr; } _stprintf(szTempBuf, _T("#. Accelerator Entry for Menu ID:%d; '%s'"), wID, wmenu.c_str()); AKey_entry.automaticcomments.push_back(std::wstring(szTempBuf)); m_StringEntries[wstr] = AKey_entry; delete [] pBuf; } while (!bEnd); UnlockResource(hglAccTable); FreeResource(hglAccTable); return TRUE; DONE_ERROR: UnlockResource(hglAccTable); FreeResource(hglAccTable); MYERROR; }
static bool InstallCopyFiles() { FileInfo fileInfos[32]; HRSRC resSrc = FindResource(ghinst, MAKEINTRESOURCE(1), RT_RCDATA); CrashIf(!resSrc); HGLOBAL res = LoadResource(NULL, resSrc); CrashIf(!res); const uint8_t *data = (const uint8_t*)LockResource(res); DWORD dataSize = SizeofResource(NULL, resSrc); // extract all payload files one by one (transacted, if possible) FileTransaction trans; const int32_t *idata = (const int32_t*)data; int32_t fileCount = *idata++; CrashIf(fileCount >= dimof(fileInfos)); int32_t off = 0; for (int32_t i = 0; i < fileCount; i++) { fileInfos[i].off = off; fileInfos[i].sizeUncompressed = *idata++; fileInfos[i].sizeCompressed = *idata++; off += fileInfos[i].sizeCompressed; data = (const uint8_t*)idata; fileInfos[i].name = (const char*)data; while (*data) { ++data; } ++data; idata = (const int32_t*)data; } uint8_t *dst; for (int32_t i = 0; i < fileCount; i++) { ScopedMem<WCHAR> filepathT(str::conv::FromUtf8(fileInfos[i].name)); int32_t srcLen = fileInfos[i].sizeCompressed; off = fileInfos[i].off; const uint8_t *src = data + off; unsigned dstLen; dst = decodeLZMA((uint8_t*)src, (unsigned)srcLen, &dstLen); CrashIf(dstLen != (unsigned)fileInfos[i].sizeUncompressed); ScopedMem<WCHAR> extpath(path::Join(gGlobalData.installDir, path::GetBaseName(filepathT))); bool ok = trans.WriteAll(extpath, dst, dstLen); if (!ok) { ScopedMem<WCHAR> msg(str::Format(_TR("Couldn't write %s to disk"), filepathT)); NotifyFailed(msg); goto Error; } free(dst); // set modification time to original value //FILETIME ftModified = archive.GetFileTime(filepathT); //trans.SetModificationTime(extpath, ftModified); ProgressStep(); } UnlockResource(res); return trans.Commit(); Error: UnlockResource(res); return false; }
int CWebInterfaceDlg::DoModal() { ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL || m_lpDialogTemplate != NULL); LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate; HGLOBAL hDialogTemplate = m_hDialogTemplate; HINSTANCE hInst = AfxGetResourceHandle(); if (m_lpszTemplateName != NULL) { hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG); HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG); hDialogTemplate = LoadResource(hInst, hResource); } if (hDialogTemplate != NULL) lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate); if (lpDialogTemplate == NULL) return -1; HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); bEnableParent = TRUE; } TRY { AfxHookWindowCreate(this); if (CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), hInst)) { if (m_nFlags & WF_CONTINUEMODAL) { DWORD dwFlags = 0; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } if (m_hWnd != NULL) SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW| SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER); } } CATCH_ALL(e) { DELETE_EXCEPTION(e); m_nModalResult = -1; } END_CATCH_ALL if (bEnableParent) ::EnableWindow(hWndParent, TRUE); if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd) ::SetActiveWindow(hWndParent); DestroyWindow(); PostModal(); if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL) UnlockResource(hDialogTemplate); if (m_lpszTemplateName != NULL) FreeResource(hDialogTemplate); return m_nModalResult; }
static bool LoadMind(const TCHAR* filename, int &line) { TCHAR* fullname = GetFullName(filename); HCURSOR newCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT)); HCURSOR oldCur = SetCursor(newCur); #ifdef DEBUG_LOAD_TIME unsigned __int64 t = __rdtsc(); #endif Mind* mind = new Mind(); line = -1; try { mind->Load(fullname); } catch (Mind::CorruptedMind c) { line = c.line; delete mind; if (fullname != filename) delete[] fullname; SetCursor(oldCur); return false; } catch (...) { delete mind; if (fullname != filename) delete[] fullname; SetCursor(oldCur); return false; } if (fullname != filename) delete[] fullname; #ifdef DEBUG_LOAD_TIME t = __rdtsc() - t; char dest[101]; mir_snprintf(dest, "%I64d ticks\n", t / 3200000); MessageBoxA(NULL, dest, NULL, 0); //exit(0); #endif SetCursor(oldCur); HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDR_SMILES), _T("SMILES")); if (!hRes) { delete mind; return false; } DWORD size = SizeofResource(hInst, hRes); if (!size) { delete mind; return false; } HGLOBAL hGlob = LoadResource(hInst, hRes); if (!hGlob) { delete mind; return false; } void *data = LockResource(hGlob); if (!data) { FreeResource(hGlob); delete mind; return false; } bool res = true; try { mind->LoadSmiles(data, size); } catch (...) { res = false; } UnlockResource(data); FreeResource(hGlob); if (!res) { delete mind; return false; } delete bot; bot = new TalkBot(*mind); delete mind; UpdateEngine(); return true; }
HWND CPagePanel::Create(HWND hWndParent) { _ASSERTE(m_hWnd == NULL); _AtlWinModule.AddCreateWndData(&m_thunk.cd, (CDialogImplBase*)this); HDC hDC = ::CreateIC("DISPLAY", NULL, NULL, NULL); int nLogPixelsY = ::GetDeviceCaps(hDC, LOGPIXELSY); ::DeleteDC(hDC); HINSTANCE hInst = _AtlBaseModule.GetResourceInstance(); LPCSTR idDialog = MAKEINTRESOURCE(IDD); HWND hWnd = NULL; if (nLogPixelsY > 96) { do // A convenient block we can break out of { HRSRC hResource = ::FindResource(hInst, idDialog, RT_DIALOG); if (!hResource) break; HGLOBAL hTemplate = ::LoadResource(hInst, hResource); if (!hTemplate) break; LPVOID pTemplate = ::LockResource(hTemplate); if (pTemplate) { int nSize = ::SizeofResource(hInst, hResource); LPVOID pNewTemplate = (DLGTEMPLATE*)malloc(nSize); if (pNewTemplate) { memcpy(pNewTemplate, pTemplate, nSize); WORD* pwPointsize = (WORD*)_DialogSizeHelper::GetFontSizeField((DLGTEMPLATE*)pNewTemplate); if (pwPointsize) *pwPointsize = ((*pwPointsize * 96) / nLogPixelsY); hWnd = ::CreateDialogIndirectParam(hInst, (DLGTEMPLATE*)pNewTemplate, hWndParent, (DLGPROC)CPagePanel::StartDialogProc, NULL); free(pNewTemplate); } UnlockResource(hTemplate); } ::FreeResource(hTemplate); } while (0); } if (!hWnd) hWnd = ::CreateDialogParam(hInst, idDialog, hWndParent, (DLGPROC)CPagePanel::StartDialogProc, NULL); m_ToolTip.Create(m_hWnd); m_ToolTip.Activate(true); DWORD c = m_ToolTip.GetDelayTime(TTDT_AUTOPOP); // How long if remains stationary DWORD a = m_ToolTip.GetDelayTime(TTDT_INITIAL); // before coming up DWORD b = m_ToolTip.GetDelayTime(TTDT_RESHOW); // between reappearances //j m_ToolTip.SetDelayTime(TTDT_INITIAL, 250); AddToolTip(IDC_DOC_PAGENAV); AddToolTip(IDC_DOC_PAGEADD); AddToolTip(IDC_DOC_PAGEDELETE); AddToolTip(IDC_DOC_PAGEPREV); AddToolTip(IDC_DOC_PAGENEXT); AddToolTip(IDC_BTN_CARD, IDS_BTN_VIEWCARD); AddToolTip(IDC_BTN_ENVELOPE, IDS_BTN_VIEWENV); _ASSERTE(m_hWnd == hWnd); return hWnd; }
BOOL CRRECToolbar::Create( CWnd* parent, CRect& rc ) /* ============================================================ Function : CRRECToolbar::Create Description : Creates the toolbar control Access : Public Return : BOOL - "TRUE" if success Parameters : CWnd* parent - Parent editor CRect& rc - Rectangle to place toolbar in. Usage : Called from the parent editor ============================================================*/ { BOOL result = FALSE; HINSTANCE hInstance = AfxFindResourceHandle( MAKEINTRESOURCE( TOOLBAR_CONTROL ), RT_TOOLBAR ); if(!hInstance) return FALSE; HRSRC hRsrc = ::FindResource( hInstance, MAKEINTRESOURCE( TOOLBAR_CONTROL ), RT_TOOLBAR ); if( !hRsrc ) return FALSE; HGLOBAL hGlobal = LoadResource( hInstance, hRsrc ); if (hGlobal == NULL) return FALSE; CToolBarData* pData = ( CToolBarData* ) LockResource( hGlobal ); if (pData == NULL) return FALSE; ASSERT( pData->wVersion == 1 ); TBBUTTON tb, tbSep; memset ( &tb, 0, sizeof( tb ) ); memset ( &tbSep, 0, sizeof( tbSep ) ); result = CToolBarCtrl::Create(WS_VISIBLE|WS_CHILD, rc, parent, TOOLBAR_CONTROL); if( result ) { SetButtonStructSize( sizeof ( tb ) ); CSize sz ( pData->wWidth, pData->wHeight ); SetBitmapSize( sz ); sz.cx += 4; sz.cy += 4; SetButtonSize( sz ); // Loop through adding buttons. tb.fsState = TBSTATE_ENABLED; tb.fsStyle = TBSTYLE_BUTTON; tb.iString = -1; tb.iBitmap = 0; tbSep.iString = -1; tbSep.fsStyle = TBSTYLE_SEP; for( WORD w = 0; w < pData->wItemCount; w++ ) { if ( pData->items()[ w ] == 0 ) AddButtons( 1, &tbSep ); else { tb.idCommand = pData->items()[ w ]; AddButtons( 1, &tb ); tb.iBitmap++; } } HBITMAP hBitmap = (HBITMAP) ::LoadImage( hInstance, MAKEINTRESOURCE( TOOLBAR_CONTROL ), IMAGE_BITMAP, 0,0, LR_LOADMAP3DCOLORS ); if( !hBitmap ) return FALSE; BITMAP bm; memset( &bm, 0, sizeof ( bm ) ); ::GetObject( hBitmap, sizeof ( bm ), &bm ); AddBitmap( bm.bmWidth / pData->wWidth, CBitmap::FromHandle ( hBitmap ) ); UnlockResource( hGlobal ); FreeResource( hGlobal ); ///////////////////////////////////// // Map in combo boxes // CRect rect; TBBUTTONINFO tbi; tbi.cbSize = sizeof( TBBUTTONINFO ); tbi.cx = FONT_COMBO_WIDTH; tbi.dwMask = TBIF_SIZE | 0x80000000; // By index SetButtonInfo( FONT_NAME_POS, &tbi ); GetItemRect( FONT_NAME_POS, &rect ); rect.bottom += COMBO_HEIGHT; // The font name combo if( m_font.Create( WS_CHILD | WS_VSCROLL | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWN | CBS_SORT | CBS_HASSTRINGS, rect, this, DROPDOWN_FONT ) ) { m_font.SetFont( CFont::FromHandle( ( HFONT ) ::GetStockObject( ANSI_VAR_FONT ) ) ); m_font.FillCombo(); tbi.cx = COMBO_WIDTH; SetButtonInfo( FONT_SIZE_POS, &tbi ); GetItemRect( FONT_SIZE_POS, &rect ); rect.bottom += COMBO_HEIGHT; // The font size combo if( m_size.Create( WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST | CBS_HASSTRINGS, rect, this, DROPDOWN_SIZE ) ) { m_size.SetFont( CFont::FromHandle( ( HFONT ) ::GetStockObject( ANSI_VAR_FONT ) ) ); m_size.FillCombo(); CString color; CString defaultText; CString customText; color.LoadString( STRING_COLOR ); defaultText.LoadString( STRING_DEFAULT ); customText.LoadString( STRING_CUSTOM ); tbi.cx = COLOR_WIDTH; SetButtonInfo( FONT_COLOR_POS, &tbi ); GetItemRect( FONT_COLOR_POS, &rect ); // The color picker if( m_color.Create( color, WS_VISIBLE| WS_CHILD, rect, this, BUTTON_COLOR ) ) { m_color.SetDefaultText( defaultText ); m_color.SetCustomText( customText ); m_color.SetSelectionMode( CP_MODE_TEXT ); m_color.SetBkColour( RGB( 255, 255, 255 ) ); m_color.SetFont( CFont::FromHandle( ( HFONT ) ::GetStockObject( ANSI_VAR_FONT ) ) ); result = TRUE; } } } } return result; }
CSize CPopupWnd::GetContentDlgSize( CDialog* pDlg, UINT nID ) { CSize sizeDlg; typedef struct { WORD dlgVer; WORD signature; DWORD helpID; DWORD exStyle; DWORD style; WORD cDlgItems; short x; short y; short cx; short cy; // 后面的属性不能直接用,要根据具体的情况分析,是变长结构 // ... } DLGTEMPLATEEX; // LPCTSTR lpszName = MAKEINTRESOURCE( nID ); HINSTANCE hInstance = AfxFindResourceHandle( lpszName, RT_DIALOG ); HRSRC hResource = ::FindResource( hInstance, lpszName, RT_DIALOG ); HGLOBAL hTemplate = LoadResource( hInstance, hResource); DLGTEMPLATE* pTemplate; WORD *pDlgTemplateTemp = NULL; int nPageWidth = 0; int nPageHeight = 0; pTemplate = (DLGTEMPLATE*)(LPCDLGTEMPLATE)LockResource(hTemplate); // 判断是哪一种 dlg 模板 pDlgTemplateTemp = (WORD*)pTemplate; if ( pDlgTemplateTemp[1] == 0xFFFF ) { // 扩展模板 DLGTEMPLATEEX *pTemplateEx = (DLGTEMPLATEEX*)pTemplate; nPageWidth = pTemplateEx->cx; nPageHeight = pTemplateEx->cy; } else { nPageWidth = pTemplate->cx; nPageHeight = pTemplate->cy; } // UnlockResource(hTemplate); // dialog模板使用的是 dialog unit, 需要转换成 pixel unit CRect rectTemp( 0, 0, nPageWidth, nPageHeight); ::MapDialogRect( pDlg->GetSafeHwnd(), &rectTemp ); sizeDlg.cx = rectTemp.Width(); sizeDlg.cy = rectTemp.Height(); // return sizeDlg; }
BOOL ReplaceIconResource(LPSTR lpFileName, LPCTSTR lpName, UINT langId, LPICONDIR pIconDir, LPICONIMAGE* pIconImage) { BOOL res=true; HANDLE hFile3=NULL; LPMEMICONDIR lpInitGrpIconDir=new MEMICONDIR; //LPICONIMAGE pIconImage; HINSTANCE hUi; BYTE *test,*test1,*temp,*temp1; DWORD cbInit=0,cbOffsetDir=0,cbOffset=0,cbInitOffset=0; WORD cbRes=0; int i; hUi = LoadLibraryExA(lpFileName,NULL,DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); HRSRC hRsrc = FindResourceEx(hUi, RT_GROUP_ICON, lpName,langId); //nu stiu de ce returneaza 104 wtf??? //cbRes=SizeofResource( hUi, hRsrc ); HGLOBAL hGlobal = LoadResource( hUi, hRsrc ); test1 =(BYTE*) LockResource( hGlobal ); temp1=test1; // temp1=new BYTE[118]; // CopyMemory(temp1,test1,118); if (test1) { lpInitGrpIconDir->idReserved=(WORD)*test1; test1=test1+sizeof(WORD); lpInitGrpIconDir->idType=(WORD)*test1; test1=test1+sizeof(WORD); lpInitGrpIconDir->idCount=(WORD)*test1; test1=test1+sizeof(WORD); } else { lpInitGrpIconDir->idReserved=0; lpInitGrpIconDir->idType=1; lpInitGrpIconDir->idCount=0; } lpInitGrpIconDir->idEntries=new MEMICONDIRENTRY[lpInitGrpIconDir->idCount]; for(i=0;i<lpInitGrpIconDir->idCount;i++) { lpInitGrpIconDir->idEntries[i].bWidth=(BYTE)*test1; test1=test1+sizeof(BYTE); lpInitGrpIconDir->idEntries[i].bHeight=(BYTE)*test1; test1=test1+sizeof(BYTE); lpInitGrpIconDir->idEntries[i].bColorCount=(BYTE)*test1; test1=test1+sizeof(BYTE); lpInitGrpIconDir->idEntries[i].bReserved=(BYTE)*test1; test1=test1+sizeof(BYTE); lpInitGrpIconDir->idEntries[i].wPlanes=(WORD)*test1; test1=test1+sizeof(WORD); lpInitGrpIconDir->idEntries[i].wBitCount=(WORD)*test1; test1=test1+sizeof(WORD); //nu merge cu (DWORD)*test lpInitGrpIconDir->idEntries[i].dwBytesInRes=pIconDir->idEntries[i].dwBytesInRes; test1=test1+sizeof(DWORD); lpInitGrpIconDir->idEntries[i].nID=(WORD)*test1; test1=test1+sizeof(WORD); } // memcpy( lpInitGrpIconDir->idEntries, test, cbRes-3*sizeof(WORD) ); UnlockResource((HGLOBAL)test1); LPMEMICONDIR lpGrpIconDir=new MEMICONDIR; lpGrpIconDir->idReserved=pIconDir->idReserved; lpGrpIconDir->idType=pIconDir->idType; lpGrpIconDir->idCount=pIconDir->idCount; cbRes=3*sizeof(WORD)+lpGrpIconDir->idCount*sizeof(MEMICONDIRENTRY); test=new BYTE[cbRes]; temp=test; CopyMemory(test,&lpGrpIconDir->idReserved,sizeof(WORD)); test=test+sizeof(WORD); CopyMemory(test,&lpGrpIconDir->idType,sizeof(WORD)); test=test+sizeof(WORD); CopyMemory(test,&lpGrpIconDir->idCount,sizeof(WORD)); test=test+sizeof(WORD); lpGrpIconDir->idEntries=new MEMICONDIRENTRY[lpGrpIconDir->idCount]; for(i=0;i<lpGrpIconDir->idCount;i++) { lpGrpIconDir->idEntries[i].bWidth=pIconDir->idEntries[i].bWidth; CopyMemory(test,&lpGrpIconDir->idEntries[i].bWidth,sizeof(BYTE)); test=test+sizeof(BYTE); lpGrpIconDir->idEntries[i].bHeight=pIconDir->idEntries[i].bHeight; CopyMemory(test,&lpGrpIconDir->idEntries[i].bHeight,sizeof(BYTE)); test=test+sizeof(BYTE); lpGrpIconDir->idEntries[i].bColorCount=pIconDir->idEntries[i].bColorCount; CopyMemory(test,&lpGrpIconDir->idEntries[i].bColorCount,sizeof(BYTE)); test=test+sizeof(BYTE); lpGrpIconDir->idEntries[i].bReserved=pIconDir->idEntries[i].bReserved; CopyMemory(test,&lpGrpIconDir->idEntries[i].bReserved,sizeof(BYTE)); test=test+sizeof(BYTE); lpGrpIconDir->idEntries[i].wPlanes=pIconDir->idEntries[i].wPlanes; CopyMemory(test,&lpGrpIconDir->idEntries[i].wPlanes,sizeof(WORD)); test=test+sizeof(WORD); lpGrpIconDir->idEntries[i].wBitCount=pIconDir->idEntries[i].wBitCount; CopyMemory(test,&lpGrpIconDir->idEntries[i].wBitCount,sizeof(WORD)); test=test+sizeof(WORD); lpGrpIconDir->idEntries[i].dwBytesInRes=pIconDir->idEntries[i].dwBytesInRes; CopyMemory(test,&lpGrpIconDir->idEntries[i].dwBytesInRes,sizeof(DWORD)); test=test+sizeof(DWORD); if(i<lpInitGrpIconDir->idCount) //nu am depasit numarul initial de RT_ICON lpGrpIconDir->idEntries[i].nID=lpInitGrpIconDir->idEntries[i].nID; else { nMaxID++; lpGrpIconDir->idEntries[i].nID=i+1; //adaug noile ICO la sfarsitul RT_ICON-urilor } CopyMemory(test,&lpGrpIconDir->idEntries[i].nID,sizeof(WORD)); test=test+sizeof(WORD); } //offsetul de unde incep structurile ICONIMAGE cbInitOffset=3*sizeof(WORD)+lpGrpIconDir->idCount*sizeof(ICONDIRENTRY); cbOffset=cbInitOffset; //cbOffset=118 FreeLibrary(hUi); HANDLE hUpdate; // _chmod((char*)lpFileName,_S_IWRITE); hUpdate = BeginUpdateResourceA(lpFileName, FALSE); //false sa nu stearga resursele neupdated if(hUpdate==NULL) { QTextStream(stdout, QIODevice::WriteOnly) << "erreur BeginUpdateResource " << lpFileName << "\n"; res=false; } //aici e cu lang NEUTRAL //res=UpdateResource(hUpdate,RT_GROUP_ICON,MAKEINTRESOURCE(6000),langId,lpGrpIconDir,cbRes); res=UpdateResource(hUpdate,RT_GROUP_ICON,lpName,langId,temp,cbRes); if(res==false) QTextStream(stdout, QIODevice::WriteOnly) << "erreur UpdateResource RT_GROUP_ICON " << lpFileName << "\n"; for(i=0;i<lpGrpIconDir->idCount;i++) { res=UpdateResource(hUpdate,RT_ICON,MAKEINTRESOURCE(lpGrpIconDir->idEntries[i].nID),langId,pIconImage[i],lpGrpIconDir->idEntries[i].dwBytesInRes); if(res==false) QTextStream(stdout, QIODevice::WriteOnly) << "erreur UpdateResource RT_ICON " << lpFileName << "\n"; } for(i=lpGrpIconDir->idCount;i<lpInitGrpIconDir->idCount;++i) { res=UpdateResource(hUpdate,RT_ICON,MAKEINTRESOURCE(lpInitGrpIconDir->idEntries[i].nID),langId,NULL,0); if(res==false) QTextStream(stdout, QIODevice::WriteOnly) << "erreur to delete resource " << lpFileName << "\n"; } if(!EndUpdateResource(hUpdate,FALSE)) //false ->resource updates will take effect. QTextStream(stdout, QIODevice::WriteOnly) << "eroare EndUpdateResource" << lpFileName << "\n"; // FreeResource(hGlobal); delete[] lpGrpIconDir->idEntries; delete lpGrpIconDir; delete[] temp; return res; }
INT LcD3D_TextureLoadRscCustom(PDTX* pTexture, PDEV pDev, INT nResourceId, const char* sType , DWORD dColor , D3DXIMAGE_INFO* pSrcInf , DWORD Filter , DWORD MipFilter , D3DFORMAT d3Fmt , DWORD Pool) { HINSTANCE hInst = NULL; HRSRC hRsc = NULL; DWORD dwSize = 0; HGLOBAL hMem = NULL; LPVOID pMem = NULL; HRESULT hr; UINT uMip = D3DX_DEFAULT; if(D3DX_FILTER_NONE == Filter || D3DX_FILTER_NONE == MipFilter) uMip = 1; hInst = GetModuleHandle(NULL); hRsc = FindResource( hInst, MAKEINTRESOURCE(nResourceId), sType); if(NULL == hRsc) return -1; dwSize = SizeofResource(hInst,hRsc); if(0==dwSize) return -1; hMem = LoadResource(hInst, hRsc); if(NULL == hMem) return -1; pMem = LockResource(hMem); // 이것은 안된다... // HRESULT hr = D3DXCreateTextureFromResourceEx( // pDev // , NULL // , MAKEINTRESOURCE(IDR_PNG1) // , D3DX_DEFAULT // , D3DX_DEFAULT // , uMip // , 0 // , d3Fmt // , D3DPOOL_MANAGED // , Filter, MipFilter // , dColor, pSrcInf // , NULL // , &pTexture); // 이것으로 해야 한다. hr = D3DXCreateTextureFromFileInMemoryEx( pDev , pMem , dwSize , D3DX_DEFAULT , D3DX_DEFAULT , uMip , 0 , d3Fmt , (D3DPOOL)Pool , Filter, MipFilter , dColor, pSrcInf , NULL , pTexture); UnlockResource(hMem); FreeResource(hMem); if(FAILED(hr)) return -1; return 0; }
extern void CResizerInit(CResizer *cs, HINSTANCE hInst, HWND dlg, int iIDD) { BOOL bDialogEx = 0; /* set variables */ cs->inst = hInst; cs->IDD = iIDD; cs->hwnd = dlg; /* Get current point size information */ HDC hdcScreen = GetDC(NULL); if (!hdcScreen) { cs->dpi = 96; } else { cs->dpi = GetDeviceCaps(hdcScreen, LOGPIXELSX); ReleaseDC(NULL, hdcScreen); } helper::DLGTEMPLATEEX *lpDialogTemplate; if (!hInst) { } // hInst = AfxFindResourceHandle(IMAKEINTRESOURCE(IDD), RT_DIALOG); HRSRC hResource = ::FindResource(hInst, MAKEINTRESOURCE(cs->IDD), RT_DIALOG); HANDLE hDialogTemplate = LoadResource(hInst, hResource); lpDialogTemplate = (helper::DLGTEMPLATEEX *)LockResource(hDialogTemplate); bDialogEx = helper::IsDialogEx((const DLGTEMPLATE*) lpDialogTemplate); querydialogdata((LPCSTR)lpDialogTemplate, &cs->sDialogData); /* cs->sDialogData.style = lpDialogTemplate->style; cs->sDialogData.exStyle = lpDialogTemplate->exStyle; */ if ((cs->sDialogData.pt<0)||(cs->sDialogData.pt>32767)) { // I don't know what to do if it happens this way // this is a compromise solution: cs->sDialogData.pt = -cs->sDialogData.pt; cs->sDialogData.pt &= 0xFFFF; } cs->font=CreateFontW( -(int)(cs->sDialogData.pt*96.0/72.0 + 0.5), // negative makes it use "char size" 0, // logical average character width 0, // angle of escapement 0, // base-line orientation angle cs->sDialogData.weight, // weight cs->sDialogData.italic, // italic FALSE, // underline attribute flag FALSE, // strikeout attribute flag DEFAULT_CHARSET, // character set identifier OUT_DEFAULT_PRECIS, // output precision CLIP_DEFAULT_PRECIS,// clipping precision DEFAULT_QUALITY, // output quality DEFAULT_PITCH, // pitch and family cs->sDialogData.faceName // pointer to typeface name string ); cs->oldfont=(HFONT)::SendMessage(cs->hwnd, WM_GETFONT, 0, 0); SendMessage(cs->hwnd, WM_SETFONT, (LPARAM)cs->font, TRUE); /* Pick up all of the item ID's */ /* go through the Item ID's to resize them */ helper::DLGITEMTEMPLATEEX *itemE = (helper::DLGITEMTEMPLATEEX *)helper::FindFirstDlgItem((DLGTEMPLATE *)lpDialogTemplate); DLGITEMTEMPLATE *item = (DLGITEMTEMPLATE *) itemE; cs->jNtItems = 0; int jMax = helper::DlgTemplateItemCount((DLGTEMPLATE *)lpDialogTemplate); while (cs->jNtItems < jMax) { if (bDialogEx) { cs->asDI[cs->jNtItems].x = itemE->x; cs->asDI[cs->jNtItems].y = itemE->y; cs->asDI[cs->jNtItems].cx= itemE->cx; cs->asDI[cs->jNtItems].cy= itemE->cy; cs->asDI[cs->jNtItems].id= itemE->id; itemE=(helper::DLGITEMTEMPLATEEX *)helper::FindNextDlgItem((DLGITEMTEMPLATE *)itemE,TRUE); } else { cs->asDI[cs->jNtItems].x = item->x; cs->asDI[cs->jNtItems].y = item->y; cs->asDI[cs->jNtItems].cx= item->cx; cs->asDI[cs->jNtItems].cy= item->cy; cs->asDI[cs->jNtItems].id= item->id; cs->asDI[cs->jNtItems].uiFlags = 0; item = helper::FindNextDlgItem(item,FALSE); } cs->asDI[cs->jNtItems].uiFlags = 0; cs->jNtItems++; } UnlockResource(hDialogTemplate); FreeResource(hDialogTemplate); cs->x_factor = (double) 2; cs->y_factor = (double) 2; } /* CResizerInit */