GuiMiniFrame.cpp
上传用户:wlkj888
上传日期:2022-08-01
资源大小:806k
文件大小:14k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. /****************************************************************************
  2.  * *  
  3.  * GuiToolKit   *
  4.  *  (MFC extension) *  
  5.  * Created by Francisco Campos G. www.beyondata.com fcampos@beyondata.com *
  6.  *--------------------------------------------------------------------------*    
  7.  * *
  8.  * This program is free software;so you are free to use it any of your *
  9.  * applications (Freeware, Shareware, Commercial),but leave this header *
  10.  * intact. *
  11.  * *
  12.  * These files are provided "as is" without warranty of any kind. *
  13.  * *
  14.  *        GuiToolKit is forever FREE CODE !!!!! *
  15.  * *
  16.  *--------------------------------------------------------------------------*
  17.  * Created by: Francisco Campos G. *
  18.  * Bug Fixes and improvements : (Add your name) *
  19.  * -Francisco Campos *
  20.  * *
  21.  ****************************************************************************/
  22. #include "stdafx.h"
  23. #include "Guiminiframe.h"
  24. #include "GuiDrawlayer.h"
  25. #include "GuiControlBar.h"
  26. #include "GuiToolBarWnd.h"
  27. #include "MenuBar.h"
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char THIS_FILE[]=__FILE__;
  31. #define new DEBUG_NEW
  32. #endif
  33. #define _countof(array) (sizeof(array)/sizeof(array[0]))
  34. ////////////////////////////////////////////////////////////////////////////////
  35. // CGuiMiniFrame
  36. IMPLEMENT_DYNCREATE(CGuiMiniFrame, CMiniDockFrameWnd)
  37. CGuiMiniFrame::CGuiMiniFrame()
  38. {
  39. IsGuiControlBar=-1;
  40. m_stateBtn=NORMAL;
  41. IsMenuBar=FALSE;
  42. IsToolBar=FALSE;
  43. }
  44. BEGIN_MESSAGE_MAP(CGuiMiniFrame, CMiniDockFrameWnd)
  45. //{{AFX_MSG_MAP(CGuiMiniFrame)
  46. ON_WM_CLOSE()
  47. ON_WM_NCLBUTTONDOWN()
  48. ON_WM_NCLBUTTONUP()
  49. ON_WM_NCLBUTTONDBLCLK()
  50. ON_WM_LBUTTONUP()
  51. //}}AFX_MSG_MAP
  52. ON_WM_MOUSEACTIVATE()
  53. ON_WM_CREATE()
  54. ON_WM_NCCALCSIZE()
  55. ON_WM_NCPAINT()
  56. ON_WM_NCACTIVATE()
  57. ON_WM_TIMER()
  58. ON_WM_PAINT()
  59. ON_WM_KILLFOCUS()
  60. ON_WM_SETFOCUS()
  61. ON_WM_NCHITTEST()
  62. ON_WM_NCMOUSEMOVE()
  63. END_MESSAGE_MAP()
  64. int CGuiMiniFrame::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
  65. {
  66. CGuiControlBar* pBar=(CGuiControlBar* )GetChildWnd();
  67. if (nHitTest >= HTSIZEFIRST && nHitTest <= HTSIZELAST && (IsGuiControlBar==TRUE && !pBar->IsAutoHide())) // resizing
  68. return MA_ACTIVATE   ;
  69. return CMiniDockFrameWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
  70. }
  71. void CGuiMiniFrame::RecalcLayout(BOOL bNotify)
  72. {
  73. if (!m_bInRecalcLayout)
  74. {
  75. CMiniDockFrameWnd::RecalcLayout(bNotify);
  76. // syncronize window text of frame window with dockbar itself
  77. TCHAR szTitle[_MAX_PATH];
  78. m_wndDockBar.GetWindowText(szTitle, _countof(szTitle));
  79. AfxSetWindowText(m_hWnd, szTitle);
  80. }
  81. }
  82. void CGuiMiniFrame::OnClose()
  83. {
  84. m_wndDockBar.ShowAll(FALSE);
  85. }
  86. BOOL CGuiMiniFrame::Create(CWnd* pParent, DWORD dwBarStyle)
  87. {
  88. // set m_bInRecalcLayout to avoid flashing during creation
  89. // RecalcLayout will be called once something is docked
  90. if(!CMiniDockFrameWnd::Create(pParent, dwBarStyle))
  91. return FALSE;
  92. //ModifyStyle( MFS_4THICKFRAME, 0 );
  93. ModifyStyleEx( 0, WS_EX_TOOLWINDOW );
  94. ModifyStyle( WS_SYSMENU, 0 );
  95. m_btn.SetData(6,_T("Close"));
  96. m_btn.SetImageList(IDB_GUI_DOCKBAR,9,10,RGB(255,0,255));
  97. m_btn.SetTypeButton(CGuiControlBarButton::GUITOOLBUTTON);
  98. SetTimer(1010,100,NULL);
  99. return TRUE;
  100. }
  101. void CGuiMiniFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
  102. {
  103. // SetTimer(1,100,NULL);
  104. if (nHitTest == HTCLOSE)
  105. {
  106. m_stateBtn=PRESSBTN;
  107. SetTimer(1,100,0);
  108. SendMessage(WM_NCPAINT);
  109. CWnd* pBar=GetChildWnd();
  110. if (pBar== NULL) return;
  111. if (pBar->IsKindOf(RUNTIME_CLASS(CGuiToolBarWnd)))
  112. {
  113. m_stateBtn=NORMAL;
  114. KillTimer(1);
  115. GetParentFrame()->ShowControlBar((CControlBar*)pBar, FALSE, FALSE);
  116. }
  117. }
  118. else 
  119. {
  120. CGuiControlBar* pBar=(CGuiControlBar* )GetChildWnd();
  121. if (pBar)
  122. if (IsGuiControlBar==TRUE && pBar->IsAutoHide())
  123. return;
  124. SetCursor (LoadCursor(NULL, IDC_SIZEALL));
  125. SendMessage(WM_NCPAINT);//SendMessage(WM_NCCALCSIZE);
  126. if (pBar->IsKindOf(RUNTIME_CLASS(CGuiToolBarWnd)))
  127. {
  128. if (nHitTest != HTCAPTION)
  129.  return;
  130. }
  131. }
  132. SendMessage(WM_NCPAINT);
  133. CMiniDockFrameWnd::OnNcLButtonDown(nHitTest, point);
  134. }
  135. void CGuiMiniFrame::OnNcLButtonUp(UINT nHitTest, CPoint point)
  136. {
  137. // SetTimer(1,100,NULL);
  138. if (nHitTest == HTCLOSE)
  139. {
  140. CWnd* pBar=GetChildWnd();
  141. if (pBar== NULL) return;
  142. if (pBar->IsKindOf(RUNTIME_CLASS(CGuiToolBarWnd)))
  143. {
  144. m_stateBtn=NORMAL;
  145. KillTimer(1);
  146. GetParentFrame()->ShowControlBar((CControlBar*)pBar, FALSE, FALSE);
  147. }
  148. }
  149. SendMessage(WM_NCPAINT);
  150. CMiniDockFrameWnd::OnNcLButtonUp(nHitTest, point);
  151. }
  152. void CGuiMiniFrame::OnLButtonUp(UINT nHitTest, CPoint point)
  153. {
  154. // SetTimer(1,100,NULL);
  155. if (nHitTest == HTCLOSE)
  156. {
  157. CWnd* pBar=GetChildWnd();
  158. if (pBar== NULL) return;
  159. if (pBar->IsKindOf(RUNTIME_CLASS(CGuiToolBarWnd)))
  160. {
  161. m_stateBtn=NORMAL;
  162. KillTimer(1);
  163. GetParentFrame()->ShowControlBar((CControlBar*)pBar, FALSE, FALSE);
  164. }
  165. }
  166. SendMessage(WM_NCPAINT);
  167. CMiniDockFrameWnd::OnLButtonUp(nHitTest, point);
  168. }
  169. void CGuiMiniFrame::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
  170. {
  171. // SetTimer(1,100,NULL);
  172. SendMessage(WM_NCACTIVATE);
  173. CMiniDockFrameWnd::OnNcLButtonDblClk(nHitTest, point);
  174. }
  175. int CGuiMiniFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  176. {
  177. if (CMiniDockFrameWnd::OnCreate(lpCreateStruct) == -1)
  178. return -1;
  179. // TODO:  Add your specialized creation code here
  180. return 0;
  181. }
  182. void CGuiMiniFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
  183. {
  184. SendMessage( WM_NCACTIVATE );
  185. CMiniDockFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  186. }
  187. void CGuiMiniFrame::OnNcPaint()
  188. {
  189. CGuiControlBar* pBar=(CGuiControlBar* )GetChildWnd();
  190. if (!pBar) return;
  191. if (IsGuiControlBar==TRUE && !pBar->IsAutoHide())
  192. {
  193. CMiniDockFrameWnd::OnNcPaint();
  194. return; 
  195. }
  196. //if (!pBar->GetComplete()) return;
  197. CRect rcWindow;
  198. CRect rcClient;
  199. CWindowDC dc(this);
  200. CDC m_dc; //contexto de dispositivo en memoria
  201. CBitmap m_bitmap;
  202. CPen Dark(PS_SOLID,1,GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style));
  203. //la idea es tomar el area de la ventana y area  cliente , luego debemos
  204. //igualar el area de coordenadas de ventana al cliente
  205. GetWindowRect(&rcWindow);
  206. GetClientRect(&rcClient);
  207. int nSize=rcClient.right;
  208. ScreenToClient(rcWindow);
  209.     rcClient.OffsetRect(-rcWindow.TopLeft());
  210.     rcWindow.OffsetRect(-rcWindow.TopLeft());
  211.  
  212. m_dc.CreateCompatibleDC(&dc);
  213. m_bitmap.CreateCompatibleBitmap(&dc,rcWindow.Width(),rcWindow.Height());
  214. CBitmap *m_OldBitmap=m_dc.SelectObject(&m_bitmap);
  215. //aqui debe utilizarse la brocha que define GuiDrawLayer, si no hacemos la siguiente
  216. //linea usted vera un horrible color negro, a cambio del dibujo.
  217. CBrush cb;
  218. COLORREF clrBrush;
  219. if(IsGuiControlBar!=TRUE )
  220. clrBrush= GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style);
  221. else
  222. clrBrush=GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style);
  223. cb.CreateSolidBrush(clrBrush);
  224. m_dc.FillRect(rcWindow, &cb);
  225. if (IsGuiControlBar==TRUE && pBar->IsAutoHide())
  226. {
  227. CRect m_rc=rcWindow;
  228. if (pBar->GetLastDocking() == CBRS_ALIGN_LEFT)
  229. {
  230. m_rc.left=m_rc.right-1;
  231. m_rc.top+=3;
  232. cb.DeleteObject();
  233. cb.CreateSolidBrush(RGB(0,0,0));
  234. }
  235. if (pBar->GetLastDocking() == CBRS_ALIGN_RIGHT)
  236. {
  237. m_rc.right=m_rc.left+1;
  238. m_rc.top+=2;
  239. cb.DeleteObject();
  240. cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorBTNHigh());
  241. }
  242. if (pBar->GetLastDocking() == CBRS_ALIGN_TOP)
  243. {
  244. m_rc.top=m_rc.bottom-1;
  245. cb.DeleteObject();
  246. cb.CreateSolidBrush(RGB(0,0,0));
  247. }
  248. m_dc.FillRect(m_rc, &cb);
  249. }
  250. CRect rcCaption=rcClient;
  251. rcCaption.InflateRect(1,1);
  252. if(IsGuiControlBar!=TRUE )
  253. dc.Draw3dRect(rcCaption,GuiDrawLayer::GetRGBColorBTNHigh(),GuiDrawLayer::GetRGBColorBTNHigh());
  254. DrawGripper(&m_dc,&rcClient);
  255. dc.IntersectClipRect(rcWindow);
  256.     dc.ExcludeClipRect(rcClient);//asi evitamos el parpadeo
  257. //rcWindow.InflateRect(1,1);
  258. dc.BitBlt(rcWindow.left,rcWindow.top,rcWindow.Width(),rcWindow.Height(),&m_dc,0,0,SRCCOPY);
  259. ReleaseDC(&dc);
  260. m_dc.SelectObject(m_OldBitmap);
  261. m_bitmap.DeleteObject();
  262. m_dc.DeleteDC();
  263. // SetTimer(1,200,NULL);
  264. // TODO: Add your message handler code here
  265. // Do not call CMiniDockFrameWnd::OnNcPaint() for painting messages
  266. }
  267. void CGuiMiniFrame::DrawGripper(CDC* pDC,CRect* rc)
  268. {
  269. CRect gripper = rc;
  270. gripper.top =3;
  271. gripper.left-=1;
  272. gripper.right+=2;
  273. gripper.bottom +=2;
  274. int nCaption=::GetSystemMetrics(SM_CYSMCAPTION);
  275. //si la ventana esta activa pintamos el caption o el area del titulo de color azul 
  276. CBrush cb;
  277. cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorShadow());//GuiDrawLayer::GetRGBCaptionXP());
  278. pDC->Draw3dRect(gripper,GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style),GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style));
  279. CRect rcLineLeft=gripper;
  280. rcLineLeft.top+=nCaption+1;
  281. rcLineLeft.left+=2;
  282. rcLineLeft.right-=1;
  283. rcLineLeft.bottom-=1;
  284. pDC->Draw3dRect(rcLineLeft,GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style),GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style));
  285. gripper.DeflateRect(1, 1);
  286. CString m_caption;
  287. GetWindowText(m_caption);
  288. CFont m_cfont;
  289. m_cfont.CreateFont(-11,0,0,0,FW_BOLD,0,0,0,0,1,2,1,34,_T("Verdana"));
  290. CFont* m_fontOld=pDC->SelectObject(&m_cfont);
  291. int nMode = pDC->SetBkMode(TRANSPARENT);
  292. CSize SizeCad=pDC->GetTextExtent(m_caption);
  293. CRect rCText=gripper;
  294. rCText.top=6;
  295. rCText.bottom =rCText.top+14;
  296. int cont=SizeCad.cx;
  297. while(cont > 1 && gripper.Width() > 0)
  298. {
  299. CSize coor=pDC->GetTextExtent(m_caption,m_caption.GetLength());
  300. if(coor.cx > gripper.Width()-10)
  301. {
  302. m_caption=m_caption.Left(m_caption.GetLength()-1);
  303. }
  304. else
  305. break;
  306. cont--;
  307. }
  308. if (gripper.Width() > 0 )
  309. {
  310. pDC->SetTextColor(GuiDrawLayer::GetRGBTitleMenu());
  311. pDC->TextOut(rCText.left+3,rCText.top,m_caption);
  312. }
  313. //CRect gripper;
  314. //------------------------------------------------
  315. GetWindowRect( gripper );
  316. ScreenToClient( gripper );
  317. gripper.OffsetRect( -gripper.left, -gripper.top );
  318. gripper.left=gripper.right-20;
  319. gripper.right-=4;
  320. gripper.top+=4;
  321. gripper.bottom=gripper.top+nCaption;
  322. m_rcCloseBtn=gripper;
  323. if (IsMenuBar==FALSE)
  324. {
  325. if (m_stateBtn==NORMAL)
  326. m_btn.Paint(pDC,m_stateBtn,gripper,GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style));
  327. else if (m_stateBtn==OVER)
  328. m_btn.Paint(pDC,m_stateBtn,gripper,GuiDrawLayer::GetRGBFondoXP());
  329. else
  330. m_btn.Paint(pDC,m_stateBtn,gripper,GuiDrawLayer::GetRGBPressBXP());
  331. }
  332. pDC->SetBkMode(nMode);
  333. pDC->SelectObject(m_fontOld);
  334. }
  335. void CGuiMiniFrame::OnNcMouseMove(UINT nHitTest, CPoint point)
  336. {
  337. // TODO: Add your message handler code here and/or call default
  338. if (m_stateBtn != NORMAL) return;
  339. if (nHitTest == HTCLOSE)
  340. {
  341. m_stateBtn=OVERBTN;
  342. SetTimer(1,100,0);
  343. SendMessage(WM_NCPAINT);
  344. }
  345. CMiniDockFrameWnd::OnNcMouseMove(nHitTest, point);
  346. }
  347. void CGuiMiniFrame::OnTimer(UINT nIDEvent)
  348. {
  349. // TODO: Add your message handler code here and/or call default
  350. if (nIDEvent == 1010)
  351. {
  352. KillTimer(1010);
  353. SendMessage(WM_NCACTIVATE);
  354. }
  355. else
  356. {
  357. if (m_stateBtn==NORMAL) 
  358. return;
  359. CRect rc;
  360. CPoint pt(GetMessagePos());
  361. CRect rcT=m_rcCloseBtn;
  362. ClientToScreen(rcT);
  363. pt.y+=23;
  364. pt.x+=5;
  365. if (!rcT.PtInRect(pt))
  366. {
  367. m_stateBtn=NORMAL;
  368. KillTimer(1);
  369. SendMessage(WM_NCPAINT); 
  370. }
  371. }
  372. CMiniDockFrameWnd::OnTimer(nIDEvent);
  373. }
  374. UINT CGuiMiniFrame::OnNcHitTest(CPoint point)
  375. {
  376. // TODO: Add your message handler code here and/or call default
  377. CRect rcWindow;
  378. //no se convierte las coordenadas de pantalla porque el punto
  379. //entregado por esta funci髇 esta dado en el mismo sentido.
  380. GetWindowRect(rcWindow);
  381. int it=0;
  382. CRect rcT=m_rcCloseBtn;
  383. ClientToScreen(rcT);
  384. CPoint pt=point;
  385. pt.y+=23;
  386. pt.x+=5;
  387. if (rcT.PtInRect(pt))
  388. return HTCLOSE;
  389. CGuiControlBar* pBar=(CGuiControlBar* )GetChildWnd();
  390. if (pBar)
  391. if ( IsGuiControlBar == TRUE && pBar->IsAutoHide())
  392. return -1; 
  393. return CMiniDockFrameWnd::OnNcHitTest(point);
  394. }
  395. BOOL CGuiMiniFrame::OnNcActivate(BOOL bActive)
  396. {
  397. // TODO: Add your message handler code here and/or call default
  398. //the followin line is the real secret
  399. BOOL bNc=CMiniDockFrameWnd::OnNcActivate(bActive);
  400. TypeBar();
  401. SendMessage( WM_NCPAINT );
  402. return bNc;
  403. }
  404. void CGuiMiniFrame::TypeBar()
  405. {
  406. if (IsGuiControlBar != -1) 
  407. return;
  408. CWnd* pBar=GetChildWnd();
  409. if (pBar==NULL) 
  410. return;
  411. if (pBar->IsKindOf(RUNTIME_CLASS(CGuiToolBarWnd)))
  412. {
  413. //ModifyStyleEx( WS_EX_TOOLWINDOW,0 );
  414. ModifyStyle( WS_SYSMENU,0 );
  415. SendMessage(WM_NCLBUTTONDOWN);
  416. IsToolBar=TRUE;
  417. }
  418. else if (pBar->IsKindOf(RUNTIME_CLASS(CGuiControlBar)))
  419. {
  420. //ModifyStyleEx( WS_EX_TOOLWINDOW,0 );
  421. ModifyStyle( 0,WS_SYSMENU );
  422. SendMessage(WM_NCLBUTTONDOWN);
  423. IsGuiControlBar=TRUE;
  424. }
  425. else
  426. {
  427. if (pBar->IsKindOf(RUNTIME_CLASS(CMenuBar)))
  428. IsMenuBar=TRUE;
  429. //ModifyStyleEx( 0, WS_EX_TOOLWINDOW );
  430. ModifyStyle( WS_SYSMENU, 0 );
  431. IsGuiControlBar=FALSE;
  432. }
  433. }
  434. CWnd* CGuiMiniFrame::GetChildWnd()
  435. {
  436. CWnd* pBar = GetWindow( GW_CHILD );
  437.     if( pBar == NULL ) return NULL;
  438. pBar = pBar->GetWindow( GW_CHILD );
  439.     if( pBar == NULL ) return NULL;
  440. return pBar;
  441. }
  442. void CGuiMiniFrame::OnPaint()
  443. {
  444. CPaintDC dc(this); // device context for painting
  445. SendMessage(WM_NCACTIVATE);
  446. }
  447. void CGuiMiniFrame::OnSetFocus(CWnd* pOldWnd)
  448. {
  449. SendMessage(WM_NCACTIVATE);
  450. CMiniDockFrameWnd::OnSetFocus(pOldWnd);
  451. // TODO: Add your message handler code here
  452. }