void FreeResourceManager(ResourceManager resourceManager) { std::map<std::string, ResourceHandle>::iterator itrBegin = resourceManager->resources.begin(); std::map<std::string, ResourceHandle>::iterator itrEnd = resourceManager->resources.end(); for (; itrBegin != itrEnd; ++itrBegin) { FreeResourceHandle(resourceManager, itrBegin->second); } delete(resourceManager); }
void AddResource(ResourceManager resourceManager, std::string identifier, ResourceType resourceType) { ResourceHandle resourceHandle = CreateResourceHandle(resourceType); switch (resourceType) { case TEXTURE: { std::string strId = resourceManager->assetBaseDir + identifier; resourceHandle->textureRes->texture = IMG_LoadTexture(resourceManager->renderer, strId.c_str()); if(!resourceHandle->textureRes->texture) { LOGE("Unable to load resource: %s\n", strId.c_str()); FreeResourceHandle(resourceManager, resourceHandle); assert(0); } resourceHandle->textureRes->name = identifier; } break; case TMX_MAP: { std::string strId = resourceManager->assetBaseDir + identifier; resourceHandle->tmxMapResource->map.ParseFile(strId); break; } case ENTITY: { std::string strId = resourceManager->assetBaseDir + identifier; SDL_RWops * file = SDL_RWFromFile (strId.c_str(), "rb"); if (!file) { assert(0); } int fileSize = file->size(file); if (fileSize <= 0) { assert(0); } char* fileText = new char[fileSize + 1]; fileText[fileSize] = 0; file->read(file, fileText, 1, fileSize); file->close(file); std::string text(fileText, fileText+fileSize); delete [] fileText; resourceHandle->entityTemplateResource->xml.Parse(text.c_str()); break; } default: assert(0); } resourceManager->resources[identifier] = resourceHandle; }
//--------------------------------------------------------------------------------------- int DisplayMenu(HWND hWnd) { int nID = 0; HMENU hMenu = CreatePopupMenu(); if(hMenu) { HMODULE hMod = GetResourceHandle(); if(hMod) { TCHAR szBuf[MAX_PATH] = _T(""); LoadString(hMod, IDS_MNU_LAUNCH, szBuf, MAX_PATH); AppendMenu(hMenu, MF_STRING, 1, szBuf); if(IsServiceRunning()) { LoadString(hMod, IDS_MNU_STOP, szBuf, MAX_PATH); AppendMenu(hMenu, MF_STRING, 2, szBuf); } else { LoadString(hMod, IDS_MNU_START, szBuf, MAX_PATH); AppendMenu(hMenu, MF_STRING, 2, szBuf); } LoadString(hMod, IDS_MNU_ABOUT, szBuf, MAX_PATH); AppendMenu(hMenu, MF_STRING, 3, szBuf); AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); LoadString(hMod, IDS_MNU_EXIT, szBuf, MAX_PATH); AppendMenu(hMenu, MF_STRING, 4, szBuf); FreeResourceHandle(hMod); } POINT pt = {0}; GetCursorPos (&pt); SetMenuDefaultItem(hMenu, 0, TRUE); nID = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL); DestroyMenu(hMenu); } return nID; }
//--------------------------------------------------------------------------------------- int DisplayAbout(HWND hWnd) { HMODULE hMod = GetResourceHandle(); if(hMod) { TCHAR szTitle[MAX_PATH] = _T(""); LoadString(hMod, IDS_APP_NAME, szTitle, MAX_PATH); const int BUF_SIZE = MAX_PATH * 2; TCHAR szMsg[BUF_SIZE] = _T(""); LoadString(hMod, IDS_APP_ABOUT, szMsg, BUF_SIZE); MessageBox(hWnd, szMsg, szTitle, MB_ICONINFORMATION | MB_OK); FreeResourceHandle(hMod); } return 0; }
//--------------------------------------------------------------------------------------- LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { LRESULT lr = 0; PNOTIFYICONDATA pTrayIcon = (PNOTIFYICONDATA)malloc(sizeof(NOTIFYICONDATA)); if(pTrayIcon) { ZeroMemory(pTrayIcon, sizeof(NOTIFYICONDATA)); HMODULE hMod = LoadLibrary(_T("shell32.dll")); if(hMod) { FNDllGetVersion pfnDllGetVersion = (FNDllGetVersion)GetProcAddress(hMod, "DllGetVersion"); if(pfnDllGetVersion) { DLLVERSIONINFO VerInfo = {0}; VerInfo.cbSize = sizeof(VerInfo); pfnDllGetVersion(&VerInfo); if(VerInfo.dwMajorVersion == 6) { if(VerInfo.dwBuildNumber > 6) pTrayIcon->cbSize = sizeof(NOTIFYICONDATA); else pTrayIcon->cbSize = NOTIFYICONDATA_V3_SIZE; pTrayIcon->uVersion = NOTIFYICON_VERSION_4; } else if(VerInfo.dwMajorVersion == 5) { pTrayIcon->cbSize = NOTIFYICONDATA_V2_SIZE; pTrayIcon->uVersion = NOTIFYICON_VERSION; } else { pTrayIcon->cbSize = NOTIFYICONDATA_V1_SIZE; } } FreeLibrary(hMod); hMod = NULL; } pTrayIcon->hWnd = hWnd; pTrayIcon->uFlags = NIF_INFO | NIF_TIP | NIF_ICON | NIF_MESSAGE; pTrayIcon->dwInfoFlags = NIIF_USER; pTrayIcon->uCallbackMessage = WM_TRAY; pTrayIcon->uTimeout = 10000; pTrayIcon->hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_OPENNMS_TRAY), IMAGE_ICON, 0, 0, 0); hMod = GetResourceHandle(); if(hMod) { TCHAR szBuf[MAX_PATH] = _T(""); LoadString(hMod, IDS_TRAY_TIP, szBuf, MAX_PATH); _tcsncpy_s(pTrayIcon->szTip, ARRAYSIZE(pTrayIcon->szTip), szBuf, _TRUNCATE); LoadString(hMod, IDS_TRAY_INFOTITLE, szBuf, MAX_PATH); _tcsncpy_s(pTrayIcon->szInfoTitle, ARRAYSIZE(pTrayIcon->szInfoTitle), szBuf, _TRUNCATE); LoadString(hMod, IDS_TRAY_INFOTEXT, szBuf, MAX_PATH); _tcsncpy_s(pTrayIcon->szInfo, ARRAYSIZE(pTrayIcon->szInfo), szBuf, _TRUNCATE); FreeResourceHandle(hMod); } Sleep(5000); Shell_NotifyIcon(NIM_ADD, pTrayIcon); SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)pTrayIcon); } return lr; }