文章目录
按控件名称查找指定控件
先来例子
m_pEditstart = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_START_TIME"));
m_PaintManager是CPaintManagerUI类型成员,
关于CPaintManagerUI 类详见https://blog.csdn.net/wyansai/article/details/51052441
将得到的指针强转为CEditUI类型,CEditUI类型更方便我们对他进行操作。
CEditUI源码如下,可以进行文本设置(包含密码)
class UILIB_API CEditUI : public CLabelUI
{
friend class CEditWnd;
public:
CEditUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
UINT GetControlFlags() const;
void SetEnabled(bool bEnable = true);
void SetText(LPCTSTR pstrText);
void SetMaxChar(UINT uMax);
UINT GetMaxChar();
void SetReadOnly(bool bReadOnly);
bool IsReadOnly() const;
void SetPasswordMode(bool bPasswordMode);
bool IsPasswordMode() const;
void SetPasswordChar(TCHAR cPasswordChar);
TCHAR GetPasswordChar() const;
void SetNumberOnly(bool bNumberOnly);
bool IsNumberOnly() const;
int GetWindowStyls() const;
LPCTSTR GetNormalImage();
void SetNormalImage(LPCTSTR pStrImage);
LPCTSTR GetHotImage();
void SetHotImage(LPCTSTR pStrImage);
LPCTSTR GetFocusedImage();
void SetFocusedImage(LPCTSTR pStrImage);
LPCTSTR GetDisabledImage();
void SetDisabledImage(LPCTSTR pStrImage);
void SetNativeEditBkColor(DWORD dwBkColor);
DWORD GetNativeEditBkColor() const;
void SetSel(long nStartChar, long nEndChar);
void SetSelAll();
void SetReplaceSel(LPCTSTR lpszReplace);
void SetPos(RECT rc);
void SetVisible(bool bVisible = true);
void SetInternVisible(bool bVisible = true);
SIZE EstimateSize(SIZE szAvailable);
void DoEvent(TEventUI& event);
void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
void PaintStatusImage(HDC hDC);
void PaintText(HDC hDC);
protected:
CEditWnd* m_pWindow;
UINT m_uMaxChar;
bool m_bReadOnly;
bool m_bPasswordMode;
TCHAR m_cPasswordChar;
UINT m_uButtonState;
CDuiString m_sNormalImage;
CDuiString m_sHotImage;
CDuiString m_sFocusedImage;
CDuiString m_sDisabledImage;
DWORD m_dwEditbkColor;
int m_iWindowStyls;
};
}
获取edit控件的输入文本
edit控件可以接受用户输入的文本,首先获取控件的操作句柄:
if (msg.sType == _T("windowinit"))//当窗口有数据输入
{
m_pEditstart = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_START_TIME")); //获取输入时间控件的句柄
}
然后使用CLabelUI ::GetText函数获取文本
CDuiString strStartTime = m_pEditstart->GetText();//获取起始时间
CLabelUI 是CEditUI 的父类,其源码如下
class UILIB_API CLabelUI : public CControlUI
{
public:
CLabelUI();
~CLabelUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
void SetTextStyle(UINT uStyle);
UINT GetTextStyle() const;
void SetTextColor(DWORD dwTextColor);
DWORD GetTextColor() const;
void SetDisabledTextColor(DWORD dwTextColor);
DWORD GetDisabledTextColor() const;
void SetFont(int index);
int GetFont() const;
RECT GetTextPadding() const;
void SetTextPadding(RECT rc);
bool IsShowHtml();
void SetShowHtml(bool bShowHtml = true);
SIZE EstimateSize(SIZE szAvailable);
void DoEvent(TEventUI& event);
void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
void PaintText(HDC hDC);
void SetEnabledEffect(bool _EnabledEffect);
bool GetEnabledEffect();
void SetText(LPCTSTR pstrText);
CDuiString GetText() const;
void SetTransShadow(int _TransShadow);
int GetTransShadow();
void SetTransShadow1(int _TransShadow);
int GetTransShadow1();
void SetTransText(int _TransText);
int GetTransText();
void SetTransText1(int _TransText);
int GetTransText1();
void SetTransStroke(int _TransStroke);
int GetTransStroke();
void SetGradientLength(int _GradientLength);
int GetGradientLength();
void SetTextRenderingHintAntiAlias(int _TextRenderingHintAntiAlias);
int GetTextRenderingHintAntiAlias();
void SetShadowOffset(int _offset,int _angle);
RectF GetShadowOffset();
void SetTextColor1(DWORD _TextColor1);
DWORD GetTextColor1();
void SetTextShadowColorA(DWORD _TextShadowColorA);
DWORD GetTextShadowColorA();
void SetTextShadowColorB(DWORD _TextShadowColorB);
DWORD GetTextShadowColorB();
void SetStrokeColor(DWORD _StrokeColor);
DWORD GetStrokeColor();
void SetGradientAngle(int _SetGradientAngle);
int GetGradientAngle();
void SetEnabledStroke(bool _EnabledStroke);
bool GetEnabledStroke();
void SetEnabledShadow(bool _EnabledShadowe);
bool GetEnabledShadow();
protected:
DWORD m_dwTextColor;
DWORD m_dwDisabledTextColor;
int m_iFont;
UINT m_uTextStyle;
RECT m_rcTextPadding;
bool m_bShowHtml;
int m_hAlign;
int m_vAlign;
int m_TransShadow;
int m_TransShadow1;
int m_TransText;
int m_TransText1;
int m_TransStroke;
int m_GradientLength;
int m_GradientAngle;
bool m_EnableEffect;
bool m_EnabledStroke;
bool m_EnabledShadow;
DWORD m_dwTextColor1;
DWORD m_dwTextShadowColorA;
DWORD m_dwTextShadowColorB;
DWORD m_dwStrokeColor;
RectF m_ShadowOffset;
CDuiString m_TextValue;
ULONG_PTR m_gdiplusToken;
GdiplusStartupInput m_gdiplusStartupInput;
TextRenderingHint m_TextRenderingHintAntiAlias;
};
~~~