add Icon
This commit is contained in:
parent
0651cd1f74
commit
6cf6139d25
|
|
@ -43,7 +43,7 @@ struct Settings
|
|||
uint32_t width; ///< 窗口宽度
|
||||
uint32_t height; ///< 窗口高度
|
||||
String title; ///< 窗口标题
|
||||
uint32_t icon; ///< ´°¿Úͼ±ê
|
||||
Icon icon; ///< ´°¿Úͼ±ê
|
||||
bool resizable; ///< 窗口大小可调整
|
||||
bool fullscreen; ///< 窗口全屏
|
||||
Color bg_color; ///< 窗口背景色
|
||||
|
|
|
|||
|
|
@ -56,6 +56,31 @@ struct Resolution
|
|||
uint32_t refresh_rate; ///< 刷新率
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 图标
|
||||
*/
|
||||
struct Icon
|
||||
{
|
||||
Icon() = default;
|
||||
|
||||
Icon(const String& file_path)
|
||||
: file_path(file_path)
|
||||
{
|
||||
}
|
||||
|
||||
String file_path; ///< 文件路径
|
||||
|
||||
#if defined(KGE_PLATFORM_WINDOWS)
|
||||
uint32_t resource_id = 0; ///< 资源ID,仅在windows上生效
|
||||
|
||||
Icon(uint32_t resource_id)
|
||||
: resource_id(resource_id)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
#if defined(KGE_PLATFORM_WINDOWS)
|
||||
typedef HWND WindowHandle;
|
||||
|
|
@ -79,7 +104,7 @@ public:
|
|||
* @param resizable 窗口大小可拉伸
|
||||
* @throw kiwano::SystemError 窗口创建失败时抛出
|
||||
*/
|
||||
static WindowPtr Create(const String& title, uint32_t width, uint32_t height, uint32_t icon = 0,
|
||||
static WindowPtr Create(const String& title, uint32_t width, uint32_t height, Icon icon = Icon(),
|
||||
bool resizable = false, bool fullscreen = false);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
virtual ~WindowWin32Impl();
|
||||
|
||||
void Init(const String& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable, bool fullscreen);
|
||||
void Init(const String& title, uint32_t width, uint32_t height, Icon icon, bool resizable, bool fullscreen);
|
||||
|
||||
void SetTitle(const String& title) override;
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ private:
|
|||
std::array<KeyCode, 256> key_map_;
|
||||
};
|
||||
|
||||
WindowPtr Window::Create(const String& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable,
|
||||
WindowPtr Window::Create(const String& title, uint32_t width, uint32_t height, Icon icon, bool resizable,
|
||||
bool fullscreen)
|
||||
{
|
||||
WindowWin32ImplPtr ptr = memory::New<WindowWin32Impl>();
|
||||
|
|
@ -205,7 +205,7 @@ WindowWin32Impl::~WindowWin32Impl()
|
|||
::timeEndPeriod(0);
|
||||
}
|
||||
|
||||
void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable,
|
||||
void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, Icon icon, bool resizable,
|
||||
bool fullscreen)
|
||||
{
|
||||
HINSTANCE hinst = GetModuleHandle(nullptr);
|
||||
|
|
@ -222,11 +222,16 @@ void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height,
|
|||
wcex.lpszMenuName = nullptr;
|
||||
wcex.hCursor = ::LoadCursor(hinst, IDC_ARROW);
|
||||
|
||||
if (icon)
|
||||
if (icon.resource_id != 0 && IS_INTRESOURCE(icon.resource_id))
|
||||
{
|
||||
wcex.hIcon = (HICON)::LoadImage(hinst, MAKEINTRESOURCE(icon), IMAGE_ICON, 0, 0,
|
||||
wcex.hIcon = (HICON)::LoadImage(hinst, MAKEINTRESOURCE(icon.resource_id), IMAGE_ICON, 0, 0,
|
||||
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
|
||||
}
|
||||
else if (!icon.file_path.empty())
|
||||
{
|
||||
wcex.hIcon = (HICON)::LoadImageA(NULL, icon.file_path.c_str(), IMAGE_ICON, 0, 0,
|
||||
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
|
||||
}
|
||||
|
||||
::RegisterClassExA(&wcex);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue