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

金融证券系统

开发平台:

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 "GuiLib.h"
  15. #include "guidropdownedit.h"
  16. #include "GuiDrawLayer.h"
  17. #define DROPBUTTON 0x8888
  18. #define DROPEDIT   0x8881
  19. // CGuiDropDownEdit
  20. IMPLEMENT_DYNAMIC(CGuiDropDownEdit, CStatic)
  21. CGuiDropDownEdit::CGuiDropDownEdit()
  22. {
  23. bShowButton=TRUE;
  24. m_border=STYLEPRESS;
  25. }
  26. CGuiDropDownEdit::~CGuiDropDownEdit()
  27. {
  28. }
  29. BEGIN_MESSAGE_MAP(CGuiDropDownEdit, CStatic)
  30. ON_WM_NCPAINT()
  31. ON_WM_CREATE()
  32. ON_COMMAND(DROPBUTTON,OnDropButton)
  33. END_MESSAGE_MAP()
  34. // CGuiDropDownEdit message handlers
  35. void CGuiDropDownEdit::OnDropButton()
  36. {
  37. GetParent()->SendMessage(WM_COMMAND,GetDlgCtrlID());
  38. }
  39. void CGuiDropDownEdit::PreSubclassWindow()
  40. {
  41. // TODO: Add your specialized code here and/or call the base class
  42. ModifyStyle(0,BS_OWNERDRAW);
  43. m_cfont.CreateFont(-11,0,0,0,400,0,0,0,0,1,2,1,34,"MS Sans Serif");
  44. CreateControls();
  45. CStatic::PreSubclassWindow();
  46. }
  47. void CGuiDropDownEdit::OnNcPaint()
  48. {
  49. // TODO: Add your message handler code here
  50. // Do not call CStatic::OnNcPaint() for painting messages
  51. CBrush cbr;
  52. CRect m_rectDraw;
  53. CPaintDC dc(this);
  54. GetClientRect(&m_rectDraw);
  55. cbr.CreateSolidBrush(GuiDrawLayer::GetRGBColorFace());
  56. dc.FillRect(&m_rectDraw,&cbr);
  57. if (m_border == STYLE3D)
  58. dc.Draw3dRect(m_rectDraw,GuiDrawLayer::GetRGBColorBTNHigh(),
  59. GuiDrawLayer::GetRGBColorShadow());
  60. if (m_border == STYLEPRESS)
  61. {
  62. dc.Draw3dRect(m_rectDraw,GuiDrawLayer::GetRGBColorShadow(),
  63. GuiDrawLayer::GetRGBColorBTNHigh());
  64. }
  65. if (m_border == STYLEFRAME)
  66. {
  67. dc.Draw3dRect(m_rectDraw,GuiDrawLayer::GetRGBColorShadow(),
  68. GuiDrawLayer::GetRGBColorShadow());
  69. }
  70. CSize szBtn=CSize(0,0);
  71. if (bShowButton)
  72. {
  73. if (!m_toolBtn.GetSafeHwnd()) return;
  74. szBtn=m_toolBtn.GetSizeButton();
  75. }
  76. m_rectDraw.DeflateRect(1,1);
  77. m_Edit.MoveWindow(m_rectDraw.left,m_rectDraw.top,m_rectDraw.Width()-(szBtn.cx+1),m_rectDraw.Height());
  78. if (bShowButton)
  79. m_toolBtn.MoveWindow(m_rectDraw.Width()-(szBtn.cx-1),m_rectDraw.top,szBtn.cx,m_rectDraw.Height());
  80. }
  81. int CGuiDropDownEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
  82. {
  83. if (CStatic::OnCreate(lpCreateStruct) == -1)
  84. return -1;
  85. CreateControls();
  86. return 0;
  87. }
  88. void CGuiDropDownEdit::SetStyle(Border border)
  89. {
  90. m_border=border;
  91. }
  92. void CGuiDropDownEdit::SetLimitText(int numText)
  93. {
  94. m_Edit.SetLimitText(numText);
  95. }
  96. void CGuiDropDownEdit::CreateControls()
  97. {
  98. m_Edit.Create(WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL,CRect(0,0,0,0),this,DROPEDIT);
  99. m_Edit.ModifyStyle(WS_BORDER,0);
  100. m_Edit.SetFont(&m_cfont);
  101. m_Edit.SetLimitText(100);
  102. m_toolBtn.Create(_T(""),WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,CRect(0,0,0,0),this,DROPBUTTON);
  103. m_toolBtn.SetCaption(_T(" ... "));
  104. m_toolBtn.SetStyleButton(CGuiNormalButton::STL_SEMIFLAT);
  105. }
  106. void CGuiDropDownEdit::ShowButton(BOOL bShow)
  107. {
  108. bShowButton=bShow;
  109. m_toolBtn.ShowWindow(bShow?SW_SHOW:SW_HIDE);
  110. }
  111. void CGuiDropDownEdit::SetImageButton(HICON hIcon)
  112. {
  113. m_toolBtn.SethIcon(hIcon);
  114. m_toolBtn.SetCaption(_T(""));
  115. }
  116. void CGuiDropDownEdit::SetMask(CString mszMask,CString mszShowMask,CGuiEdit::Mask enTypeMask)
  117. {
  118. m_Edit.SetMask(mszMask,mszShowMask,enTypeMask);
  119. }
  120. void CGuiDropDownEdit::SetToolTipEdit(CString szToolTip)
  121. {
  122. m_Edit.SetToolTip(szToolTip);
  123. }
  124. void CGuiDropDownEdit::SetToolTipBtn(CString szToolTip)
  125. {
  126. m_toolBtn.SetToolTip(szToolTip);
  127. }
  128. CString CGuiDropDownEdit::GetText()
  129. {
  130. if (!m_Edit.m_szMask.IsEmpty())
  131. return m_Edit.m_cadResult;
  132. else
  133. {
  134. CString cad;
  135. m_Edit.GetWindowText(cad);
  136. return cad;
  137. }
  138. }
  139. void CGuiDropDownEdit::SetText(CString szCaption)
  140. {
  141. m_Edit.SetWindowText(szCaption);
  142. }