1.窗口基类:见介绍
顺便贴下出来,留底。
.h
1 class WindowImplBase : public CWindowWnd, public INotifyUI, public IMessageFilterUI, public IDialogBuilderCallback, public SkinChangedReceiver 2 { 3 public: 4 WindowImplBase(); 5 virtual ~WindowImplBase(); 6 7 virtual void OnFinalMessage(HWND hWnd); 8 9 virtual void Init(); 10 11 virtual CControlUI* CreateControl(LPCTSTR pstrClass); 12 13 virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled); 14 15 virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 16 17 virtual LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 18 19 virtual LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 20 21 virtual LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 22 23 virtual LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 24 25 virtual LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 26 27 virtual LRESULT OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 28 29 virtual LRESULT OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 30 31 virtual LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 32 33 virtual LRESULT OnMoving(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 34 35 virtual LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 36 37 virtual LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 38 39 virtual LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 40 41 virtual LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 42 43 virtual LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 44 45 virtual LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 46 47 virtual LRESULT OnNCLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 48 49 virtual LRESULT OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 50 51 virtual LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 52 53 virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); 54 55 virtual LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 56 57 protected: 58 virtual tString GetSkinFolder(); 59 virtual tString GetSkinFile() = 0; 60 61 virtual LRESULT ResponseDefaultKeyEvent(WPARAM wParam, bool& bHandled); 62 63 protected: 64 CPaintManagerUI paint_manager_; 65 66 };
.cpp
1 WindowImplBase::WindowImplBase() 2 {} 3 4 WindowImplBase::~WindowImplBase() 5 {} 6 7 CControlUI* WindowImplBase::CreateControl(LPCTSTR pstrClass) 8 { 9 return NULL; 10 } 11 12 void WindowImplBase::OnFinalMessage(HWND /*hWnd*/) 13 { 14 paint_manager_.RemovePreMessageFilter(this); 15 paint_manager_.RemoveNotifier(this); 16 paint_manager_.ReapObjects(paint_manager_.GetRoot()); 17 } 18 19 void WindowImplBase::Init() 20 {} 21 22 LRESULT WindowImplBase::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 23 { 24 bHandled = FALSE; 25 return 0; 26 } 27 28 LRESULT WindowImplBase::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 29 { 30 bHandled = FALSE; 31 return 0; 32 } 33 34 #if defined(WIN32) && !defined(UNDER_CE) 35 LRESULT WindowImplBase::OnNcActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) 36 { 37 if( ::IsIconic(*this) ) bHandled = FALSE; 38 return (wParam == 0) ? TRUE : FALSE; 39 } 40 41 LRESULT WindowImplBase::OnNcCalcSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) 42 { 43 return 0; 44 } 45 46 LRESULT WindowImplBase::OnNcPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) 47 { 48 return 0; 49 } 50 51 LRESULT WindowImplBase::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 52 { 53 POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); 54 ::ScreenToClient(*this, &pt); 55 56 RECT rcClient; 57 ::GetClientRect(*this, &rcClient); 58 59 //if( !::IsZoomed(*this) ) { 60 // RECT rcSizeBox = paint_manager_.GetSizeBox(); 61 // if( pt.y < rcClient.top + rcSizeBox.top ) { 62 // if( pt.x < rcClient.left + rcSizeBox.left ) return HTTOPLEFT; 63 // if( pt.x > rcClient.right - rcSizeBox.right ) return HTTOPRIGHT; 64 // return HTTOP; 65 // } 66 // else if( pt.y > rcClient.bottom - rcSizeBox.bottom ) { 67 // if( pt.x < rcClient.left + rcSizeBox.left ) return HTBOTTOMLEFT; 68 // if( pt.x > rcClient.right - rcSizeBox.right ) return HTBOTTOMRIGHT; 69 // return HTBOTTOM; 70 // } 71 // if( pt.x < rcClient.left + rcSizeBox.left ) return HTLEFT; 72 // if( pt.x > rcClient.right - rcSizeBox.right ) return HTRIGHT; 73 //} 74 75 RECT rcCaption = paint_manager_.GetCaptionRect(); 76 if( pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right 77 && pt.y >= rcCaption.top && pt.y < rcCaption.bottom ) { 78 CControlUI* pControl = static_cast<CControlUI*>(paint_manager_.FindControl(pt)); 79 if( pControl && _tcsicmp(pControl->GetClass(), _T("ButtonUI")) != 0 && 80 _tcsicmp(pControl->GetClass(), _T("OptionUI")) != 0 ) 81 return HTCAPTION; 82 } 83 84 return HTCLIENT; 85 } 86 87 LRESULT WindowImplBase::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 88 { 89 MONITORINFO oMonitor = {}; 90 oMonitor.cbSize = sizeof(oMonitor); 91 ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); 92 CRect rcWork = oMonitor.rcWork; 93 rcWork.Offset(-rcWork.left, -rcWork.top); 94 95 LPMINMAXINFO lpMMI = (LPMINMAXINFO) lParam; 96 lpMMI->ptMaxPosition.x = rcWork.left; 97 lpMMI->ptMaxPosition.y = rcWork.top; 98 lpMMI->ptMaxSize.x = rcWork.right; 99 lpMMI->ptMaxSize.y = rcWork.bottom; 100 101 bHandled = FALSE; 102 return 0; 103 } 104 105 LRESULT WindowImplBase::OnMouseWheel(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 106 { 107 bHandled = FALSE; 108 return 0; 109 } 110 #endif 111 112 LRESULT WindowImplBase::OnSetFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 113 { 114 bHandled = FALSE; 115 return 0; 116 } 117 118 LRESULT WindowImplBase::OnLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 119 { 120 bHandled = FALSE; 121 return 0; 122 } 123 124 LRESULT WindowImplBase::OnNCLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 125 { 126 bHandled = FALSE; 127 return 0; 128 } 129 130 LRESULT WindowImplBase::OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 131 { 132 bHandled = FALSE; 133 return 0; 134 } 135 136 LRESULT WindowImplBase::OnLButtonUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 137 { 138 bHandled = FALSE; 139 return 0; 140 } 141 142 LRESULT WindowImplBase::OnKeyDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 143 { 144 bHandled = FALSE; 145 return 0; 146 } 147 148 LRESULT WindowImplBase::OnKillFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) 149 { 150 bHandled = FALSE; 151 return 0; 152 } 153 154 LRESULT WindowImplBase::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 155 { 156 SIZE szRoundCorner = paint_manager_.GetRoundCorner(); 157 #if defined(WIN32) && !defined(UNDER_CE) 158 if( !::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0) ) { 159 CRect rcWnd; 160 ::GetWindowRect(*this, &rcWnd); 161 rcWnd.Offset(-rcWnd.left, -rcWnd.top); 162 rcWnd.right++; rcWnd.bottom++; 163 HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy); 164 ::SetWindowRgn(*this, hRgn, TRUE); 165 ::DeleteObject(hRgn); 166 } 167 #endif 168 bHandled = FALSE; 169 return 0; 170 } 171 172 LRESULT WindowImplBase::OnMoving(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 173 { 174 bHandled = FALSE; 175 return 0; 176 } 177 178 LRESULT WindowImplBase::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 179 { 180 if (wParam == SC_CLOSE){ 181 bHandled = TRUE; 182 return 0; 183 } 184 #if defined(WIN32) && !defined(UNDER_CE) 185 BOOL bZoomed = ::IsZoomed(*this); 186 LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam); 187 if( ::IsZoomed(*this) != bZoomed ){ 188 } 189 #else 190 LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam); 191 #endif 192 return lRes; 193 } 194 195 tString WindowImplBase::GetSkinFolder() 196 { 197 return tString(CPaintManagerUI::GetInstancePath()) + _T("Skins\\"); 198 } 199 200 LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 201 { 202 LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); 203 styleValue &= ~WS_CAPTION; 204 ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); 205 RECT rcClient; 206 ::GetClientRect(*this, &rcClient); 207 ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, 208 rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); 209 210 paint_manager_.Init(m_hWnd); 211 paint_manager_.AddPreMessageFilter(this); 212 213 CDialogBuilder builder; 214 215 paint_manager_.SetResourcePath(GetSkinFolder().c_str()); 216 217 #if USE(ZIP_SKIN) 218 219 #if defined(WIN32) && !defined(UNDER_CE) 220 static bool resource_unzipped = false; 221 if (!resource_unzipped) 222 { 223 resource_unzipped = true; 224 paint_manager_.SetResourceZip(GlobalVariable::kResourceSkinZipFileName); 225 paint_manager_.UnzipResource(); 226 paint_manager_.SetResourceZip(GlobalVariable::kNullString); 227 } 228 tString tstrSkin = paint_manager_.GetResourcePath(); 229 tstrSkin += GetSkinFile(); 230 #else 231 paint_manager_.SetResourceZip(GlobalVariable::kResourceSkinZipFileName); 232 tString tstrSkin = GetSkinFile(); 233 #endif 234 235 #else 236 tString tstrSkin = paint_manager_.GetResourcePath(); 237 tstrSkin += GetSkinFile(); 238 #endif 239 CControlUI* pRoot = builder.Create(tstrSkin.c_str(), (UINT)0, this, &paint_manager_); 240 paint_manager_.AttachDialog(pRoot); 241 paint_manager_.AddNotifier(this); 242 #endif 243 244 Init(); 245 return 0; 246 } 247 248 LRESULT WindowImplBase::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 249 { 250 bHandled = FALSE; 251 return 0; 252 } 253 254 LRESULT WindowImplBase::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) 255 { 256 LRESULT lRes = 0; 257 BOOL bHandled = TRUE; 258 switch (uMsg) 259 { 260 case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break; 261 case WM_CLOSE: lRes = OnClose(uMsg, wParam, lParam, bHandled); break; 262 case WM_DESTROY: lRes = OnDestroy(uMsg, wParam, lParam, bHandled); break; 263 #if defined(WIN32) && !defined(UNDER_CE) 264 case WM_NCACTIVATE: lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break; 265 case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break; 266 case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break; 267 case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break; 268 case WM_GETMINMAXINFO: lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled); break; 269 case WM_MOUSEWHEEL: lRes = OnMouseWheel(uMsg, wParam, lParam, bHandled); break; 270 #endif 271 case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break; 272 case WM_MOVING: lRes = OnMoving(uMsg, wParam, lParam, bHandled); break; 273 case WM_SYSCOMMAND: lRes = OnSysCommand(uMsg, wParam, lParam, bHandled); break; 274 case WM_KEYDOWN: lRes = OnKeyDown(uMsg, wParam, lParam, bHandled); break; 275 case WM_KILLFOCUS: lRes = OnKillFocus(uMsg, wParam, lParam, bHandled); break; 276 case WM_SETFOCUS: lRes = OnSetFocus(uMsg, wParam, lParam, bHandled); break; 277 case WM_LBUTTONUP: lRes = OnLButtonUp(uMsg, wParam, lParam, bHandled); break; 278 case WM_LBUTTONDOWN: lRes = OnLButtonDown(uMsg, wParam, lParam, bHandled); break; 279 case WM_MOUSEMOVE: lRes = OnMouseMove(uMsg, wParam, lParam, bHandled); break; 280 case WM_NCLBUTTONDOWN: lRes = OnNCLButtonDown(uMsg, wParam, lParam, bHandled); break; 281 default: bHandled = FALSE; break; 282 } 283 if (bHandled) return lRes; 284 285 lRes = HandleCustomMessage(uMsg, wParam, lParam, bHandled); 286 if (bHandled) return lRes; 287 288 if (paint_manager_.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes; 289 return CWindowWnd::HandleMessage(uMsg, wParam, lParam); 290 } 291 292 LRESULT WindowImplBase::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled) 293 { 294 if (uMsg == WM_KEYDOWN) 295 { 296 switch (wParam) 297 { 298 case VK_RETURN: 299 case VK_ESCAPE: 300 return ResponseDefaultKeyEvent(wParam, bHandled); 301 default: 302 break; 303 } 304 } 305 return FALSE; 306 } 307 308 LRESULT WindowImplBase::ResponseDefaultKeyEvent(WPARAM wParam, bool& bHandled) 309 { 310 if (wParam == VK_RETURN) 311 { 312 return FALSE; 313 } 314 else if (wParam == VK_ESCAPE) 315 { 316 Close(); 317 return TRUE; 318 } 319 320 return FALSE; 321 }
代码出处:http://www.who1753.com/duilib-windowimplbase.html
2.属性列表.xml
有时间把它精简后再帖出来。。。原xml 900+ 行,吓死爹了
时间: 2024-10-07 07:46:23