add Window::SetIcon

This commit is contained in:
Nomango 2020-06-22 21:38:50 +08:00
parent 061bbfeca0
commit 8014857fbc
2 changed files with 23 additions and 9 deletions

View File

@ -163,9 +163,9 @@ public:
/** /**
* \~chinese * \~chinese
* @brief ÉèÖô°¿Úͼ±ê * @brief ÉèÖô°¿Úͼ±ê
* @param icon_resource ͼ±ê×ÊÔ´ID * @param icon ͼ±ê
*/ */
virtual void SetIcon(uint32_t icon_resource) = 0; virtual void SetIcon(Icon icon) = 0;
/** /**
* \~chinese * \~chinese

View File

@ -53,7 +53,7 @@ public:
void SetTitle(const String& title) override; void SetTitle(const String& title) override;
void SetIcon(uint32_t icon_resource) override; void SetIcon(Icon icon) override;
void SetMinimumSize(uint32_t width, uint32_t height) override; void SetMinimumSize(uint32_t width, uint32_t height) override;
@ -317,16 +317,30 @@ void WindowWin32Impl::SetTitle(const String& title)
::SetWindowTextA(handle_, title.c_str()); ::SetWindowTextA(handle_, title.c_str());
} }
void WindowWin32Impl::SetIcon(uint32_t icon_resource) void WindowWin32Impl::SetIcon(Icon icon)
{ {
KGE_ASSERT(handle_); KGE_ASSERT(handle_);
HINSTANCE hinstance = ::GetModuleHandle(nullptr); HICON hicon = NULL;
HICON icon = (HICON)::LoadImage(hinstance, MAKEINTRESOURCE(icon_resource), IMAGE_ICON, 0, 0, if (icon.resource_id != 0 && IS_INTRESOURCE(icon.resource_id))
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); {
HINSTANCE hinstance = ::GetModuleHandle(nullptr);
::SendMessage(handle_, WM_SETICON, ICON_BIG, (LPARAM)icon); hicon = (HICON)::LoadImage(hinstance, MAKEINTRESOURCE(icon.resource_id), IMAGE_ICON, 0, 0,
::SendMessage(handle_, WM_SETICON, ICON_SMALL, (LPARAM)icon); LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
}
else
{
String full_path = FileSystem::GetInstance().GetFullPathForFile(icon.file_path);
if (!full_path.empty())
{
hicon = (HICON)::LoadImageA(NULL, full_path.c_str(), IMAGE_ICON, 0, 0,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
}
}
::SendMessage(handle_, WM_SETICON, ICON_BIG, (LPARAM)hicon);
::SendMessage(handle_, WM_SETICON, ICON_SMALL, (LPARAM)hicon);
} }
void WindowWin32Impl::SetMinimumSize(uint32_t width, uint32_t height) void WindowWin32Impl::SetMinimumSize(uint32_t width, uint32_t height)