From 55b9a1366e55c01d34aca79b58c1c45125408a35 Mon Sep 17 00:00:00 2001 From: gtwguo Date: Wed, 2 Aug 2023 11:13:52 +0800 Subject: [PATCH] Update UIBase.cpp load icon from file --- DuiLib/Core/UIBase.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/DuiLib/Core/UIBase.cpp b/DuiLib/Core/UIBase.cpp index 6eea5ad2..89d68570 100644 --- a/DuiLib/Core/UIBase.cpp +++ b/DuiLib/Core/UIBase.cpp @@ -193,7 +193,7 @@ bool CNotifyPump::LoopDispatch(TNotifyUI& msg) void CNotifyPump::NotifyPump(TNotifyUI& msg) { - ///遍历虚拟窗口 + ///閬嶅巻铏氭嫙绐楀彛 if( !msg.sVirtualWnd.IsEmpty() ){ for( int i = 0; i< m_VirtualWndMap.GetSize(); i++ ) { if( LPCTSTR key = m_VirtualWndMap.GetAt(i) ) { @@ -207,7 +207,7 @@ void CNotifyPump::NotifyPump(TNotifyUI& msg) } /// - //遍历主窗口 + //閬嶅巻涓荤獥鍙 LoopDispatch( msg ); } @@ -371,7 +371,7 @@ void CWindowWnd::CenterWindow() if (hWndCenter!=NULL) hWnd=hWndCenter; - // 处理多显示器模式下屏幕居中 + // 澶勭悊澶氭樉绀哄櫒妯″紡涓嬪睆骞曞眳涓 MONITORINFO oMonitor = {}; oMonitor.cbSize = sizeof(oMonitor); ::GetMonitorInfo(::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), &oMonitor); @@ -400,18 +400,38 @@ void CWindowWnd::CenterWindow() void CWindowWnd::SetIcon(UINT nRes) { HICON hIcon = (HICON)::LoadImage(CPaintManagerUI::GetInstance(), MAKEINTRESOURCE(nRes), IMAGE_ICON, - (::GetSystemMetrics(SM_CXICON) + 15) & ~15, (::GetSystemMetrics(SM_CYICON) + 15) & ~15, // 防止高DPI下图标模糊 + (::GetSystemMetrics(SM_CXICON) + 15) & ~15, (::GetSystemMetrics(SM_CYICON) + 15) & ~15, // 闃叉楂楧PI涓嬪浘鏍囨ā绯 LR_DEFAULTCOLOR); ASSERT(hIcon); ::SendMessage(m_hWnd, WM_SETICON, (WPARAM) TRUE, (LPARAM) hIcon); hIcon = (HICON)::LoadImage(CPaintManagerUI::GetInstance(), MAKEINTRESOURCE(nRes), IMAGE_ICON, - (::GetSystemMetrics(SM_CXICON) + 15) & ~15, (::GetSystemMetrics(SM_CYICON) + 15) & ~15, // 防止高DPI下图标模糊 + (::GetSystemMetrics(SM_CXICON) + 15) & ~15, (::GetSystemMetrics(SM_CYICON) + 15) & ~15, // 闃叉楂楧PI涓嬪浘鏍囨ā绯 LR_DEFAULTCOLOR); ASSERT(hIcon); ::SendMessage(m_hWnd, WM_SETICON, (WPARAM) FALSE, (LPARAM) hIcon); } +void CWindowWnd::SetIcon(LPCTSTR path) +{ + HINSTANCE instance = CPaintManagerUI::GetInstance(); + int cx = (::GetSystemMetrics(SM_CXICON) + 15) & ~15; + int cy = (::GetSystemMetrics(SM_CYICON) + 15) & ~15; + HICON hIcon = (HICON)::LoadImage(instance, path, IMAGE_ICON, + cx, cy, // 闃叉楂楧PI涓嬪浘鏍囨ā绯 + LR_LOADFROMFILE); + ASSERT(hIcon); + ::SendMessage(m_hWnd, WM_SETICON, (WPARAM) TRUE, (LPARAM) hIcon); + + cx = (::GetSystemMetrics(SM_CXICON) + 15) & ~15; + cy = (::GetSystemMetrics(SM_CYICON) + 15) & ~15; + hIcon = (HICON)::LoadImage(instance, path, IMAGE_ICON, + cx, cy, // 闃叉楂楧PI涓嬪浘鏍囨ā绯 + LR_LOADFROMFILE); + ASSERT(hIcon); + ::SendMessage(m_hWnd, WM_SETICON, (WPARAM) FALSE, (LPARAM) hIcon); +} + bool CWindowWnd::RegisterWindowClass() { WNDCLASS wc = { 0 };