RTFrameWnd.cpp
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:27k
源码类别:

界面编程

开发平台:

Visual C++

  1. // RTFrameWnd.cpp : CMainFrame 类的实现
  2. #include "stdafx.h"
  3. #include "RTFrameWnd.h"
  4. #include "RTDraw.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #endif
  8. // CRTFrameWnd
  9. IMPLEMENT_DYNCREATE(CRTFrameWnd, CFrameWnd)
  10. IMPLEMENT_MENUXP(CRTFrameWnd,CFrameWnd)
  11. BEGIN_MESSAGE_MAP(CRTFrameWnd, CFrameWnd)
  12. ON_WM_CREATE()
  13. END_MESSAGE_MAP()
  14. static UINT indicators[] =
  15. {
  16. ID_SEPARATOR,           // 状态行指示器
  17. ID_INDICATOR_CAPS,
  18. ID_INDICATOR_NUM,
  19. ID_INDICATOR_SCRL,
  20. };
  21. // CRTFrameWnd 构造/销毁
  22. CRTFrameWnd::CRTFrameWnd()
  23. {
  24. m_bActive = FALSE;
  25. m_ExitButtonState = StateNormal;
  26. m_MinimizeButtonState = StateNormal;
  27. m_MaximizeButtonState = StateNormal;
  28. m_NcMouseState = MouseStateNormal;
  29. m_SelTitleButton = NoneButton;
  30. }
  31. CRTFrameWnd::~CRTFrameWnd()
  32. {
  33. }
  34. COLORREF CRTFrameWnd::m_BorderColor[4] = {0xAD9E9C,0xCEBEB5,0xCEBEB5,0xDED3CE};
  35. BOOL     CRTFrameWnd::m_bEnableSkin = FALSE;
  36. BOOL     CRTFrameWnd::m_bEnableBackAndBorder = FALSE;
  37. BOOL     CRTFrameWnd::m_bEnableTitleBar = FALSE;
  38. CBitmap* CRTFrameWnd::m_TitleBarBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  39. CBitmap* CRTFrameWnd::m_MenuBarBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  40. CBitmap* CRTFrameWnd::m_MaximizeButtonBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  41. CBitmap* CRTFrameWnd::m_MinimizeButtonBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  42. CBitmap* CRTFrameWnd::m_RestoreButtonBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  43. CBitmap* CRTFrameWnd::m_ExitButtonBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  44. UINT     CRTFrameWnd::m_TitleBarBitmapDrawMode[5] = {0,0,0,0,0};
  45. UINT     CRTFrameWnd::m_MenuBarBitmapDrawMode[5] = {0,0,0,0,0};
  46. UINT     CRTFrameWnd::m_MaximizeButtonBitmapDrawMode[5] = {0,0,0,0,0};
  47. UINT     CRTFrameWnd::m_MinimizeButtonBitmapDrawMode[5] = {0,0,0,0,0};
  48. UINT     CRTFrameWnd::m_ExitButtonBitmapDrawMode[5] = {0,0,0,0,0};
  49. UINT     CRTFrameWnd::m_RestoreButtonBitmapDrawMode[5] = {0,0,0,0,0};
  50. int CRTFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  51. {
  52. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  53. return -1;
  54. return 0;
  55. }
  56. BOOL CRTFrameWnd::PreCreateWindow(CREATESTRUCT& cs)
  57. {
  58. if( !CFrameWnd::PreCreateWindow(cs) )
  59. return FALSE;
  60. return TRUE;
  61. }
  62. // CRTFrameWnd 诊断
  63. #ifdef _DEBUG
  64. void CRTFrameWnd::AssertValid() const
  65. {
  66. CFrameWnd::AssertValid();
  67. }
  68. void CRTFrameWnd::Dump(CDumpContext& dc) const
  69. {
  70. CFrameWnd::Dump(dc);
  71. }
  72. #endif //_DEBUG
  73. // CRTFrameWnd 消息处理程序
  74. BOOL CRTFrameWnd::RTDrawFrameBorder(CDC *pDC,HRGN hRgn)
  75. {
  76. //画框架
  77. CRect rtWnd;
  78. GetWindowRect(&rtWnd);
  79. int Frame_BorderWidth = GetSystemMetrics(SM_CXFRAME);
  80. int Frame_BorderHeight =GetSystemMetrics(SM_CYFRAME);
  81. if(!m_bEnableBackAndBorder)
  82. {
  83. HRGN rgn = NULL;
  84. //left border
  85. rgn = CreateRectRgn(rtWnd.left,rtWnd.top,rtWnd.left + Frame_BorderWidth,rtWnd.bottom);
  86. if(hRgn != NULL)
  87. {
  88. if(NULLREGION != CombineRgn(rgn,rgn,hRgn,RGN_AND))
  89. {
  90. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  91. }
  92. }
  93. else
  94. {
  95. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  96. }
  97. DeleteObject(rgn);
  98. //top border
  99. rgn = CreateRectRgn(rtWnd.left,rtWnd.top,rtWnd.right,rtWnd.top + Frame_BorderHeight);
  100. if(hRgn != NULL && NULLREGION != CombineRgn(rgn,rgn,hRgn,RGN_AND))
  101. {
  102. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  103. }
  104. else
  105. {
  106. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  107. }
  108. DeleteObject(rgn);
  109. //right border
  110. rgn = CreateRectRgn(rtWnd.right - Frame_BorderWidth,rtWnd.top,rtWnd.right,rtWnd.bottom);
  111. if(hRgn != NULL && NULLREGION != CombineRgn(rgn,rgn,hRgn,RGN_AND))
  112. {
  113. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  114. }
  115. else
  116. {
  117. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  118. }
  119. DeleteObject(rgn);
  120. //bottom
  121. rgn = CreateRectRgn(rtWnd.left,rtWnd.bottom - Frame_BorderHeight,rtWnd.right,rtWnd.bottom);
  122. if(hRgn != NULL && NULLREGION != CombineRgn(rgn,rgn,hRgn,RGN_AND))
  123. {
  124. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  125. }
  126. else
  127. {
  128. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  129. }
  130. DeleteObject(rgn);
  131. return TRUE;
  132. }
  133. CRect rtBorder;
  134. rtBorder.SetRect(0,0,rtWnd.Width(),rtWnd.Height());
  135. //画立体边框
  136. for(int i = 0; i < Frame_BorderWidth ; i ++)
  137. {
  138. if(i < 4)
  139. {
  140. pDC->Draw3dRect(i,i,rtWnd.Width() - 2*i,rtWnd.Height() - 2*i,m_BorderColor[i],m_BorderColor[i]);
  141. }
  142. else
  143. {
  144. pDC->Draw3dRect(i,i,rtWnd.Width() - 2*i,rtWnd.Height() - 2*i,m_BorderColor[3],m_BorderColor[3]);
  145. }
  146. }
  147. return TRUE;
  148. }
  149. BOOL CRTFrameWnd::RTDrawMenuBar(CDC *pDC,LPARAM lParam,HRGN hrgn)
  150. {
  151. CMenu *pMenu = GetMenu();
  152. if(pMenu == NULL)return TRUE;
  153. CRect rtMenu;
  154. CRect rtWnd;
  155. GetWindowRect(&rtWnd);
  156. rtMenu.left = GetSystemMetrics(SM_CXFRAME);
  157. rtMenu.top = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CXFRAME) + 1;
  158. rtMenu.right = rtWnd.Width() - GetSystemMetrics(SM_CXFRAME);
  159. rtMenu.bottom = rtMenu.top +  GetSystemMetrics(SM_CYMENU);
  160. UINT ItemCount = pMenu->GetMenuItemCount();
  161. int PrevTop = rtMenu.top;
  162. int PrevLeft = rtMenu.left;
  163. int MenuItemHeight = GetSystemMetrics(SM_CYMENU);
  164. CRect rtMenuItem;
  165. //画菜单上部线
  166. CBrush brMenu(GetSysColor(COLOR_MENU));
  167. CBrush* pOldBrush = pDC->SelectObject(&brMenu);
  168. pDC->PatBlt(rtMenu.left,rtMenu.top - 1,rtMenu.Width(),1, PATCOPY);
  169. for(UINT items = 0; items < ItemCount; items++)
  170. {
  171. GetMenuItemRect(m_hWnd,pMenu->m_hMenu,items,&rtMenuItem);
  172. //画系统菜单
  173. HRGN rgn = CreateRectRgn(rtMenuItem.left,rtMenuItem.top,rtMenuItem.right,rtMenuItem.bottom);
  174. if(hrgn != NULL)
  175. {
  176. if(NULLREGION != CombineRgn(rgn,rgn,hrgn,RGN_AND))
  177. {
  178. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  179. }
  180. }
  181. else
  182. {
  183. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  184. }
  185. DeleteObject(rgn);
  186. int MenuTop = rtMenuItem.top - rtWnd.top;
  187. MenuItemHeight = rtMenuItem.Height();
  188. if(MenuTop != PrevTop)
  189. {
  190. if(!CRTMenu::m_bEnableSkin)
  191. {
  192. rgn = CreateRectRgn(rtWnd.left + PrevLeft,rtWnd.top + PrevTop,rtWnd.right - GetSystemMetrics(SM_CXFRAME),rtWnd.top + PrevTop + MenuItemHeight);
  193. if(hrgn != NULL)
  194. {
  195. if(NULLREGION != CombineRgn(rgn,rgn,hrgn,RGN_AND))
  196. {
  197. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  198. }
  199. }
  200. else
  201. {
  202. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  203. }
  204. DeleteObject(rgn);
  205. }
  206. else
  207. {
  208. CRect rtDraw(PrevLeft,PrevTop,rtMenu.right,PrevTop + MenuItemHeight);
  209. CRTDraw::RTDrawBitmap(pDC,&rtDraw,CRTMenu::m_MenuBarBitmap[BMP_BACK],CRTMenu::m_MenuBarBitmapDrawMode[BMP_BACK]);
  210. }
  211. PrevTop = MenuTop;
  212. PrevLeft = rtMenu.left + rtMenuItem.Width();
  213. }
  214. else
  215. {
  216. PrevLeft += rtMenuItem.Width();
  217. }
  218. }
  219. if(!CRTMenu::m_bEnableSkin)
  220. {
  221. HRGN rgn = CreateRectRgn(rtWnd.left + PrevLeft,rtWnd.top + PrevTop,rtWnd.right - GetSystemMetrics(SM_CXFRAME),rtWnd.top + PrevTop + MenuItemHeight);
  222. if(hrgn != NULL)
  223. {
  224. if(NULLREGION != CombineRgn(rgn,rgn,hrgn,RGN_AND))
  225. {
  226. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  227. }
  228. }
  229. else
  230. {
  231. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  232. }
  233. DeleteObject(rgn);
  234. }
  235. else
  236. {
  237. CRect rtDraw(PrevLeft,PrevTop,rtMenu.right,PrevTop + MenuItemHeight);
  238. CRTDraw::RTDrawBitmap(pDC,&rtDraw,CRTMenu::m_MenuBarBitmap[BMP_BACK],CRTMenu::m_MenuBarBitmapDrawMode[BMP_BACK]);
  239. }
  240. //画菜单上部线
  241. pDC->PatBlt(rtMenu.left,PrevTop + MenuItemHeight,rtMenu.Width(),1, PATCOPY);
  242. pDC->SelectObject(pOldBrush);
  243. return TRUE;
  244. }
  245. BOOL CRTFrameWnd::SetMinimizeButtonBitmap(CBitmap *MinimizeButtonBitmap[],UINT DrawMode[])
  246. {
  247. for(int i = 0; i < 5; i ++)
  248. {
  249. m_MinimizeButtonBitmap[i] = MinimizeButtonBitmap[i];
  250. m_MinimizeButtonBitmapDrawMode[i] = DrawMode[i];
  251. }
  252. return TRUE;
  253. }
  254. BOOL CRTFrameWnd::SetTitleBarBitmap(CBitmap *TitleBarBitmap[],UINT DrawMode[])
  255. {
  256. for(int i = 0; i < 5; i ++)
  257. {
  258. m_TitleBarBitmap[i] = TitleBarBitmap[i];
  259. m_TitleBarBitmapDrawMode[i] = DrawMode[i];
  260. }
  261. return TRUE;
  262. }
  263. BOOL CRTFrameWnd::SetMenuBarBitmap(CBitmap* MenuBarBitmap[],UINT DrawMode[])
  264. {
  265. for(int i = 0; i < 5; i ++)
  266. {
  267. m_MenuBarBitmap[i] = MenuBarBitmap[i];
  268. m_MenuBarBitmapDrawMode[i] = DrawMode[i];
  269. }
  270. return TRUE;
  271. }
  272. BOOL CRTFrameWnd::SetMaximizeButtonBitmap(CBitmap* MaximizeButtonBitmap[],UINT DrawMode[])
  273. {
  274. for(int i = 0; i < 5; i ++)
  275. {
  276. m_MaximizeButtonBitmap[i] =  MaximizeButtonBitmap[i];
  277. m_MinimizeButtonBitmapDrawMode[i] = DrawMode[i];
  278. }
  279. return TRUE;
  280. }
  281. BOOL CRTFrameWnd::SetBorderColor(COLORREF ColorArray[])
  282. {
  283. for(int i = 0; i < 5 ; i++)
  284. m_BorderColor[i] = ColorArray[i];
  285. return TRUE;
  286. }
  287. BOOL CRTFrameWnd::RTDrawTitleBar(CDC* pDC,BOOL bActive,HRGN hrgn)
  288. {
  289. //取得标题栏的位置
  290. DWORD style = GetStyle();
  291. if((style & WS_CAPTION) != WS_CAPTION)return TRUE;
  292. CRect rtWnd;
  293. GetWindowRect(&rtWnd);
  294. if(!m_bEnableTitleBar)
  295. {
  296. rtWnd.left = rtWnd.left + GetSystemMetrics(SM_CXFRAME);
  297. rtWnd.top = rtWnd.top + GetSystemMetrics(SM_CYFRAME);
  298. rtWnd.right = rtWnd.right - GetSystemMetrics(SM_CXFRAME);
  299. rtWnd.bottom = rtWnd.top + GetSystemMetrics(SM_CYSIZE);
  300. HRGN rgn = CreateRectRgn(rtWnd.left,rtWnd.top,rtWnd.right,rtWnd.bottom);
  301. if(hrgn != NULL)
  302. {
  303. if(NULLREGION != CombineRgn(rgn,rgn,hrgn,RGN_AND))
  304. {
  305. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  306. }
  307. }
  308. else
  309. {
  310. CFrameWnd::WindowProc(WM_NCPAINT,(WPARAM)rgn,0);
  311. }
  312. DeleteObject(rgn);
  313. return TRUE;
  314. }
  315. CRect rtTitle;
  316. rtTitle.left = GetSystemMetrics(SM_CXFRAME);
  317. rtTitle.top = GetSystemMetrics(SM_CYFRAME);
  318. rtTitle.right = rtWnd.Width() - GetSystemMetrics(SM_CXFRAME);
  319. rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
  320. CMemDC memDC(pDC,rtTitle);
  321. CBitmap*  BackBitmap;
  322. COLORREF TitleTextColor;
  323. UINT     DrawMode;
  324. if(bActive)
  325. {
  326. BackBitmap = m_TitleBarBitmap[BMP_ACTIVE];
  327. DrawMode = m_TitleBarBitmapDrawMode[BMP_ACTIVE];
  328. TitleTextColor = GetSysColor(COLOR_CAPTIONTEXT);
  329. }
  330. else
  331. {
  332. BackBitmap = m_TitleBarBitmap[BMP_INACTIVE];
  333. DrawMode = m_TitleBarBitmapDrawMode[BMP_INACTIVE];
  334. TitleTextColor = GetSysColor(COLOR_INACTIVECAPTIONTEXT);
  335. }
  336. if(BackBitmap == NULL)return FALSE;
  337. //用位图画标题栏
  338. CRTDraw::RTDrawBitmap(&memDC,&rtTitle,BackBitmap,DrawMode);
  339. //画标题栏图标
  340. HICON hIcon = GetIcon(FALSE);
  341. CRect rtTitleText;
  342. if(hIcon != NULL)
  343. {
  344. DrawIconEx(memDC.m_hDC,rtTitle.left+1,rtTitle.top+1,hIcon,rtTitle.Height() - 2,rtTitle.Height() - 2,0,NULL,DI_NORMAL);
  345. rtTitleText.SetRect(rtTitle.left + rtTitle.Height(),rtTitle.top,rtTitle.right - 60,rtTitle.bottom);
  346. }
  347. else
  348. {
  349. rtTitleText.SetRect(rtTitle.left + 1,rtTitle.top,rtTitle.right - 60,rtTitle.bottom);
  350. }
  351. //画标题栏文字
  352. CFont TitleFont;
  353. NONCLIENTMETRICS nif;
  354. nif.cbSize = sizeof(nif);
  355. SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),&nif,0);
  356. TitleFont.CreateFontIndirect(&nif.lfCaptionFont);
  357. CFont *pOldFont = memDC.SelectObject(&TitleFont);
  358. CString titleText = GetTitle();
  359. int oldBkMode = memDC.SetBkMode(TRANSPARENT);
  360. int oldTextColor = memDC.SetTextColor(TitleTextColor);
  361. TEXTMETRIC Metrics;
  362. pDC->GetTextMetrics(&Metrics);
  363. rtTitleText.top = rtTitle.top + (rtTitle.Height() - Metrics.tmHeight)/2 + 1;
  364. memDC.DrawText(titleText,&rtTitleText,DT_LEFT | DT_SINGLELINE);
  365. memDC.SetBkMode(oldBkMode);
  366. memDC.SetTextColor(oldTextColor);
  367. memDC.SelectObject(&pOldFont);
  368. //画标题栏按扭
  369. RTDrawTitleBarButtons(&memDC);
  370. return TRUE;
  371. }
  372. LRESULT CRTFrameWnd::OnRTNcPaint(WPARAM wParam, LPARAM lParam)
  373. {
  374. //绘制非客户区
  375. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_NCPAINT,wParam,lParam);
  376. CWindowDC dc(this);
  377. HRGN hrgn = NULL;
  378. CRect rtWnd;
  379. GetWindowRect(&rtWnd);
  380. if(wParam != 1)
  381. {
  382. hrgn = (HRGN)wParam;
  383. }
  384. if(hrgn != NULL)
  385. {
  386. ::SelectClipRgn(dc.m_hDC,hrgn);
  387. ::OffsetClipRgn(dc.m_hDC,0 - rtWnd.left,0 - rtWnd.top);
  388. }
  389. RTDrawFrameBorder(&dc,hrgn);
  390. RTDrawTitleBar(&dc,m_bActive,hrgn);
  391. RTDrawMenuBar(&dc,lParam);
  392. if(hrgn != NULL)
  393. {
  394. ::SelectClipRgn(dc.m_hDC,NULL);
  395. DeleteObject(hrgn);
  396. }
  397. return FALSE;
  398. }
  399. BOOL CRTFrameWnd::EnableSkin(BOOL bEnable,BOOL bEnablBackAndBorder,BOOL bEnableTitleBar)
  400. {
  401. m_bEnableSkin = bEnable;
  402. m_bEnableBackAndBorder = bEnablBackAndBorder;
  403. m_bEnableTitleBar = bEnableTitleBar;
  404. return bEnable;
  405. }
  406. LRESULT CRTFrameWnd::OnRTNcActive(WPARAM wParam, LPARAM lParam)
  407. {
  408. return CFrameWnd::WindowProc(WM_NCACTIVATE,wParam,lParam);
  409. }
  410. LRESULT CRTFrameWnd::OnRTActive(WPARAM wParam,LPARAM lParam)
  411. {
  412. LRESULT result = CFrameWnd::WindowProc(WM_ACTIVATE,wParam,lParam);
  413. if(!m_bEnableSkin)return result;
  414. if(!m_bEnableTitleBar)return result;
  415. if(!IsWindow(m_hWnd))return result;
  416. CWindowDC dc(this);
  417. if(wParam == WA_INACTIVE)
  418. {
  419. m_bActive = FALSE;
  420. }
  421. else
  422. {
  423. m_bActive = TRUE;
  424. }
  425. OnRTNcPaint(1,0);
  426. return result;
  427. }
  428. LRESULT CRTFrameWnd::OnRTNodify(WPARAM wParam, LPARAM lParam)
  429. {
  430. LRESULT result = CFrameWnd::WindowProc(WM_NOTIFY,wParam,lParam);
  431. if(!m_bEnableSkin)return result;
  432. if(!m_bEnableTitleBar)return result;
  433. CWindowDC dc(this);
  434. RTDrawTitleBar(&dc,m_bActive);
  435. return 0;
  436. }
  437. LRESULT CRTFrameWnd::OnRTActiveApp(WPARAM wParam,LPARAM lParam)
  438. {
  439. LRESULT result = CFrameWnd::WindowProc(WM_ACTIVATEAPP,wParam,lParam);
  440. if(!m_bEnableSkin)return result;
  441. if(!m_bEnableTitleBar)return result;
  442. m_bActive = (BOOL)wParam;
  443. return 0;
  444. }
  445. LRESULT CRTFrameWnd::OnRTSetText(WPARAM wParam, LPARAM lParam)
  446. {
  447. LRESULT result = CFrameWnd::WindowProc(WM_SETTEXT,wParam,lParam);
  448. if(!m_bEnableSkin)return result;
  449. if(!m_bEnableTitleBar)return result;
  450. CWindowDC dc(this);
  451. RTDrawTitleBar(&dc,m_bActive);
  452. return result;
  453. }
  454. BOOL CRTFrameWnd::SetRestoreButtonBitmap(CBitmap* RestoreButtonBitmap[],UINT DrawMode[])
  455. {
  456. for(int i = 0; i < 5; i ++)
  457. {
  458. m_RestoreButtonBitmap[i] = RestoreButtonBitmap[i];
  459. m_RestoreButtonBitmapDrawMode[i] = DrawMode[i];
  460. }
  461. return TRUE;
  462. }
  463. BOOL CRTFrameWnd::SetExitButtonBitmap(CBitmap* ExitButtonBitmap[],UINT DrawMode[])
  464. {
  465. for(int i = 0; i < 5; i ++)
  466. {
  467. m_ExitButtonBitmap[i] = ExitButtonBitmap[i];
  468. m_ExitButtonBitmapDrawMode[i] = DrawMode[i];
  469. }
  470. return TRUE;
  471. }
  472. BOOL CRTFrameWnd::RTDrawTitleBarButtons(CDC* pDC)
  473. {
  474. //取得标题栏的位置
  475. CRect rtWnd;
  476. CRect rtTitle;
  477. GetWindowRect(&rtWnd);
  478. rtTitle.left = GetSystemMetrics(SM_CXFRAME);
  479. rtTitle.top = GetSystemMetrics(SM_CYFRAME);
  480. rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME);
  481. rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
  482. CRect rtButtons;
  483. //画标题栏按扭
  484. DWORD dwStyle = GetStyle();
  485. CBitmap* pCloseBox = NULL;
  486. CBitmap* pMaximizeBox = NULL;
  487. CBitmap* pMinimizeBox = NULL;
  488. if(TRUE)
  489. {
  490. if(m_ExitButtonState == StateNormal)
  491. {
  492. pCloseBox = m_ExitButtonBitmap[BMP_NORMAL];
  493. }
  494. else if(m_ExitButtonState == StateDown)
  495. {
  496. pCloseBox = m_ExitButtonBitmap[BMP_DOWN];
  497. }
  498. else if(m_ExitButtonState == StateFocus)
  499. {
  500. pCloseBox = m_ExitButtonBitmap[BMP_FOCUS];
  501. }
  502. }
  503. if(WS_MAXIMIZEBOX & dwStyle)
  504. {
  505. if(IsZoomed())
  506. {
  507. if(m_MaximizeButtonState == StateNormal)
  508. {
  509. pMaximizeBox = m_RestoreButtonBitmap[BMP_NORMAL];
  510. }
  511. else if(m_MaximizeButtonState == StateDown)
  512. {
  513. pMaximizeBox = m_RestoreButtonBitmap[BMP_DOWN];
  514. }
  515. else if(m_MaximizeButtonState == StateFocus)
  516. {
  517. pMaximizeBox = m_RestoreButtonBitmap[BMP_FOCUS];
  518. }
  519. }
  520. else
  521. {
  522. if(m_MaximizeButtonState == StateNormal)
  523. {
  524. pMaximizeBox = m_MaximizeButtonBitmap[BMP_NORMAL];
  525. }
  526. else if(m_MaximizeButtonState == StateDown)
  527. {
  528. pMaximizeBox = m_MaximizeButtonBitmap[BMP_DOWN];
  529. }
  530. else if(m_MaximizeButtonState == StateFocus)
  531. {
  532. pMaximizeBox = m_MaximizeButtonBitmap[BMP_FOCUS];
  533. }
  534. }
  535. }
  536. else if(WS_MINIMIZEBOX & dwStyle)
  537. {
  538. if(IsZoomed())
  539. {
  540. pMaximizeBox = m_RestoreButtonBitmap[BMP_DISABLE];
  541. }
  542. else
  543. {
  544. pMaximizeBox = m_MaximizeButtonBitmap[BMP_DISABLE];
  545. }
  546. }
  547. if(WS_MINIMIZEBOX & dwStyle)
  548. {
  549. if(m_MinimizeButtonState == StateNormal)
  550. {
  551. pMinimizeBox = m_MinimizeButtonBitmap[BMP_NORMAL];
  552. }
  553. else if(m_MinimizeButtonState == StateDown)
  554. {
  555. pMinimizeBox = m_MinimizeButtonBitmap[BMP_DOWN];
  556. }
  557. else if(m_MinimizeButtonState == StateFocus)
  558. {
  559. pMinimizeBox = m_MinimizeButtonBitmap[BMP_FOCUS];
  560. }
  561. }
  562. else if(WS_MAXIMIZEBOX & dwStyle)
  563. {
  564. pMinimizeBox = m_MinimizeButtonBitmap[BMP_DISABLE];
  565. }
  566. //重画关闭button
  567. if(dwStyle & WS_SYSMENU)
  568. {
  569. rtButtons.left = rtTitle.right - rtTitle.Height();
  570. rtButtons.top = rtTitle.top + 2;
  571. rtButtons.right = rtTitle.right - 2;
  572. rtButtons.bottom = rtTitle.bottom - 2;
  573. CRTDraw::RTDrawBitmap(pDC,&rtButtons,pCloseBox,CRTDraw::DrawModeAllStretch);
  574. }
  575. //重画最大化/恢复button
  576. if(dwStyle & WS_MAXIMIZEBOX || dwStyle & WS_MINIMIZEBOX)
  577. {
  578. rtButtons.right = rtButtons.left - 2;
  579. rtButtons.left = rtButtons.left - rtTitle.Height();
  580. CRTDraw::RTDrawBitmap(pDC,&rtButtons,pMaximizeBox,CRTDraw::DrawModeAllStretch);
  581. }
  582. //重画最小化button
  583. if(dwStyle & WS_MAXIMIZEBOX || dwStyle & WS_MINIMIZEBOX)
  584. {
  585. rtButtons.right = rtButtons.left;
  586. rtButtons.left = rtButtons.left - rtTitle.Height() + 2;
  587. CRTDraw::RTDrawBitmap(pDC,&rtButtons,pMinimizeBox,CRTDraw::DrawModeAllStretch);
  588. }
  589. return TRUE;
  590. }
  591. LRESULT CRTFrameWnd::OnRTSetIcon(WPARAM wParam, LPARAM lParam)
  592. {
  593. LRESULT result = CFrameWnd::WindowProc(WM_SETICON,wParam,lParam);
  594. if(!m_bEnableSkin)return result;
  595. if(!m_bEnableTitleBar)return result;
  596. if(IsWindow(m_hWnd))
  597. {
  598. CWindowDC dc(this);
  599. RTDrawTitleBar(&dc,m_bActive);
  600. }
  601. return result;
  602. }
  603. LRESULT CRTFrameWnd::OnRTNcMouseMove(WPARAM wParam,LPARAM lParam)
  604. {
  605. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_NCMOUSEMOVE,wParam,lParam);
  606. if(!m_bEnableTitleBar)return CFrameWnd::WindowProc(WM_NCMOUSEMOVE,wParam,lParam);
  607. LRESULT result = 0;
  608. CWindowDC dc(this);
  609. switch(wParam)
  610. {
  611. case HTMAXBUTTON:
  612. if(m_NcMouseState == MouseStateNormal)
  613. {
  614. if(m_MaximizeButtonState != StateFocus)
  615. {
  616. m_MaximizeButtonState = StateFocus;
  617. m_MinimizeButtonState = StateNormal;
  618. m_ExitButtonState = StateNormal;
  619. RTDrawTitleBarButtons(&dc);
  620. }
  621. }
  622. else if(m_NcMouseState == MouseStateDown)
  623. {
  624. if(m_SelTitleButton == MaximizeButton)
  625. {
  626. if(m_MaximizeButtonState != StateDown)
  627. {
  628. m_MaximizeButtonState = StateDown;
  629. RTDrawTitleBarButtons(&dc);
  630. }
  631. }
  632. else if(m_SelTitleButton != NoneButton)
  633. {
  634. m_MinimizeButtonState = StateNormal;
  635. m_ExitButtonState = StateNormal;
  636. RTDrawTitleBarButtons(&dc);
  637. }
  638. }
  639. break;
  640. case HTMINBUTTON:
  641. if(m_NcMouseState == MouseStateNormal)
  642. {
  643. if(m_MinimizeButtonState != StateFocus)
  644. {
  645. m_MinimizeButtonState = StateFocus;
  646. m_MaximizeButtonState = StateNormal;
  647. m_ExitButtonState = StateNormal;
  648. RTDrawTitleBarButtons(&dc);
  649. }
  650. }
  651. else if(m_NcMouseState == MouseStateDown)
  652. {
  653. if(m_SelTitleButton == MinimizeButton)
  654. {
  655. if(m_MinimizeButtonState != StateDown)
  656. {
  657. m_MinimizeButtonState = StateDown;
  658. RTDrawTitleBarButtons(&dc);
  659. }
  660. }
  661. else if(m_SelTitleButton != NoneButton)
  662. {
  663. m_MaximizeButtonState = StateNormal;
  664. m_ExitButtonState = StateNormal;
  665. RTDrawTitleBarButtons(&dc);
  666. }
  667. }
  668. break;
  669. case HTCLOSE:
  670. if(m_NcMouseState == MouseStateNormal)
  671. {
  672. if(m_ExitButtonState != StateFocus)
  673. {
  674. m_ExitButtonState = StateFocus;
  675. m_MaximizeButtonState = StateNormal;
  676. m_MinimizeButtonState = StateNormal;
  677. RTDrawTitleBarButtons(&dc);
  678. }
  679. }
  680. else if(m_NcMouseState == MouseStateDown)
  681. {
  682. if(m_SelTitleButton == ExitButton)
  683. {
  684. if(m_ExitButtonState != StateDown)
  685. {
  686. m_ExitButtonState = StateDown;
  687. RTDrawTitleBarButtons(&dc);
  688. }
  689. }
  690. else if(m_SelTitleButton != NoneButton)
  691. {
  692. m_MaximizeButtonState = StateNormal;
  693. m_MinimizeButtonState = StateNormal;
  694. RTDrawTitleBarButtons(&dc);
  695. }
  696. }
  697. break;
  698. default:
  699. if(m_ExitButtonState != StateNormal || m_MinimizeButtonState != StateNormal || m_MaximizeButtonState != StateNormal)
  700. {
  701. m_MaximizeButtonState = StateNormal;
  702. m_MinimizeButtonState = StateNormal;
  703. m_ExitButtonState = StateNormal;
  704. RTDrawTitleBarButtons(&dc);
  705. }
  706. result = 0;//CFrameWnd::WindowProc(WM_NCMOUSEMOVE,wParam,lParam);
  707. break;
  708. }
  709. return result;
  710. }
  711. LRESULT CRTFrameWnd::OnRTNcLMouseDown(WPARAM wParam,LPARAM lParam)
  712. {
  713. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_NCLBUTTONDOWN,wParam,lParam);
  714. if(!m_bEnableTitleBar)return CFrameWnd::WindowProc(WM_NCLBUTTONDOWN,wParam,lParam);
  715. LRESULT result = 0;
  716. CWindowDC dc(this);
  717. switch(wParam)
  718. {
  719. case HTMAXBUTTON:
  720. m_NcMouseState = MouseStateDown;
  721. m_SelTitleButton = MaximizeButton;
  722. m_MaximizeButtonState = StateDown;
  723. RTDrawTitleBarButtons(&dc);
  724. SetCapture();
  725. break;
  726. case HTMINBUTTON:
  727. m_NcMouseState = MouseStateDown;
  728. m_SelTitleButton = MinimizeButton;
  729. m_MinimizeButtonState = StateDown;
  730. RTDrawTitleBarButtons(&dc);
  731. SetCapture();
  732. break;
  733. case HTCLOSE:
  734. m_NcMouseState = MouseStateDown;
  735. m_SelTitleButton = ExitButton;
  736. m_ExitButtonState = StateDown;
  737. RTDrawTitleBarButtons(&dc);
  738. SetCapture();
  739. break;
  740. default:
  741. result = CFrameWnd::WindowProc(WM_NCLBUTTONDOWN,wParam,lParam);
  742. break;
  743. }
  744. RTDrawTitleBar(&dc,m_bActive);
  745. return result;
  746. }
  747. LRESULT CRTFrameWnd::OnRTNcLMouseUp(WPARAM wParam,LPARAM lParam)
  748. {
  749. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_NCLBUTTONUP,wParam,lParam);
  750. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_NCLBUTTONUP,wParam,lParam);
  751. LRESULT result = 0;
  752. if(m_NcMouseState == MouseStateNormal)
  753. {
  754. return CFrameWnd::WindowProc(WM_NCLBUTTONUP,wParam,lParam);
  755. }
  756. m_NcMouseState = MouseStateNormal;
  757. ReleaseCapture();
  758. if(wParam == HTMAXBUTTON)
  759. {
  760. if(m_SelTitleButton == MaximizeButton)
  761. {
  762. CWindowDC dc(this);
  763. m_SelTitleButton = NoneButton;
  764. m_MaximizeButtonState = StateNormal;
  765. RTDrawTitleBarButtons(&dc);
  766. if(IsZoomed())
  767. {
  768. SendMessage(WM_SYSCOMMAND, SC_RESTORE, lParam);
  769. }
  770. else
  771. {
  772. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE,lParam);
  773. }
  774. }
  775. }
  776. else if(wParam == HTMINBUTTON)
  777. {
  778. if(m_SelTitleButton == MinimizeButton)
  779. {
  780. CWindowDC dc(this);
  781. m_SelTitleButton = NoneButton;
  782. m_MinimizeButtonState = StateNormal;
  783. RTDrawTitleBarButtons(&dc);
  784. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE,lParam);
  785. }
  786. }
  787. else if(wParam == HTCLOSE)
  788. {
  789. if(m_SelTitleButton == ExitButton)
  790. {
  791. //CWindowDC dc(this);
  792. m_SelTitleButton = NoneButton;
  793. m_ExitButtonState = StateNormal;
  794. //RTDrawTitleBarButtons(&dc);
  795. SendMessage(WM_SYSCOMMAND,SC_CLOSE,lParam);
  796. }
  797. }
  798. else
  799. {
  800. m_MinimizeButtonState = StateNormal;
  801. m_MaximizeButtonState = StateNormal;
  802. m_ExitButtonState = StateNormal;
  803. result = CFrameWnd::WindowProc(WM_NCLBUTTONUP,wParam,lParam);
  804. }
  805. return result;
  806. }
  807. LRESULT CRTFrameWnd::OnRTMouseMove(WPARAM wParam, LPARAM lParam)
  808. {
  809. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_MOUSEMOVE,wParam,lParam);
  810. if(!m_bEnableTitleBar)return CFrameWnd::WindowProc(WM_MOUSEMOVE,wParam,lParam);
  811. if(m_NcMouseState != MouseStateNormal)
  812. {
  813. CRect rtWnd;
  814. GetWindowRect(&rtWnd);
  815. CPoint point(lParam);
  816. ClientToScreen(&point);
  817. UINT hit = (UINT)CFrameWnd::WindowProc(WM_NCHITTEST,wParam,MAKELPARAM(point.x,point.y));
  818. return OnRTNcMouseMove(hit,MAKELPARAM(point.x,point.y));
  819. }
  820. else
  821. {
  822. if(m_ExitButtonState != StateNormal || m_MinimizeButtonState != StateNormal || m_MaximizeButtonState != StateNormal)
  823. {
  824. CWindowDC dc(this);
  825. m_MaximizeButtonState = StateNormal;
  826. m_MinimizeButtonState = StateNormal;
  827. m_ExitButtonState = StateNormal;
  828. RTDrawTitleBarButtons(&dc);
  829. }
  830. }
  831. return CFrameWnd::WindowProc(WM_MOUSEMOVE,wParam,lParam);
  832. }
  833. LRESULT CRTFrameWnd::OnRTLButtonUp(WPARAM wParam, LPARAM lParam)
  834. {
  835. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_LBUTTONUP,wParam,lParam);
  836. if(!m_bEnableTitleBar)return CFrameWnd::WindowProc(WM_LBUTTONUP,wParam,lParam);
  837. if(m_NcMouseState != MouseStateNormal)
  838. {
  839. CRect rtWnd;
  840. GetWindowRect(&rtWnd);
  841. CPoint point(lParam);
  842. ClientToScreen(&point);
  843. UINT hit = (UINT)CFrameWnd::WindowProc(WM_NCHITTEST,wParam,MAKELPARAM(point.x,point.y));
  844. return OnRTNcLMouseUp(hit,MAKELPARAM(point.x,point.y));
  845. }
  846. return CFrameWnd::WindowProc(WM_LBUTTONUP,wParam,lParam);
  847. }
  848. BOOL CRTFrameWnd::LoadFrame (UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
  849. {
  850.     if ( !CFrameWnd::LoadFrame (nIDResource, dwDefaultStyle, pParentWnd, pContext) )
  851.     {
  852.         return false;
  853.     }
  854.  
  855.     return true;
  856. }
  857. LRESULT CRTFrameWnd::OnRTSysCommand(WPARAM wParam,LPARAM lParam)
  858. {
  859. if(!m_bEnableSkin)return CFrameWnd::WindowProc(WM_SYSCOMMAND,wParam,lParam);
  860. if(!m_bEnableTitleBar)return CFrameWnd::WindowProc(WM_SYSCOMMAND,wParam,lParam);
  861. if(wParam != SC_CLOSE)
  862. {
  863. CWindowDC dc(this);
  864. RTDrawTitleBar(&dc,m_bActive);
  865. }
  866. return CFrameWnd::WindowProc(WM_SYSCOMMAND,wParam,lParam);
  867. }
  868. LRESULT CRTFrameWnd::OnRTSetCursor(WPARAM wParam,LPARAM lParam)
  869. {
  870. LRESULT rt = CFrameWnd::WindowProc(WM_SETCURSOR,wParam,lParam); 
  871. if(!m_bEnableSkin)return rt;
  872. if(!m_bEnableTitleBar)return rt;
  873. UINT nHitTest = LOWORD(lParam);
  874. if(m_bEnableSkin)
  875. {
  876. CWindowDC dc(this);
  877. switch(nHitTest)
  878. {
  879. case HTBORDER:
  880. case HTLEFT:
  881. case HTRIGHT:
  882. case HTTOP:
  883. case HTBOTTOM:
  884. case HTBOTTOMLEFT:
  885. case HTBOTTOMRIGHT:
  886. case HTTOPLEFT:
  887. case HTTOPRIGHT:
  888. RTDrawTitleBar(&dc,m_bActive);
  889. break;
  890. default:
  891. break;
  892. }
  893. }
  894. return rt;
  895. }
  896. LRESULT CRTFrameWnd::OnRTNcHitTest(WPARAM wParam, LPARAM lParam)
  897. {
  898. LRESULT lrst = CFrameWnd::WindowProc(WM_NCHITTEST,wParam,lParam);
  899. return lrst;
  900. }
  901. LRESULT CRTFrameWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  902. {
  903. switch(message)
  904. {
  905. case WM_INITMENUPOPUP:
  906. if(m_bEnableSkin && m_bEnableTitleBar)
  907. {
  908. CWindowDC dc(this);
  909. RTDrawTitleBar(&dc,m_bActive);
  910. }
  911. break;
  912. case WM_NCPAINT:
  913. return OnRTNcPaint(wParam,lParam);
  914. case WM_NCACTIVATE:
  915. return OnRTNcActive(wParam,lParam);
  916. case WM_ACTIVATE:
  917. return OnRTActive(wParam,lParam);
  918. case WM_ACTIVATEAPP:
  919. return OnRTActiveApp(wParam,lParam);
  920. case WM_NOTIFY:
  921. return OnRTNodify(wParam,lParam);
  922. case WM_SETTEXT:
  923. return OnRTSetText(wParam,lParam);
  924. case WM_SETICON:
  925. return OnRTSetIcon(wParam,lParam);
  926. case WM_NCMOUSEMOVE:
  927. return OnRTNcMouseMove(wParam,lParam);
  928. case WM_NCLBUTTONDOWN:
  929. return OnRTNcLMouseDown(wParam,lParam);
  930. case WM_NCLBUTTONUP:
  931. OnRTNcLMouseUp(wParam,lParam);
  932. case WM_LBUTTONUP:
  933. return OnRTLButtonUp(wParam,lParam);
  934. case WM_MOUSEMOVE:
  935. return OnRTMouseMove(wParam,lParam);
  936. case WM_SYSCOMMAND:
  937. return OnRTSysCommand(wParam,lParam);
  938. case WM_SETCURSOR:
  939. return OnRTSetCursor(wParam,lParam);
  940. default:
  941. break;
  942. }
  943. return CFrameWnd::WindowProc(message, wParam, lParam);
  944. }