GuiWorkPanel.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:6k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------//
  2. // This is a part of the GuiLib MFC Extention.  //
  3. // Autor  :  Francisco Campos  //
  4. // (C) 2002 Francisco Campos <www.beyondata.com> All rights reserved     //
  5. // This code is provided "as is", with absolutely no warranty expressed  //
  6. // or implied. Any use is at your own risk.  //
  7. // You must obtain the author's consent before you can include this code //
  8. // in a software library.  //
  9. // If the source code in  this file is used in any application  //
  10. // then acknowledgement must be made to the author of this program  //
  11. // fcampos@tutopia.com  //
  12. //-----------------------------------------------------------------------//
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "guiworkpanel.h"
  16. #include "guiworkpanel.h"
  17. CGuiWorkPanel::CGuiWorkPanel(void)
  18. {
  19. m_PressDown=FALSE;
  20. m_PressUp=FALSE;
  21. m_nDif=0;
  22. }
  23. CGuiWorkPanel::~CGuiWorkPanel(void)
  24. {
  25. }
  26. void  CGuiWorkPanel::RecalLayout()
  27. {
  28. if (!GetSafeHwnd()) return;
  29. CRect rcClient;
  30. CClientDC dc(this);
  31. GetClientRect(rcClient);
  32. rcClient.DeflateRect(1,1);
  33. CRect rctemp=rcClient;
  34. rctemp.top+=7;
  35. int nRealval=0;
  36. rctemp.top+=m_nDif;
  37. int nTipo=0;
  38. m_nResultTools=m_nDif;
  39. for (int i=0; i < m_nItems+1;i++)
  40. {
  41. CComponents* m_cwnd=(CComponents*) m_arrContainer[i];
  42. if(m_cwnd->bTypeSmall == TRUE)
  43. nTipo=18;
  44. m_nResultTools+=nTipo;
  45. rctemp.bottom=rctemp.top+nTipo;
  46. m_cwnd->m_cwnd->MoveWindow(rctemp);
  47. if((rctemp.top < rcClient.top+7) || (rctemp.top > rcClient.bottom-25))
  48. m_cwnd->m_cwnd->ShowWindow(SW_HIDE);
  49. else 
  50. m_cwnd->m_cwnd->ShowWindow(SW_SHOW);
  51. nRealval+=nTipo;
  52. rctemp.top+=nTipo;
  53. }
  54. m_ToolDown.ShowWindow(SW_HIDE);
  55. m_ToolUp.ShowWindow(SW_HIDE);
  56. m_PressDown=TRUE;
  57. m_PressUp=TRUE;
  58. if (rcClient.Height() > 1)
  59. {
  60. if(nRealval+8 > rcClient.Height())
  61. {
  62. if (m_nDif < 0)
  63. {
  64. m_ToolUp.ShowWindow(SW_SHOW);
  65. m_ToolUp.MoveWindow(0,0,rcClient.Width(),8);
  66. }
  67. if (m_nDif==0 || m_nResultTools > rcClient.bottom-25)
  68. {
  69. m_ToolDown.ShowWindow(SW_SHOW);
  70. m_ToolDown.MoveWindow(0,rcClient.bottom-8,rcClient.Width(),8);
  71. }
  72. }
  73. else
  74. {
  75. if (m_nDif < 0)
  76. {
  77. m_ToolUp.ShowWindow(SW_SHOW);
  78. m_ToolUp.MoveWindow(0,0,rcClient.Width(),8);
  79. }
  80. }
  81. }
  82. }
  83. void  CGuiWorkPanel::SetImageList(UINT nBitmapID, int cx, int nGrow, COLORREF crMask)
  84. {
  85. CBitmap cbmp;
  86. BITMAP bmp;
  87. m_imgList.Create(nBitmapID,cx,nGrow,crMask);
  88. cbmp.LoadBitmap(nBitmapID);
  89. cbmp.GetBitmap(&bmp);
  90. m_imgList.Add(&cbmp,crMask);
  91. }
  92. CGuiLabelButton* CGuiWorkPanel::Addlabel(UINT ID_BUTTON)
  93. {
  94. CGuiLabelButton* m_btn;
  95. m_btn= (CGuiLabelButton*)
  96.     AddComponen(RUNTIME_CLASS(CGuiLabelButton),ID_BUTTON,WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW);
  97. m_btn->DrawUnderLine();
  98. m_btn->SetColor(RGB(255,255,255));
  99. return m_btn;
  100. }
  101. CGuiImageLinkButton* CGuiWorkPanel::AddImageLink(UINT ID_BUTTON,int nNumImage)
  102. {
  103. CGuiImageLinkButton* m_Linkbtn;
  104. m_Linkbtn= (CGuiImageLinkButton*)AddComponen(RUNTIME_CLASS(CGuiImageLinkButton),ID_BUTTON,WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW);
  105. m_Linkbtn->SethIcon(m_imgList.ExtractIcon(nNumImage));
  106. m_Linkbtn->SetColor(RGB(255,255,255));
  107. return m_Linkbtn;
  108. }
  109. BOOL CGuiWorkPanel::OnCommand(WPARAM wParam, LPARAM lParam)
  110. {
  111. HWND hwnd = (HWND) lParam;
  112. for (int i=0; i < m_nItems+1;i++)
  113. {
  114. if (((CComponents*) m_arrContainer[i])->m_cwnd->m_hWnd
  115. == hwnd)
  116. {
  117. int x=((CComponents*) m_arrContainer[i])->m_cwnd->GetDlgCtrlID();
  118. CWnd* pParent= GetParent();
  119. pParent->SendMessage (WM_COMMAND,x);
  120. AfxGetMainWnd()->SendMessage(WM_COMMAND,x);
  121. return TRUE;
  122. }
  123. }
  124. if (wParam == ID_TOOLUP)
  125. OnUp();
  126. if (wParam == ID_TOOLDOWN)
  127. OnDownd();
  128. return FALSE;
  129. }
  130. void  CGuiWorkPanel::OnDownd()
  131. {
  132. m_nDif--;
  133. m_PressDown=TRUE;
  134. m_PressUp=FALSE;
  135. RecalLayout();
  136. }
  137. void  CGuiWorkPanel::OnUp()
  138. {
  139. m_nDif++;
  140. m_PressDown=FALSE;
  141. m_PressUp=TRUE;
  142. RecalLayout();
  143. }
  144. BEGIN_MESSAGE_MAP(CGuiWorkPanel, CGuiContainer)
  145. ON_WM_CREATE()
  146. ON_WM_PAINT()
  147. ON_COMMAND(ID_TOOLUP,OnUp)
  148. ON_COMMAND(ID_TOOLDOWN,OnDownd)
  149. END_MESSAGE_MAP()
  150. int CGuiWorkPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
  151. {
  152. if (CGuiContainer::OnCreate(lpCreateStruct) == -1)
  153. return -1;
  154. CBitmap cbmp;
  155. BITMAP bmp;
  156. m_imgListLocal.Create(IDB_DOCKBAR,9,11,RGB(255,0,255));
  157. cbmp.LoadBitmap(IDB_DOCKBAR);
  158. cbmp.GetBitmap(&bmp);
  159. m_imgListLocal.Add(&cbmp,RGB(255,0,255));
  160. SetColor(RGB(255,255,255));
  161. m_ToolUp.Create(_T(""),WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(0,0,0,0),this,ID_TOOLUP);
  162. m_ToolUp.SethIcon(m_imgListLocal.ExtractIcon(8));
  163. m_ToolUp.SetScrollButton();
  164. m_ToolDown.Create(_T(""),WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(0,0,0,0),this,ID_TOOLDOWN);
  165. m_ToolDown.SethIcon(m_imgListLocal.ExtractIcon(0));
  166. m_ToolDown.SetScrollButton();
  167. m_ToolUp.ShowWindow(SW_HIDE);
  168. m_ToolDown.ShowWindow(SW_HIDE);
  169. SetDrawBorder();
  170. return 0;
  171. }
  172. void CGuiWorkPanel::OnPaint()
  173. {
  174. CPaintDC dc(this); // device context for painting
  175. // TODO: Add your message handler code here
  176. // Do not call CGuiContainer::OnPaint() for painting messages
  177. CRect rcClient;
  178. GetClientRect(rcClient);
  179. CBrush cb;
  180. cb.CreateSolidBrush(RGB(255,255,255));
  181. dc.FillRect(rcClient,&cb);
  182. if (m_ToolUp.IsWindowVisible())
  183. m_ToolUp.MoveWindow(0,0,rcClient.Width(),8);
  184. else
  185. m_ToolUp.MoveWindow(0,0,0,0);
  186. if (m_ToolDown.IsWindowVisible())
  187. m_ToolDown.MoveWindow(0,rcClient.bottom-8,rcClient.Width(),8);
  188. else
  189. m_ToolDown.MoveWindow(0,0,0,0);
  190. }