Magic_Game/core/base/Resource.h

68 lines
2.1 KiB
C++

// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "macros.h"
namespace easy2d
{
// 资源
//
// Usage:
// Resource 用于获取可执行文件 (exe) 中的资源, 必须在构造函数中指定它的
// 资源类型和名称标识符。
// 例如, 一份音频资源的类型为 L"WAVE", 名称标识符为 IDR_WAVE_1, 那么可以这样指定该资源:
// Resource res(MAKEINTRESOURCE(IDR_WAVE_1), L"WAVE");
// 如果需要手动加载这份资源, 可以通过 Load 方法获取资源内容
// if (res.Load()) {
// LPVOID data = res.GetData();
// DWORD size = res.GetDataSize();
// }
// 了解资源的更多信息: https://docs.microsoft.com/en-us/windows/desktop/menurc/resources
//
class Resource
{
public:
Resource(
LPCWSTR name, /* 资源名称 */
LPCWSTR type /* 资源类型 */
);
bool Load();
LPCWSTR GetName() const;
LPCWSTR GetType() const;
LPVOID GetData() const;
DWORD GetDataSize() const;
size_t GetHashCode() const;
private:
bool loaded_;
LPCWSTR name_;
LPCWSTR type_;
LPVOID data_;
DWORD data_size_;
};
}