project64/Source/Project64/UserInterface/WTLControls/wtl-BitmapPicture.cpp

95 lines
2.7 KiB
C++
Raw Normal View History

#include "stdafx.h"
2022-09-21 05:16:07 +00:00
#include "wtl-BitmapPicture.h"
CBitmapPicture::CBitmapPicture() :
2022-09-21 05:16:07 +00:00
m_hBitmap(nullptr),
m_nResourceID(-1),
m_ResourceIcon(false)
{
2022-09-21 05:16:07 +00:00
memset(&m_bmInfo, 0, sizeof(m_bmInfo));
m_BackgroundBrush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
}
2022-09-21 05:16:07 +00:00
LRESULT CBitmapPicture::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{
2022-09-21 05:16:07 +00:00
CPaintDC dc(m_hWnd);
CRect rect;
GetClientRect(&rect);
2022-09-21 05:16:07 +00:00
CBrush PaintBrush;
HBRUSH OldBrush = dc.SelectBrush(m_BackgroundBrush);
dc.PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
if (m_ResourceIcon)
{
CIcon hIcon = (HICON)::LoadImage(ModuleHelper::GetResourceInstance(), m_nResourceID > 0 ? MAKEINTRESOURCE(m_nResourceID) : m_strResourceName.c_str(), IMAGE_ICON, m_IconWidth, m_IconHeight, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
if (!hIcon.IsNull())
{
dc.DrawIconEx(0, 0, hIcon, rect.Width(), rect.Height(), 0, nullptr, DI_NORMAL);
}
}
else
{
CBitmap hBmp = (HBITMAP)::LoadImage(ModuleHelper::GetResourceInstance(), m_nResourceID > 0 ? MAKEINTRESOURCE(m_nResourceID) : m_strResourceName.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
BITMAP bm;
hBmp.GetBitmap(&bm);
CDC dcMem;
dcMem.CreateCompatibleDC(dc);
dcMem.SelectBitmap(hBmp);
dc.StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(), dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}
2022-09-21 05:16:07 +00:00
dc.SelectBrush(OldBrush);
return 0;
}
bool CBitmapPicture::SetIcon(LPCWSTR lpszResourceName, uint32_t nWidth, uint32_t nHeight)
{
2022-09-21 05:16:07 +00:00
CIcon hIcon = (HICON)::LoadImage(ModuleHelper::GetResourceInstance(), lpszResourceName, IMAGE_ICON, nWidth, nHeight, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
if (hIcon.IsNull())
{
return false;
}
ICONINFO IconInfo;
if (!hIcon.GetIconInfo(&IconInfo))
{
return false;
}
if (IS_INTRESOURCE(lpszResourceName))
{
2023-02-27 23:39:08 +00:00
m_nResourceID = (int)((LONG_PTR)lpszResourceName);
2022-09-21 05:16:07 +00:00
}
else
{
m_strResourceName = lpszResourceName;
}
m_ResourceIcon = true;
m_IconWidth = nWidth;
m_IconHeight = nHeight;
return true;
}
bool CBitmapPicture::SetBitmap(HBITMAP hBitmap)
{
2022-09-21 05:16:07 +00:00
m_hBitmap.Attach(hBitmap);
return ::GetObject(m_hBitmap, sizeof(BITMAP), &m_bmInfo) != 0;
}
void CBitmapPicture::SetBitmap(LPCWSTR lpszResourceName)
{
if (IS_INTRESOURCE(lpszResourceName))
{
2023-02-27 23:39:08 +00:00
m_nResourceID = (int)((LONG_PTR)lpszResourceName);
}
else
{
m_strResourceName = lpszResourceName;
}
m_ResourceIcon = false;
}
void CBitmapPicture::SetBackroundBrush(HBRUSH brush)
{
2022-09-21 05:16:07 +00:00
m_BackgroundBrush.Attach(brush);
}