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

对话框与窗口

开发平台:

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 "guiworkpanel.h"
  24. #include "guipanelAccess.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[]=__FILE__;
  28. #define new DEBUG_NEW
  29. #endif
  30. CGuiPanelAccess::CGuiPanelAccess(void)
  31. {
  32. m_PressDown=FALSE;
  33. m_PressUp=FALSE;
  34. m_nDif=0;
  35. m_cfont.CreateFont(-11,0,0,0,400,0,0,0,0,1,2,1,34,_T("MS Sans Serif"));
  36. }
  37. CGuiPanelAccess::~CGuiPanelAccess(void)
  38. {
  39. }
  40. void  CGuiPanelAccess::RecalLayout()
  41. {
  42. if (!GetSafeHwnd()) return;
  43. CRect rcClient;
  44. CClientDC dc(this);
  45. GetClientRect(rcClient);
  46. rcClient.DeflateRect(1,1);
  47. CRect rctemp=rcClient;
  48. rctemp.top+=7;
  49. int nRealval=0;
  50. rctemp.top+=m_nDif;
  51. int nTipo=0;
  52. m_nResultTools=m_nDif;
  53. for (int i=0; i < m_nItems;i++)
  54. {
  55. CComponents* m_cwnd=(CComponents*) m_arrContainer[i];
  56. if(m_cwnd->bTypeSmall == TRUE)
  57. nTipo=22;
  58. m_nResultTools+=nTipo;
  59. rctemp.bottom=rctemp.top+nTipo;
  60. m_cwnd->m_cwnd->MoveWindow(rctemp);
  61. if((rctemp.top < rcClient.top+7) || (rctemp.top > rcClient.bottom-27))
  62. m_cwnd->m_cwnd->ShowWindow(SW_HIDE);
  63. else 
  64. m_cwnd->m_cwnd->ShowWindow(SW_SHOW);
  65. nRealval+=nTipo;
  66. rctemp.top+=nTipo;
  67. }
  68. m_ToolDown.ShowWindow(SW_HIDE);
  69. m_ToolUp.ShowWindow(SW_HIDE);
  70. m_PressDown=TRUE;
  71. m_PressUp=TRUE;
  72. if (rcClient.Height() > 1)
  73. {
  74. if(nRealval > rcClient.Height())
  75. {
  76. if (m_nDif < 0)
  77. {
  78. m_ToolUp.ShowWindow(SW_SHOW);
  79. m_ToolUp.MoveWindow(0,0,rcClient.Width(),8);
  80. }
  81. if (m_nDif==0 || m_nResultTools > rcClient.bottom-5)
  82. {
  83. m_ToolDown.ShowWindow(SW_SHOW);
  84. m_ToolDown.MoveWindow(0,rcClient.bottom-8,rcClient.Width(),8);
  85. }
  86. }
  87. else
  88. {
  89. if (m_nDif < 0)
  90. {
  91. m_ToolUp.ShowWindow(SW_SHOW);
  92. m_ToolUp.MoveWindow(0,0,rcClient.Width(),8);
  93. }
  94. }
  95. }
  96. }
  97. void  CGuiPanelAccess::SetImageList(UINT nBitmapID, int cx, int nGrow, COLORREF crMask)
  98. {
  99. CBitmap cbmp;
  100. BITMAP bmp;
  101. m_imgList.Create(nBitmapID,cx,nGrow,crMask);
  102. cbmp.LoadBitmap(nBitmapID);
  103. cbmp.GetBitmap(&bmp);
  104. m_imgList.Add(&cbmp,crMask);
  105. }
  106. void CGuiPanelAccess::AddButton(UINT ID_BUTTON,int nNumImage,CGuiToolButton* m_pBtn,CString m_sztext)
  107. {
  108. if (!m_pBtn->Create(_T(""),WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,CRect(0,0,0,0),this,ID_BUTTON))
  109. {
  110. m_pBtn=NULL;
  111. return;
  112. }
  113. AddComponen(m_pBtn);
  114. m_pBtn->SethIcon(m_imgList.ExtractIcon(nNumImage));
  115. m_pBtn->SetCaption(m_sztext);
  116. m_pBtn->SetFont(&m_cfont);
  117. m_pBtn->SetColor(GuiDrawLayer::GetRGBColorFace());
  118. }
  119. BOOL CGuiPanelAccess::OnCommand(WPARAM wParam, LPARAM lParam)
  120. {
  121. HWND hwnd = (HWND) lParam;
  122. for (int i=0; i < m_nItems;i++)
  123. {
  124. if (((CComponents*) m_arrContainer[i])->m_cwnd->m_hWnd
  125. == hwnd)
  126. {
  127. int x=((CComponents*) m_arrContainer[i])->m_cwnd->GetDlgCtrlID();
  128. CWnd* pParent= GetParent();
  129. pParent->SendMessage (WM_COMMAND,x);
  130. AfxGetMainWnd()->SendMessage(WM_COMMAND,x);
  131. return TRUE;
  132. }
  133. }
  134. if (wParam == ID_GUI_TOOLUP)
  135. OnUp();
  136. if (wParam == ID_GUI_TOOLDOWN)
  137. OnDownd();
  138. return FALSE;
  139. }
  140. void  CGuiPanelAccess::OnDownd()
  141. {
  142. m_nDif-=22;
  143. m_PressDown=TRUE;
  144. m_PressUp=FALSE;
  145. RecalLayout();
  146. }
  147. void  CGuiPanelAccess::OnUp()
  148. {
  149. m_nDif+=22;
  150. m_PressDown=FALSE;
  151. m_PressUp=TRUE;
  152. RecalLayout();
  153. }
  154. BEGIN_MESSAGE_MAP(CGuiPanelAccess, CGuiContainer)
  155. ON_WM_CREATE()
  156. ON_WM_PAINT()
  157. ON_COMMAND(ID_GUI_TOOLUP,OnUp)
  158. ON_COMMAND(ID_GUI_TOOLDOWN,OnDownd)
  159. END_MESSAGE_MAP()
  160. int CGuiPanelAccess::OnCreate(LPCREATESTRUCT lpCreateStruct)
  161. {
  162. if (CGuiContainer::OnCreate(lpCreateStruct) == -1)
  163. return -1;
  164. CBitmap cbmp;
  165. BITMAP bmp;
  166. m_imgListLocal.Create(IDB_GUI_DOCKBAR,9,11,RGB(255,0,255));
  167. cbmp.LoadBitmap(IDB_GUI_DOCKBAR);
  168. cbmp.GetBitmap(&bmp);
  169. m_imgListLocal.Add(&cbmp,RGB(255,0,255));
  170. SetColor(GuiDrawLayer::GetRGBColorFace());
  171. m_ToolUp.Create(_T(""),WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(0,0,0,0),this,ID_GUI_TOOLUP);
  172. m_ToolUp.SethIcon(m_imgListLocal.ExtractIcon(8));
  173. m_ToolUp.SetScrollButton();
  174. m_ToolDown.Create(_T(""),WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(0,0,0,0),this,ID_GUI_TOOLDOWN);
  175. m_ToolDown.SethIcon(m_imgListLocal.ExtractIcon(0));
  176. m_ToolDown.SetScrollButton();
  177. m_ToolUp.ShowWindow(SW_HIDE);
  178. m_ToolDown.ShowWindow(SW_HIDE);
  179. m_ToolDown.SetWaitClick(100);
  180. m_ToolUp.SetWaitClick(100);
  181. SetDrawBorder();
  182. return 0;
  183. }
  184. void CGuiPanelAccess::OnPaint()
  185. {
  186. CPaintDC dc(this); // device context for painting
  187. // TODO: Add your message handler code here
  188. // Do not call CGuiContainer::OnPaint() for painting messages
  189. CRect rcClient;
  190. GetClientRect(rcClient);
  191. CBrush cb;
  192. cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorFace());
  193. dc.FillRect(rcClient,&cb);
  194. if (m_ToolUp.IsWindowVisible())
  195. m_ToolUp.MoveWindow(0,0,rcClient.Width(),8);
  196. else
  197. m_ToolUp.MoveWindow(0,0,0,0);
  198. if (m_ToolDown.IsWindowVisible())
  199. m_ToolDown.MoveWindow(0,rcClient.bottom-10,rcClient.Width(),8);
  200. else
  201. m_ToolDown.MoveWindow(0,0,0,0);
  202. cb.DeleteObject();
  203. }