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

对话框与窗口

开发平台:

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