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